Skip to content

Conversation

@bbakerman
Copy link
Member

@bbakerman bbakerman commented Oct 20, 2020

This improves the DataFetchingFieldSelectionSet support so that conditional composite types such as Unions can now be supported.

Its a breaking change because we can now get multiple SelectedFields in for a given addressing name. Therefore getField no longer makes sense nor do the maps to 1:1 arguments and field definitiions

This supersedes the PR #1963

@bbakerman bbakerman added the breaking change requires a new major version to be relased label Oct 20, 2020
@bbakerman bbakerman added this to the 16.0 milestone Oct 20, 2020
@bbakerman bbakerman requested a review from andimarek October 20, 2020 11:30
…ield-support

# Conflicts:
#	src/main/java/graphql/util/FpKit.java
@bbakerman
Copy link
Member Author

graphql.schema.DataFetcherSelectionTest still needs to be fixed

Copy link
Member Author

@bbakerman bbakerman left a comment

Choose a reason for hiding this comment

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

I think this is now ready for review

protected Supplier<NormalizedField> getNormalizedField(ExecutionContext executionContext, ExecutionStrategyParameters parameters, Supplier<ExecutionStepInfo> executionStepInfo) {
Supplier<NormalizedQueryTree> normalizedQuery = executionContext.getNormalizedQuery();
return () -> normalizedQuery.get().getNormalizedField(parameters.getField(), executionStepInfo.get().getFieldContainer(), executionStepInfo.get().getPath());
}
Copy link
Member Author

Choose a reason for hiding this comment

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

All made as Supplier to ensure its super lazy - lets not pay any cost unless some one asks for this.

/**
* @return a map of the {@link graphql.schema.GraphQLFieldDefinition}s for each field in the selection set
*/
Map<String, GraphQLFieldDefinition> getDefinitions();
Copy link
Member Author

Choose a reason for hiding this comment

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

This is part of the breaking changes - these no longer make sense because we have multiple SelectedFields to a named path

name
appearsIn
friends(separationCount : 5) {
friends {
Copy link
Member Author

Choose a reason for hiding this comment

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

This was actually illegal query text - now that we run the whole thing, it needed to be fixed

DataFetchingFieldSelectionSet selectionSet = null
DataFetcher humanDF = { DataFetchingEnvironment env ->
selectionSet = env.getSelectionSet()
return StarWarsData.humanDataFetcher.get(env)
Copy link
Member Author

Choose a reason for hiding this comment

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

We use side effect to get the inner selection set.


(selectionSet.definitions['name'].getType() as GraphQLNonNull).getWrappedType() == Scalars.GraphQLString
(selectionSet.definitions['friends'].getType() as GraphQLList).getWrappedType() == starWarsSchema.getType('Character')
(selectionSet.definitions['friends/friends'].getType() as GraphQLList).getWrappedType() == starWarsSchema.getType('Character')
Copy link
Member Author

Choose a reason for hiding this comment

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

These have been removed and hence so have the tests

@jhaals
Copy link

jhaals commented Oct 21, 2020

@bbakerman thanks for improving the PR.

Here are some things that are problematic.
dataFetchingEnvironment.getSelectionSet().getFields() returns duplicates of each field.

Overall this has reduced the custom code we need thanks to the ability to find fields with DataFetchingFieldSelectionSet.getFields(String).

We noticed that the transitive nature of DataFetchingFieldSelectionSet causes issues sometimes. We need a way to get only the fields nested directly under the current field. Right now we tried using the getObjectType() of the fields in the selection set to filter out any fields we're not interested in, but this doesn’t work when the same type is nested recursively in itself.

type User {
  name: String
  address: String
  friend: User
}

{
  user(id: "steve") {
    name
    friend {
      name
      address
    }
  }
}

The selection set for the user query would contain all fields (also the nested ones) and if we try to use the type to tell which fields to take, we end up with [name, friend, address] when what we really want is to be able to tell the two “users” apart and have [name, friend] and later [name, address].

@bbakerman
Copy link
Member Author

@jhaals - see 6401f12

I have added a getImmediateFields() method

@jhaals
Copy link

jhaals commented Oct 22, 2020

@bbakerman We've switched to using getImmediateFields() and it works great 💯

@jhaals
Copy link

jhaals commented Nov 2, 2020

@bbakerman @andimarek another friendly ping about this PR. Are there any leftovers or things we can do or help out with in order to get this PR merged? We really need union support in graphql-java 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change requires a new major version to be relased

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants