Compile-time GraphQL client for Elixir.
Validates GraphQL operations at compile time and generates typed Ecto embedded schemas for responses.
Usage
defmodule MyApp.GitHub do
use Grephql,
otp_app: :my_app,
source: "priv/schemas/github.json"
defgql :get_user, ~GQL"""
query($login: String!) {
user(login: $login) {
name
}
}
"""
endOptions
:otp_app(required) — the OTP application for runtime config lookup:source(required) — path to a schema JSON file (relative to the caller file), or an inline JSON string:scalars— custom scalar type mappings (default:%{}):endpoint— default GraphQL endpoint URL:req_options— default Req options passed directly toReq.new/1(keyword list). Supports all Req options including middleware/plugins. Common examples:- Headers:
req_options: [headers: [authorization: "Bearer token"]] - Timeouts:
req_options: [receive_timeout: 30_000] - Plug (for testing):
req_options: [plug: {Req.Test, MyApp.GitHub}]
You can also attach Req plugins via the
:req_optionskey. Plugins are attached by passing the plugin'sattach/1options:# In config/runtime.exs config :my_app, MyApp.GitHub, req_options: [auth: {:bearer, System.fetch_env!("GITHUB_TOKEN")}] # In test setup config :my_app, MyApp.GitHub, req_options: [plug: {Req.Test, MyApp.GitHub}]- Headers:
Summary
Functions
Executes a compiled GraphQL query.
Functions
@spec execute(Grephql.Query.t(), struct() | map(), keyword()) :: {:ok, Grephql.Result.t()} | {:error, Req.Response.t() | Exception.t()}
Executes a compiled GraphQL query.
Takes a %Grephql.Query{} struct (produced by defgql/defgqlp),
a variables struct (built by Variables.build/1), and optional keyword options.
Options override runtime config which overrides compile-time defaults.