View Source GraphQLDocument.Variable (GraphQLDocument v0.2.2)

Variables are defined in VariableDefinitions alongside the OperationType at the beginning of a GraphQL document.

Any Variable that is defined in a Document can be used as the value of an Argument.

Link to this section Summary

Types

These are given in the variables key of the Operation options. (See GraphQLDocument.Operation.option/0.)

Options that can be passed when defining a variable.

t()

Expresses the name of a Variable to be used as a Value (See GraphQLDocument.Value)

Functions

Returns a Variable as iodata to be inserted into a Document.

Returns Variable definitions as iodata to be inserted into a Document.

Link to this section Types

These are given in the variables key of the Operation options. (See GraphQLDocument.Operation.option/0.)

This is not the usage of the Variable (as the Value of an Argument) but rather defining its Name and Type to be used in the rest of the Document.

examples

Examples

GraphQLDocument.query(
  [...],
  variables: [
    yearOfBirth: Int,
    myId: {Int, null: false},
    status: {String, default: "active"},
    days: [String],
    daysOfWeek: {[String], default: ["Saturday", "Sunday"]}
  ]
)
@type option() ::
  {:default, GraphQLDocument.Value.t()} | GraphQLDocument.Type.option()

Options that can be passed when defining a variable.

For the default option, pass any GraphQLDocument.Value.t/0.

See definition/0 for examples.

@type t() :: {:var, GraphQLDocument.Name.t()}

Expresses the name of a Variable to be used as a Value (See GraphQLDocument.Value)

Link to this section Functions

Returns a Variable as iodata to be inserted into a Document.

examples

Examples

iex> render({:var, :expandedInfo})
...> |> IO.iodata_to_binary()
"$expandedInfo"

iex> render({:var, "username"})
...> |> IO.iodata_to_binary()
"$username"

iex> render({:var, ""})
...> |> IO.iodata_to_binary()
** (ArgumentError) [empty string] is not a valid GraphQL name
Link to this function

render_definitions(variables)

View Source
@spec render_definitions(definition()) :: iodata()

Returns Variable definitions as iodata to be inserted into a Document.

Leading Space

If any definitions are given, the returned iodata includes a leading space so that the output can be inserted into a Document either way and generate valid GraphQL syntax.

examples

Examples

iex> render_definitions([])
...> |> IO.iodata_to_binary()
""

iex> render_definitions([myInt: Int, debug: Boolean])
...> |> IO.iodata_to_binary()
" ($myInt: Int, $debug: Boolean)"

iex> render_definitions(lat: Float, lng: Float)
...> |> IO.iodata_to_binary()
" ($lat: Float, $lng: Float)"