DataFetchingFieldSelectionSet ignores inline fragments when parent type is interface/union#1952
Conversation
|
Now thinking about it, I think it must by design since if we would include the inline fragments there is a risk they would conflict: type QueryType {
humanCharacter(id : String) : Character
}
interface Character {
id: ID!
}
type Human implements Character {
id: ID!
homePlanet: String
}
type Droid implements Character {
id: ID!
homePlanet: String
make: String
}and query: {
humanCharacter(id: "1003") { --> returns Leia who is a Human
id
__typename
... on Human {
homePlanet
}
... on Droid {
homePlanet
make
}
}
}the result of and this would be ambiguous? (as we would lose information about one of the two |
|
@tinnou you are right: this is intentionally as we don't have a good way at the moment to really analyze the query statically (without executing it) to the desired level you describe. The challenge are really Interfaces and Union as they are only "realized" when executed. This normalized Query would tell you that: |
|
And remember that now we have "branching" in the fields. That is you code would have to cope with "if its a This is a much more complicated programming model than "these are the concrete fields" you can access. |
|
@tinnou Please have a look at this test: https://github.com/graphql-java/graphql-java/pull/1963/files#diff-d9e663cf35993c9d4de118e0353dda5f to see how it will probably look like with |
Ok looking at the test you linked, that makes sense. So a |
|
@tinnou we talked about it a bit more and we will probably incorporate the NormalizedFields into the DataFetchingFieldSelectionSet in a way. |
|
This PR will be superseded by #2079 |
[DO NOT MERGE]
Description
This PR is more of a question than a PR, the code changes consist of a single unit test to reproduce the use case.
Say I have the following shortened SWAPI schema:
and the following query:
{ humanCharacter(id: "1003") { --> returns Leia who is a Human id __typename ... on Human { homePlanet } } }The selection set returned by
environment.getSelectionSet().get().keySet()when ran from theQuery.humanCharacterdata fetcher contains all the fields buthomePlanet. That is:I would like to understand if this omission is by design or it is a defect.
If it is by design:
We are returning only the fields in the selection set which we are sure are of the same type as the field output type. In our example, we would only return the fields from the selection set that are on the type
Character.Assuming it is by design, does it kind of defeats the purpose of looking ahead?
If say, we were making a request to a SQL system (as per the doc) using the
DataDetchingSelectionSetfields as projection. Since we only get back the selected fields onCharacter, i.eidand__typename, wouldn't this create a hurdle ashomePlanetwould be missing from the SQL statement?If it is a defect
I can update the PR to include fragments in the selection set.
The test added in this PR fails because it expected
homePlanetto be included: