apollographql / federation-jvm

JVM support for Apollo Federation
https://www.apollographql.com/docs/federation/
MIT License
245 stars 65 forks source link

Importing and renaming @key directive #379

Open RoKKim opened 6 months ago

RoKKim commented 6 months ago

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.

panatl commented 6 months ago

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