View Source BridgeEx.Graphql (bridge_ex v2.4.1)
Create a Graphql bridge in the given module.
Once created, a graphql request can be made via MyBridge.call("my-query", %{"variable": "var"})
Options
endpoint: URL of the remote Graphql endpoint.auth0: enable and configure Auth0 for authentication of requests. Takes the form of[enabled: false, audience: "target-audience"].encode_variables: if true, encode the Graphql variables to JSON. Defaults tofalse.format_response: transforms camelCase keys in response to snake_case. Defaults tofalse.format_variables: transforms snake_case variable names to camelCase. Defaults tofalse.http_headers: HTTP headers for the request. Defaults to%{"Content-type": "application/json"}.http_options: HTTP options to be passed to Telepoison. Defaults to[timeout: 1_000, recv_timeout: 16_000].log_options: override global configuration for logging errors. Takes the form of[log_query_on_error: false, log_response_on_error: false].max_attempts: number of times the request will be retried upon failure. Defaults to1. ⚠️ Deprecated: useretry_optionsinstead.decode_keys: determines how JSON keys in GraphQL responses are decoded. Can be set to:atoms,:stringsor:existing_atoms. Currently, the default mode is:atomsbut will be changed to:stringsin a future version of this library. You are highly encouraged to set this option to:stringsto avoid memory leaks and security concerns.retry_options: override configuration regarding retries, namelydelay: meaning depends ontiming:constant: retry everdelayms:exponential: start retrying withdelayms
max_retries. Defaults to0policy: a function that takes an error as input and returnstrue/falseto indicate whether to retry the error or not. Defaults to "always retry" (fn _ -> true end).timing: either:exponentialor:constant, indicates how frequently retries are made (e.g. every 1s, in an exponential manner and so on). Defaults to:exponential
Examples
defmodule MyBridge do
use BridgeEx.Graphql, endpoint: "http://my-api.com/graphql"
end
defmodule MyBridge do
use BridgeEx.Graphql,
endpoint: "http://my-api.com/graphql",
auth0: [enabled: true, audience: "target-audience", client: :target_client]
end
# If you would like to configure these options to use values evaluated at runtime,
# you can do so through your application config, e.g.
config :bridge_ex, MyBridge,
endpoint: Application.fetch_env!(:my_app, :service_endpoint)