Yson.GraphQL.Schema (yson v0.2.2) View Source

Defines a Yson GraphQL Schema.

It is an extension of Yson.Schema that represents a GraphQL request and response object. The request is built using query/3 or mutation/3 while the response and its parsing are defined by the Yson.Schema.root/2 tree.

defmodule Person do
  use Yson.GraphQL.Schema

  query :person do
    arg(:street, :string)
  end

  root do
    map :address do
      value(:street)
      value(:city)
    end

    value(:name)
  end
end

Root must be defined once using Yson.Schema.root/2 macro.

After the definition, a GraphQL Schema exposes two methods:

  • describe/0, to build the object description. It can be used with Yson.GraphQL.Builder.build/2 to create a GraphQL request.
  • resolvers/0, to build the object resolvers tree. It can be used with Yson.Parser.parse/3 to parse a GraphQL response.

Link to this section Summary

Functions

Defines a basic GraphQL argument.

Defines a complex GraphQL argument.

Defines a GraphQL mutation.

Defines a GraphQL query.

Link to this section Functions

Link to this macro

arg(name, type)

View Source (macro)

Defines a basic GraphQL argument.

It can be used inside mutation/3, query/3 or arg/3 macros.

Examples

arg(:name, :string)
Link to this macro

arg(name, opts \\ [], list)

View Source (macro)

Defines a complex GraphQL argument.

It contains args and can be used inside mutation/3, query/3 or arg/3 macros.

Examples

arg :address do
  arg(:street, :string)
  arg(:city, :string)
end
Link to this macro

mutation(name, opts \\ [], list)

View Source (macro)

Defines a GraphQL mutation.

It specifies the mutation name and its arguments.

Examples

mutation :person do
  arg(:street, :string)
end
Link to this macro

query(name, opts \\ [], list)

View Source (macro)

Defines a GraphQL query.

It specifies the query name and its arguments. It has to be defined exactly once, and it is mutually exclusive with mutation/3.

Examples

query :person do
  arg(:street, :string)
end