You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: Allow extend in type builders to support federation #1644
The issue we are having is that there is no way to mark a type as extending from the code type builders. i.e. If I am in code, and I am building my schema and type and I want to mark the Query type as extending, but there is not going to be a non-extending Query type in the schema there is no way to do that.
Ideally GraphqlTypeBuilder or GraphQLObjectType.Builder would have an option to mark the type as extend
I don't really understand the requirement here, could you explain a bit more what you want to do?
In general GraphQLSchema is a constructed and validated Schema regardless of how you define/create it. This is why GraphqlTypeBuilder or others don't know anything about extensions.
We do keep the references to the SDL definitions. Currently we don't keep the reference to multiple extends definitions, but we could enhance that.
@andimarek The Apollo Federation spec states that the type Query (and Mutation) in each service that the gateway talks to needs to be extend type Query
ie
Service 1
extendtypeQuery {
getUserName: String!
}
Service 2
extendtypeQuery {
getUserId: ID!
}
In the Gateway the schema gets merged into this
typeQuery {
getUserName: String!getUserId: ID!
}
So if Service 1 is a graphql-java service, the Query type needs to have the extend keyword on it even though there is not a Query defined in the Service 1 schema that does not have the extend keyword.
If you are not using the SDL to define the schema and instead using the TypeBuilders this is currently not possible.
I found a section in the Apollo Federation spec that acknowledges this limitation for graphql-java
Some libraries such as graphql-java don't have native support for type extensions in their printer. Apollo Federation supports using an @extends directive in place of extend type to annotate type references
So it looks like we don't need this to support federation today. It would be a nice-to-have though if we could add the extend keyword to the types from the TypeBuilders for this and other use cases.
I am still unclear on what the extend AST is meant to do in a Apollo Federation world.
I am guessing that they use the presence of the "extend" AST to help them know which parts have been added to they can make queries on the schema to "discover" the stitching "support" fields to ask them for extra info.
I have briefly read the spec but I have not done the time to deeply understand what it might mean for graphql-java to help support it.
I am also not sure what we would put into the type builders (as extra suport attributes) to cause the deserved side effect
one thing we could do is this
# A
type Query {
name : String
}
# B
extend type Query {
age : int
}
# C
extend type Query {
height : Int
}
The resultant GraphqlObjectType would have
// it has this today
public ObjectTypeDefinition getDefinition() {
return definition; // from # A
}
public List<ObjectTypeExtensionDefinition> getExtendDefinitions() {
return extendsDefs; // from # B and # C
}
This would mean that the runtime GraphqlObjectType has the combined fields (as it does today) and it would have evidence of how the object type was composed together in SDL terms
But as for graphql.language.ObjectTypeDefinition.Builder direct I am not sure what we would add for those who build types via Java since I am not sure what Apollo federation needs to know??
Nominally all AST SDL objects can be extended so such a change should be done on ALL the runtime types! eg extend Scalarextend Unionextend Interface etc...
Schema composition at the gateway relies on understanding the capabilities of underlying services. This is done through an enhanced introspection using a new entry point added to the query root of a service, the _service field.
Note that the _service field is never exposed at the gateway. This is soley done to compose the schema.
The _service resolver should return the _Service type which has a single field called sdl. This SDL (schema definition language) is a printed version of the service's schema including the annotations of federation directives. This SDL does not include the additions of the federation spec above. Given an input like this:
Copy
extend type Query {
me: User
}
type User @key(fields: "id") {
id: ID!
}
They have extensions (quadi introspection special fields) that give out printed SDL
And they want that printed SDL to have the original extend type XXX things so that they can infer federation instructions from it.
This is tricky... if we kept the original SDL we would be ok I guess (kinda sorta)
But we still dont have any story for people who build the schema by Java classes. And I am guessing that Apollo does not either in JSD land.
I think this points me to "its difficult" to build via runtime objects and support Apollo Federation
@bbakerman Yea, I get your point now. As long as the Apollo spec will check for the @extends directive, we can take care of adding that info the specific types that need it with our wrapper
Activity
andimarek commentedon Sep 4, 2019
I don't really understand the requirement here, could you explain a bit more what you want to do?
In general GraphQLSchema is a constructed and validated Schema regardless of how you define/create it. This is why
GraphqlTypeBuilderor others don't know anything about extensions.We do keep the references to the SDL definitions. Currently we don't keep the reference to multiple extends definitions, but we could enhance that.
smyrick commentedon Sep 4, 2019
@andimarek The Apollo Federation spec states that the
type Query(andMutation) in each service that the gateway talks to needs to beextend type Queryie
Service 1
Service 2
In the Gateway the schema gets merged into this
So if Service 1 is a
graphql-javaservice, theQuerytype needs to have theextendkeyword on it even though there is not aQuerydefined in the Service 1 schema that does not have theextendkeyword.If you are not using the SDL to define the schema and instead using the TypeBuilders this is currently not possible.
I found a section in the Apollo Federation spec that acknowledges this limitation for
graphql-javahttps://www.apollographql.com/docs/apollo-server/federation/federation-spec/
So it looks like we don't need this to support federation today. It would be a nice-to-have though if we could add the
extendkeyword to the types from the TypeBuilders for this and other use cases.Federation example (#315)
bbakerman commentedon Sep 5, 2019
I am still unclear on what the
extendAST is meant to do in a Apollo Federation world.I am guessing that they use the presence of the "extend" AST to help them know which parts have been added to they can make queries on the schema to "discover" the stitching "support" fields to ask them for extra info.
I have briefly read the spec but I have not done the time to deeply understand what it might mean for graphql-java to help support it.
I am also not sure what we would put into the type builders (as extra suport attributes) to cause the deserved side effect
one thing we could do is this
The resultant GraphqlObjectType would have
This would mean that the runtime GraphqlObjectType has the combined fields (as it does today) and it would have evidence of how the object type was composed together in SDL terms
But as for
graphql.language.ObjectTypeDefinition.Builderdirect I am not sure what we would add for those who build types via Java since I am not sure what Apollo federation needs to know??Nominally all AST SDL objects can be extended so such a change should be done on ALL the runtime types! eg
extend Scalarextend Unionextend Interfaceetc...bbakerman commentedon Sep 5, 2019
Ahh I get it now
They have extensions (quadi introspection special fields) that give out printed SDL
And they want that printed SDL to have the original
extend type XXXthings so that they can infer federation instructions from it.This is tricky... if we kept the original SDL we would be ok I guess (kinda sorta)
But we still dont have any story for people who build the schema by Java classes. And I am guessing that Apollo does not either in JSD land.
I think this points me to "its difficult" to build via runtime objects and support Apollo Federation
smyrick commentedon Sep 5, 2019
@bbakerman Yea, I get your point now. As long as the Apollo spec will check for the
@extendsdirective, we can take care of adding that info the specific types that need it with our wrapperhttps://github.com/ExpediaDotCom/graphql-kotlin/tree/master/graphql-kotlin-federation
I would be fine closing this issue then
Federation example (ExpediaGroup#315)