mercurius-gateway
mercurius-gateway copied to clipboard
Support for multiple @key directives
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.
Multiple @key
directives are not supported atm. Would you like to send a PR?
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.
happy to review the change!