Field selection occurs when you have a compound type (an object or interface type) and you select a set of sub fields from that type.
For example given the following query :
The field selection set of the
user field is
Knowing the field selection set can help make
DataFetchers more efficient. For example in the above query
imagine that the
user field is backed by an SQL database system. The data fetcher could look ahead into the field selection
set and use different queries because it knows the caller wants friend information as well as user information.
graphql.schema.DataFetchingFieldSelectionSet is used to represent this field selection set. It gives you maps
of the fields and their
graphql.schema.GraphQLFieldDefinitions and argument values.
A glob path matching system is used for addressing fields in the selection. Its based on
as an implementation.
This will allow you to use
? as special matching characters such that
invoice field with child fields that start with
customer. Each level of field is separated by
/ just like
a file system path.
There are methods that allow you to get more detailed information about the fields in the selection set. For example
if you are using Relay often you want to know what fields have
been request in the
Connection section of the query.
So given a query like:
you can write code that gets the details of each specific field that matches a glob.
If the field is a union or iterface type then it is not possible to know exactly that concrete object type the result will be BEFORE the field is resolved into a value.
There in fact be multiple possible
This is represented a list of possible fields and having two addressing mechanisms, a simple
x/y one and the more specific
For example imagine a
Pet interface type that has
Dog object type implementations. The query might be:
In the example above you have a
Dog.name as possible sub selections of the
pet field. They are can be addressed by either
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.
In the example above the
selectionSet.getFields("name") actually returns three SelectedFields, one
Dog.name, one for
Cat.name and one for
Dog.name with an alias of
The arguments can differ on
SelectedFields 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.