Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multiple @key directives #20

Open
jmshal opened this issue May 21, 2022 · 3 comments
Open

Support for multiple @key directives #20

jmshal opened this issue May 21, 2022 · 3 comments

Comments

@jmshal
Copy link

jmshal commented May 21, 2022

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.

@mcollina
Copy link
Contributor

Multiple @key directives are not supported atm. Would you like to send a PR?

@jmshal
Copy link
Author

jmshal commented May 21, 2022

I'm going to have a go - but I'll be honest, I'm not entirely sure where to start. It also appears that my workaround won't... well... work. So attempting to add multiple @key directives is probably my best bet at this time.

@mcollina
Copy link
Contributor

happy to review the change!

@codeflyer codeflyer transferred this issue from mercurius-js/mercurius Nov 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants