Installation

To install ExGraphQL, just add an entry to your mix.exs:

def deps do
  [
    # ...
    {:ex_graphql, "~> 0.1"}
  ]
end

(Check Hex to make sure you're using an up-to-date version number.)

Configure first object

defmodule MyApp.GQLObject.Organization do
  use ExGraphQL.Object

  gql_field(:id, :integer)
  gql_field(:name, :string)
  gql_field(:country, :string)
end

Declare a nested object

defmodule MyApp.GQLObject.Team do
  use ExGraphQL.Object

  gql_field(:id, :integer)
  gql_field(:name, :string)
  gql_field(:organization, MyApp.GQLObject.Organization)
end

Make your first query

defmodule MyApp.GraphAPI do
  base_url = "https://api.graph-provider/graphql"
  token = System.get_env("graph_api_token", "")
  query = ExGraphQL.QueryBuilder.build_query(MyApp.Object.Team)
  ExGraphQL.Client.execute(base_url, token, query)
end

Add filter to your query

defmodule MyApp.GraphAPI do
  base_url = "https://api.graph-provider/graphql"
  token = System.get_env("graph_api_token", "")
  query = ExGraphQL.QueryBuilder.build_query(MyApp.Object.Team, 
    name: [eq: "my-team"],
    organization: [
      country: [contains: "ita"]
    ]
  )
  ExGraphQL.Client.execute(base_url, token, query)
end