Skip to content

#377 - have the ability to know and capture all fields in a data fetcher - #401

Merged
bbakerman merged 6 commits into
graphql-java:masterfrom
bbakerman:377-field-selection-in-data-fetchers
May 10, 2017
Merged

bbakerman merged 6 commits into
graphql-java:masterfrom
bbakerman:377-field-selection-in-data-fetchers

Conversation

@bbakerman

Copy link
Copy Markdown
Member

#377 - have the ability to know and capture all fields in a data fetcher

This tweaks DataFetcher so it has the ExecutionContext available and FieldCollector to have a better public API

@bbakerman bbakerman added this to the 3.0.0 milestone May 2, 2017
@bbakerman
bbakerman requested a review from apottere May 2, 2017 09:35
resolvedType = (GraphQLObjectType) fieldType;
}

Map<String, List<Field>> subFields = new LinkedHashMap<>();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Notice how visitedFragments is NEVER used. Thats why I took it out of the public method signature

}


private void collectFields(ExecutionContext executionContext, GraphQLObjectType type, SelectionSet selectionSet, List<String> visitedFragments, Map<String, List<Field>> fields) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I can make this public again but I figured 3.x and breaking changes and its unlikely to break ANYONE really

@bbakerman

Copy link
Copy Markdown
Member Author

@kaqqao - this helps solve your selection problem. I think all the parts are now in place

@bbakerman bbakerman left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Atlassian needs the ability to "proxy" a field down to a backing graphql server. This will allow that

/**
* @return the {@link ExecutionContext} for the current operation
*/
ExecutionContext getExecutionContext();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

To use FieldCollector in a DataFetcher, I need the ExecutionContext.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@bbakerman Does this mean ExecutionContext is now part of the public API?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have taken this out now as being API and made a new wrapper of the bits we need

@bbakerman bbakerman added the breaking change requires a new major version to be relased label May 4, 2017
bbakerman added 2 commits May 4, 2017 20:58
…on-in-data-fetchers

# Conflicts:
#	src/main/java/graphql/execution/batched/BatchedExecutionStrategy.java
@kaqqao

kaqqao commented May 4, 2017

Copy link
Copy Markdown
Contributor

Commented on #377 about the idea I had for FieldCollector. Basically, I was thinking it could be created once per execution (with all variables and fragment set) and passed into every DatafetchingEnvironment. Maybe even completely hidden from the user and only exposed via new methods on DatafetchingEnvironment.

@bbakerman

Copy link
Copy Markdown
Member Author

Basically, I was thinking it could be created once per execution (with all variables and fragment set) and passed into every DatafetchingEnvironment.

Thats brilliant - yes that what we should do. Have an API wrapper for field collector and leave all the plumbing to the internals.

@andimarek

andimarek commented May 6, 2017 •

Copy link
Copy Markdown
Member

I agree with @bbakerman sounds good. 👍

@bbakerman

Copy link
Copy Markdown
Member Author

OK so I have created a DataFetcherSelectionSet interface so we can hide the details of how to get the selection set of fields from consumers.

I used a supplier interface for DataFetchingFieldSelectionSet so that it can be lazy. If you dont want the "selection set" of fields then it wont evaluate them.

…on-in-data-fetchers

# Conflicts:
#	src/main/java/graphql/execution/FieldCollector.java
@bbakerman
bbakerman merged commit c7fee85 into graphql-java:master May 10, 2017
@andimarek

Copy link
Copy Markdown
Member

@bbakerman why is this a breaking change?

@bbakerman

Copy link
Copy Markdown
Member Author

Its a minor breaking change in that I refactored FieldCollector. Fiven that we dont expect consumers to consume FieldCollector its debtateable.

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.

3 participants