federation-jvm icon indicating copy to clipboard operation
federation-jvm copied to clipboard

Importing and renaming @key directive

Open RoKKim opened this issue 1 year ago • 1 comments

Let's say I import the @key directive as @myKey:

extend schema @link(url: "https://specs.apollo.dev/federation/v2.5", import: [{name : "@key", as : "@myKey"}, "@requiresScopes", "Scope", "FieldSet"])

type Product @myKey(fields: "id") {
    id: ID!
    name: String!
    supplier: String @requiresScopes(scopes: [["scopeA"]])
}

In this scenario, the following code inside the com.apollographql.federation.graphqljava.SchemaTransformer#entityPredicate method will fail: entityCandidate.getAllDirectivesByName().containsKey(FederationDirectives.keyName)

This occurs because FederationDirectives.keyName is hardcoded to "key". As a result, the _Entity will not be generated in the schema by the com.apollographql.federation.graphqljava.SchemaTransformer#build.

RoKKim avatar Feb 09 '24 20:02 RoKKim

Seems like we need similar or expose imports from LinkDirectiveProcessor https://github.com/apollographql/federation-jvm/blob/main/graphql-java-support/src/main/java/com/apollographql/federation/graphqljava/directives/LinkDirectiveProcessor.java#L123

panatl avatar Feb 19 '24 23:02 panatl