View Source Neuron (neuron v5.1.0)
Neuron is a GraphQL client for elixir.
usage
Usage
iex> Neuron.Config.set(url: "https://example.com/graph")
iex> Neuron.query("""
{
films {
title
}
}
""")
# Response will be:
{:ok, %Neuron.Response{body: %{"data" => {"films" => [%{"title" => "A New Hope"}]}}%, status_code: 200, headers: []}}
# You can also run mutations
iex> Neuron.query("""
mutation createUser($name: String!) {
createUser(name: $name) {
id
name
}
}
""",
%{name: "uesteibar"}
)
Link to this section Summary
Functions
runs a query request to your graphql endpoint.
Link to this section Functions
@spec query(query_string :: String.t(), variables :: map(), options :: keyword()) :: {:ok, Neuron.Response.t()} | {:error, Neuron.Response.t() | Neuron.JSONParseError.t() | HTTPoison.Error.t()}
runs a query request to your graphql endpoint.
example
Example
Neuron.query("""
{
films {
count
}
}
""")
You can pass variables for your query
example-1
Example
Neuron.query(
"""
mutation createUser($name: String!) {
createUser(name: $name) {
id
name
}
}
""",
%{name: "uesteibar"}
)
You can also overwrite parameters set on Neuron.Config
by passing them as options.
example-2
Example
Neuron.query(
"""
mutation createUser($name: String!) {
createUser(name: $name) {
id
name
}
}
""",
%{name: "uesteibar"},
url: "https://www.other.com/graphql"
)