simple_graphql_client v0.1.0 SimpleGraphqlClient View Source
SimpleGraphqlClient is a graphql client, focused on simplicity and ease of use.
Usage
iex>
query = "query users($name: String){users(name: $name){name}}"
SimpleGraphqlClient.graphql_request(query, %{name: "Boris"})
# Will produce
{:ok,
%SimpleGraphqlClient.Response{
body: {:ok, %{"data" => %{"users" => []}}},
headers: [],
status_code: 200
}
}
If you planning to use it only against single endpoint i suggest you to config it in config.exs
config :simple_graphql_client, url: "http://example.com/graphql"
Link to this section Summary
Functions
Execute request to graphql endpoint
- query - any valid graphql query
- variables - pass a map with variables to pass alongside with query
- opts - supports overiding url with :url key and passing list of additional headers e.g for authorization
Link to this section Functions
Link to this function
graphql_request(query, variables \\ nil, opts \\ %{})
View Source
graphql_request(binary(), map() | nil, map()) :: {:ok, SimpleGraphqlClient.Response.t()} | {:error, SimpleGraphqlClient.Response.t() | any()}
Execute request to graphql endpoint
- query - any valid graphql query
- variables - pass a map with variables to pass alongside with query
- opts - supports overiding url with :url key and passing list of additional headers e.g for authorization
Usage
SimpleGraphqlClient.graphql_request(query, %{name: "Boris"}, %{url: "http://example.com/graphql", headers: token: "1234"})