-
Notifications
You must be signed in to change notification settings - Fork 16
FieldSelector
Dane Jensen edited this page Dec 10, 2015
·
2 revisions
The FieldSelector type makes it easy to define an attribute that represents the selection of a set of fields for a query, similar to GraphQL.
Its load
method parses a selector string in to a hash representation.
The field selection syntax is a simple comma-separated list of attributes to select, with sub-attributes being selectable by enclosing them in curly-braces ("{}").
This is parsed by FieldSelector
to a nested hash, with field names as keys, and values of either true
to indicate that field was selected or a sub-hash with additional sub-fields for selection.
Examples:
-
a
- select thea
attribute. Yields:{a: true}
-
a{b}
- select theb
sub-attribute ofa
(i.e.a.b
). Yields:{a: {b: true}}
-
a{b,c}
- select bothb
andc
froma
. Yields:{a: {b: true, c: true}}
-
a{b{c}}
- selectc
fromb
froma
(i.e.a.b.c
). Yields:{a: {b: {c: true}}}
-
a,b{c}
- selecta
, and thec
sub-attribute ofb
. Yields:{a: true, b: {c: true}}.