@PublicApi public interface DataFetchingFieldSelectionSet
DataFetcher
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 on SelectedField
s that have different SelectedField.getResultKey()
s, hence the multiple
selected fields returned.
To help you there is the getFieldsGroupedByResultKey()
that returns a Map<String,List<SelectedField>>
keyed
by result key, that is by the field alias or by the field name.
Modifier and Type | Method and 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 by
FileSystem.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 by
FileSystem.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 by
FileSystem.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 by
FileSystem.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.
|
boolean contains(java.lang.String fieldGlobPattern)
FileSystem.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'.
fieldGlobPattern
- the glob pattern to match fields againstFileSystem.getPathMatcher(String)
boolean containsAnyOf(java.lang.String fieldGlobPattern, java.lang.String... fieldGlobPatterns)
FileSystem.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'.
fieldGlobPattern
- the glob pattern to match fields againstfieldGlobPatterns
- optionally more glob pattern to match fields againstFileSystem.getPathMatcher(String)
boolean containsAllOf(java.lang.String fieldGlobPattern, java.lang.String... fieldGlobPatterns)
FileSystem.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'.
fieldGlobPattern
- the glob pattern to match fields againstfieldGlobPatterns
- optionally more glob pattern to match fields againstFileSystem.getPathMatcher(String)
java.util.List<SelectedField> getFields()
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.
java.util.List<SelectedField> getImmediateFields()
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.
java.util.List<SelectedField> getFields(java.lang.String fieldGlobPattern, java.lang.String... fieldGlobPatterns)
FileSystem.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.
fieldGlobPattern
- the glob pattern to match fields againstfieldGlobPatterns
- optionally more glob pattern to match fields againstjava.util.Map<java.lang.String,java.util.List<SelectedField>> getFieldsGroupedByResultKey()
GraphQLFieldDefinition
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.java.util.Map<java.lang.String,java.util.List<SelectedField>> getFieldsGroupedByResultKey(java.lang.String fieldGlobPattern, java.lang.String... fieldGlobPatterns)
GraphQLFieldDefinition
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.fieldGlobPattern
- the glob pattern to match fields againstfieldGlobPatterns
- optionally more glob pattern to match fields against