Interface DataFetchingFieldSelectionSet
-
- All Known Implementing Classes:
DataFetchingFieldSelectionSetImpl
@PublicApi public interface DataFetchingFieldSelectionSet
This class allows you to retrieve the selection set of fields that have been asked for when theDataFetcher
was invoked.For example imagine we are fetching the field 'user' in the following query
{ user { name age weight friends { name } } }
The selection set in the case above consists of the fields "name, age, weight, friends and friends/name".
You can use this selection set perhaps to "peek" ahead and decide that field values you might need from the underlying data system. Imagine a SQL system where this might represent the SQL 'projection' of columns say.
However composite types such as Interfaces and Unions add some complexity. You cant know ahead of time the exact field and object types involved. There in fact be multiple possible `conditional` fields.
This class represents this by returning a list of fields and having two addressing mechanisms, a simple `x/y` one and the more specific `Foo.x/Bar.y` mechanism.
For example imagine a `Pet` interface type that has `Cat` and `Dog` object type implementations. The query might be:
{ pet { name } }
In the example above you have a `Cat.name`and `Dog.name` as possible sub selections of the `pet` field. They are can be addressed by either `name` or `Dog.name` or `Cat.name`
selectionSet.contains("name") == true selectionSet.contains("Dog.name", "Cat.name") == true List<SelectedField> petNames = selectionSet.getFields("name") petNames.size() == 2 List<SelectedField> dogNames = selectionSet.getFields("Dog.name") dogNames.size() == 1
The simple naming is easier to work with but the type prefixed naming is more precise.
Another complication is any field aliasing that a client can specify.
{ pet { name(arg : "foo") ... on Dog { aliasedName : name(arg : "bar") } } }
In the example above the `selectionSet.getFields("name")` actually returns three
SelectedField
s, one for `Dog.name`, one for `Cat.name` and one for `Dog.name` with an alias of `aliasedName`. The arguments can differ onSelectedField
s that have differentSelectedField.getResultKey()
s, hence the multiple selected fields returned.To help you there is the
getFieldsGroupedByResultKey()
that returns aMap<String,List<SelectedField>>
keyed by result key, that is by the field alias or by the field name.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
contains(java.lang.String fieldGlobPattern)
This will return true if the field selection set matches a specified "glob" pattern matching ie the glob pattern matching supported byFileSystem.getPathMatcher(java.lang.String)
.boolean
containsAllOf(java.lang.String fieldGlobPattern, java.lang.String... fieldGlobPatterns)
This will return true if the field selection set matches all of the specified "glob" pattern matches ie the glob pattern matching supported byFileSystem.getPathMatcher(java.lang.String)
.boolean
containsAnyOf(java.lang.String fieldGlobPattern, java.lang.String... fieldGlobPatterns)
This will return true if the field selection set matches any of the specified "glob" pattern matches ie the glob pattern matching supported byFileSystem.getPathMatcher(java.lang.String)
.java.util.List<SelectedField>
getFields()
This will return all selected fields.java.util.List<SelectedField>
getFields(java.lang.String fieldGlobPattern, java.lang.String... fieldGlobPatterns)
This will return a list of selected fields that match a specified "glob" pattern matching ie the glob pattern matching supported byFileSystem.getPathMatcher(java.lang.String)
.java.util.Map<java.lang.String,java.util.List<SelectedField>>
getFieldsGroupedByResultKey()
The result key of a selected field represents what the graphql return value will be.java.util.Map<java.lang.String,java.util.List<SelectedField>>
getFieldsGroupedByResultKey(java.lang.String fieldGlobPattern, java.lang.String... fieldGlobPatterns)
The result key of a selected field represents what the graphql return value will be.java.util.List<SelectedField>
getImmediateFields()
This will return all selected fields that are immediate child fields of the field being fetched.
-
-
-
Method Detail
-
contains
boolean contains(java.lang.String fieldGlobPattern)
This will return true if the field selection set matches a specified "glob" pattern matching ie the glob pattern matching supported byFileSystem.getPathMatcher(java.lang.String)
.This will allow you to use '*', '**' and '?' as special matching characters such that "invoice/customer*" would match an invoice field with child fields that start with 'customer'.
- Parameters:
fieldGlobPattern
- the glob pattern to match fields against- Returns:
- true if the selection set contains these fields
- See Also:
FileSystem.getPathMatcher(String)
-
containsAnyOf
boolean containsAnyOf(java.lang.String fieldGlobPattern, java.lang.String... fieldGlobPatterns)
This will return true if the field selection set matches any of the specified "glob" pattern matches ie the glob pattern matching supported byFileSystem.getPathMatcher(java.lang.String)
.This will allow you to use '*', '**' and '?' as special matching characters such that "invoice/customer*" would match an invoice field with child fields that start with 'customer'.
- Parameters:
fieldGlobPattern
- the glob pattern to match fields againstfieldGlobPatterns
- optionally more glob pattern to match fields against- Returns:
- true if the selection set contains any of these these fields
- See Also:
FileSystem.getPathMatcher(String)
-
containsAllOf
boolean containsAllOf(java.lang.String fieldGlobPattern, java.lang.String... fieldGlobPatterns)
This will return true if the field selection set matches all of the specified "glob" pattern matches ie the glob pattern matching supported byFileSystem.getPathMatcher(java.lang.String)
.This will allow you to use '*', '**' and '?' as special matching characters such that "invoice/customer*" would match an invoice field with child fields that start with 'customer'.
- Parameters:
fieldGlobPattern
- the glob pattern to match fields againstfieldGlobPatterns
- optionally more glob pattern to match fields against- Returns:
- true if the selection set contains all of these these fields
- See Also:
FileSystem.getPathMatcher(String)
-
getFields
java.util.List<SelectedField> getFields()
This will return all selected fields.The fields are guaranteed to be in pre-order as they appear in the query.
A selected field may have an alias - and hence is a unique field in the returned list. It may have the same field names as others in the list but when you also consider the alias then it is indeed unique because it would be another entry in the graphql result.
- Returns:
- a list of all selected fields or empty list if none match
-
getImmediateFields
java.util.List<SelectedField> getImmediateFields()
This will return all selected fields that are immediate child fields of the field being fetched.The fields are guaranteed to be in pre-order as they appear in the query.
A selected field may have an alias - and hence is a unique field in the returned list. It may have the same field names as others in the list but when you also consider the alias then it is indeed unique because it would be another entry in the graphql result.
- Returns:
- a list of all selected immediate child fields or empty list if none match
-
getFields
java.util.List<SelectedField> getFields(java.lang.String fieldGlobPattern, java.lang.String... fieldGlobPatterns)
This will return a list of selected fields that match a specified "glob" pattern matching ie the glob pattern matching supported byFileSystem.getPathMatcher(java.lang.String)
.This will allow you to use '*', '**' and '?' as special matching characters such that "invoice/customer*" would match an invoice field with child fields that start with 'customer'.
The fields are guaranteed to be in pre-order as they appear in the query.
A selected field may have an alias - and hence is a unique field in the returned list. It may have the same field names as others in the list but when you also consider the alias then it is indeed unique because it would be another entry in the graphql result.
- Parameters:
fieldGlobPattern
- the glob pattern to match fields againstfieldGlobPatterns
- optionally more glob pattern to match fields against- Returns:
- a list of selected fields or empty list if none match
-
getFieldsGroupedByResultKey
java.util.Map<java.lang.String,java.util.List<SelectedField>> getFieldsGroupedByResultKey()
The result key of a selected field represents what the graphql return value will be. The sameGraphQLFieldDefinition
may lead to a field being asked for multiple times (with differing arguments) if field aliases are used. This method helps you get all possible field invocations grouped by their result key. The arguments are guaranteed to be the same if the result key is the same, otherwise the query would not have validated correctly.- Returns:
- a map of selected fields grouped by result key or an empty map if none match
-
getFieldsGroupedByResultKey
java.util.Map<java.lang.String,java.util.List<SelectedField>> getFieldsGroupedByResultKey(java.lang.String fieldGlobPattern, java.lang.String... fieldGlobPatterns)
The result key of a selected field represents what the graphql return value will be. The sameGraphQLFieldDefinition
may lead to a field being asked for multiple times (with differing arguments) if field aliases are used. This method helps you get all possible field invocations grouped by their result key. The arguments are guaranteed to be the same if the result key is the same, otherwise the query would not have validated correctly.- Parameters:
fieldGlobPattern
- the glob pattern to match fields againstfieldGlobPatterns
- optionally more glob pattern to match fields against- Returns:
- a map of selected fields grouped by result key or an empty map if none match
-
-