Skip to content

Avoid printing inline fragment if there is no conditional type - #2621

Merged
andimarek merged 3 commits into
graphql-java:masterfrom
gnawf:fwang/avoid-inline-fragments
Nov 30, 2021
Merged

andimarek merged 3 commits into
graphql-java:masterfrom
gnawf:fwang/avoid-inline-fragments

Conversation

@gnawf

@gnawf gnawf commented Nov 29, 2021

Copy link
Copy Markdown
Contributor

My IDE keeps freezing when I open GraphQL Java, so I used the IDE without the smart features to write this code… felt like I was sent 10 years back in time. Let me know if something is wrong.

) {
List<Selection<?>> selections = selectionsForNormalizedFields(topLevelFields);
public static Document compileToDocument(GraphQLSchema schema,
OperationDefinition.Operation operationKind,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok now that we have the schema again, we can avoid explicitly specifying the operationKind and derive it from the ENF and GraphQLSchema but as I said in the PR desc, my IDE is broken, and that approach required some refactoring which I wasn't prepared to do without the IDE. What a massive pain…


for (ExecutableNormalizedField nf : executableNormalizedFields) {
Map<String, List<Field>> groupFieldsForChild = selectionForNormalizedField(schema, nf);
if (nf.isConditional(schema)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the change, we check if the NF is conditional, if it is then we add it to the conditional field Map to group the type conditions, otherwise we add it straight to the output as a raw Field.

}

overallGroupedFields.forEach((objectTypeName, fields) -> {
conditionalFieldsByObjectTypeName.forEach((objectTypeName, fields) -> {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As usual, we group the condition fields by object type conditions so that they can be grouped together in the same inline fragment.

@andimarek
andimarek merged commit 2ca2d5f into graphql-java:master Nov 30, 2021
@andimarek andimarek added this to the 18.0 milestone Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants