Keep getting missing usable key when using requires directive

I created a new sub-graph on top of locations and review and have the schema as below. Basically I want to pass info from locations subgraph as requires to resolve something in this new sub-graph.

type Query {
“Query the entity”
preferred(id:ID!): IsPreferredLocation
}

type IsPreferredLocation{
id: ID!
isPreferred: Boolean! requires(fields: "location { name } ")
location: Location!# external
}

type Location key(fields: “id”, resolvable: false) {
id: ID!
name: String! external
}

I keep getting an error as below when publishing this with rover.

SATISFIABILITY_ERROR: The following supergraph API query:
{
preferred(id: “”) {
isPreferred
}
}
cannot be satisfied by the subgraphs because:

  • from subgraph “temp”: require condition on field “IsPreferredLocation.isPreferred” can be satisfied but missing usable key on “IsPreferredLocation” in subgraph “temp” to resume query.

Have checked around and don’t see me doing anything wrong there.

P.S. removed @ as system thought I was mentioning a user.

I think you need to add @key directive to the IsPreferredLocation type, because to use @requires, your type needs to be an entity

1 Like

thank you so much Michael; could not believe it was such a small thing. I had it as an entity earlier then removed it since i felt didn’t have any other sub-graph contributing to it referring to it.

You are welcome.

Good luck with your project

1 Like