apollographql / federation-jvm

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

SchemaTransform includes Entities in the _Entity union when @key(resolvable=false) #412

Open NavidMitchell opened 2 months ago

NavidMitchell commented 2 months ago

According to the Federation spec Entities that have @key(resolvable=false) should not be included in the _Entity union.

"The _Entity union must include all entity types that are defined in the subgraph schema, except entities with a @key that sets resolvable: false." Spec Doc

The following code from the SchemaTransformer does not consider the resolvable field.

  private Predicate<GraphQLNamedType> entityPredicate() {
    return type -> {
      if (type instanceof GraphQLDirectiveContainer) {
        GraphQLDirectiveContainer entityCandidate = (GraphQLDirectiveContainer) type;
        return entityCandidate
                .getAllAppliedDirectivesByName()
                .containsKey(FederationDirectives.keyName)
            || entityCandidate.getAllDirectivesByName().containsKey(FederationDirectives.keyName);
      } else {
        return false;
      }
    };
  }