I am trying to get Apollo federation working with two GraphQL services using Java/Spring Boot and graphql-kickstart. Consider the following schemas:
Person Service:
type Person @key(fields: "id") {
id: String!
name: String!
}
Book Service:
type Book @key(fields: "id") {
id: String!
author: Person!
}
type Person @extends @key(fields: "id") {
id: String! @external
}
I am trying to run a query such as:
query {
book(bookId:"1") {
author {
name
}
}
}
When I run the query against the Apollo gateway, the query it runs against the Person service is:
query ($representations:[_Any!]!) {
_entities(representations:$representations) {
... on Person {
name
}
}
}
with variables:
{
"representations": [
{
"__typename": "Person",
"id": "2"
}
]
}
This is returning:
{
"data": {
"_entities": [null]
}
}
GraphQL configuration (class with @Configuration annotation) has the following (taken from the example at https://github.com/setchy/graphql-java-kickstart-federation-example/blob/master/shows/src/main/java/com/example/demo/federation/FederatedSchema.java):
@Bean
public GraphQLSchema customSchema(SchemaParser schemaParser) {
GraphQLSchema federatedSchema = Federation.transform(schemaParser.makeExecutableSchema())
.fetchEntities(env -> env.<List<Map<String, Object>>>getArgument(_Entity.argumentName)
.stream()
.map(reference -> {
return null;
})
.collect(Collectors.toList()))
.resolveEntityType(env -> {
return null;
})
.build();
return federatedSchema;
}
According to the Apollo documentation at https://www.apollographql.com/docs/federation/entities/#2-define-a-reference-resolver the .fetchEntities method should add a reference resolver that resolves the type. However, I'm unsure how to do this in a static context, and in the example linked above this is not done (although I'm unable to get the example to work due to a separate issue).
Any ideas to help point out what's wrong are appreciated.