Skip to content

Support for multiple @key directives #20

@jmshal

Description

@jmshal

It would be great to have support for multiple @key directives.

For reference, I'm trying to get something like the following working...

Entity service

interface Entity {
  entityRef: String!
}

extends type Query {
  entity(ref: String!): Entity
}

User service

interface Entity {
  entityRef: String!
}

type User @key(fields: "id") @key(fields: "entityRef") {
  id: ID!
  entityRef: String!
  name: String
}

extend type Query {
  me: User
}

The problem is that the first @key directive is functional. The second one is completely ignored (it took me longer than I would like to admit to figure out why this wasn't working 🤦‍♂️). This means that when the "Entity service" returns a reference to a User, it must provide an id. But the idea for this setup is to let the "User service" figure out how to resolve the User based on the "entityRef".

I'm fairly certain I can work around this for now - simply because my current implementation of generating the "entityRef" involves serialising the ID anyway. But this, I imagine, would be a nice to have for others that don't have that option.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions