Skip to content
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.

Selection Syntax

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 the a attribute. Yields: {a: true}
  • a{b} - select the b sub-attribute of a (i.e. a.b). Yields: {a: {b: true}}
  • a{b,c} - select both b and c from a. Yields: {a: {b: true, c: true}}
  • a{b{c}} - select c from b from a (i.e. a.b.c). Yields: {a: {b: {c: true}}}
  • a,b{c} - select a, and the c sub-attribute of b. Yields: {a: true, b: {c: true}}.
Clone this wiki locally