View Source GraphQLDocument.Field (GraphQLDocument v0.2.2)
A Field describes one discrete piece of information available to request within a selection set.
Scalar fields (e.g. Ints, Booleans, and Strings) are requested by their name.
:name
:email
Whereas object fields must be given with child fields as well.
[
user: [:name, email]
]
Link to this section Summary
Types
An expression of a field with an alias or directives.
Fields can be expressed a number of different ways.
Functions
Allows you to specify a complex Field expression with Arguments, Directives, Selections, and an Alias.
Returns a Field as iodata to be inserted into a Document.
Link to this section Types
@type spec() :: {:field, as: atom(), args: [GraphQLDocument.Argument.t()], directives: [GraphQLDocument.Directive.t()], select: [GraphQLDocument.Selection.t()]}
An expression of a field with an alias or directives.
@type t() :: GraphQLDocument.Name.t() | {GraphQLDocument.Name.t(), [t()]} | {GraphQLDocument.Name.t(), {[GraphQLDocument.Argument.t()], [t()]}} | spec()
Fields can be expressed a number of different ways.
If the field is a scalar type, provide a String
or Atom
:
[:id, :firstName, :lastName]
If the field is an object type, express it as a keyword list with either
[fields]
or {args, fields}
as the value of each key:
[
friends: {[first: 10], [:name]}, # with args
birthday: [:month, :day], # with sub-fields, but no args
]
See render/2
for examples of how different Elixir expressions are rendered
as GraphQL syntax.
Link to this section Functions
Allows you to specify a complex Field expression with Arguments, Directives, Selections, and an Alias.
@spec render(t(), pos_integer()) :: iolist()
Returns a Field as iodata to be inserted into a Document.
examples
Examples
iex> render(:email, 1)
...> |> IO.iodata_to_binary()
"email"
iex> render({:self, [:name, :email]}, 1)
...> |> IO.iodata_to_binary()
"""
self {
name
email
}\
"""
iex> {:user, {:field,
...> args: [id: 100],
...> select: [:name, :email]
...> }}
...> |> render(1)
...> |> IO.iodata_to_binary()
"""
user(id: 100) {
name
email
}\
"""
iex> {:user, {:field,
...> args: [id: 100],
...> directives: [log: [level: "warn"]],
...> select: [:name, :email]
...> }}
...> |> render(1)
...> |> IO.iodata_to_binary()
"""
user(id: 100) @log(level: "warn") {
name
email
}\
"""
iex> {:me, {:field,
...> :user,
...> args: [id: 100],
...> directives: [log: [level: "warn"]],
...> select: [:name, :email]
...> }}
...> |> render(1)
...> |> IO.iodata_to_binary()
"""
me: user(id: 100) @log(level: "warn") {
name
email
}\
"""