Grapher v0.9.1 Grapher.Context View Source
A Query Execution Context, this module handles managing any shared data that should be included across multiple Grapher queries.
When executing a query Grapher expects to find any existing context in the Grapher.State
server. A Context remains valid for the duration of a process.
Structure
The Grapher.Context.t/0
struct holds two types of data:
- headers
- args
headers - The headers attribute shoud hold any HTTP Request headers (Grapher.Context.header_data/0
) which should be included with any subsequent grapher
request. These aren’t headers that are the same for a service but rather anything that might vary. For example, say you have a public API which needs to query multiple services (or a single service multiple times) in order to serve an external request. It may be useful to share a Request-ID
value across all the internal service calls for the purposes of logging or other tracing activities.
args - The args attribute is also available if you happen to have an argument that is common to all your queries and that you maybe need to retrieve in an initial query or just need to keep things DRY for multiple reasons.
Link to this section Summary
Functions
Creates a new empty context
Creates a new context
Updates the given struct by merging the given parameters
Link to this section Types
data() :: [headers: header_data(), args: Grapher.GraphQL.Request.var_data()]
t() :: %Grapher.Context{ args: Grapher.GraphQL.Request.var_data(), headers: header_data() }
Link to this section Functions
Creates a new context
Parameters
data
: AKeyword.t
of initialization data (Grapher.Context.data/0
), this parameter is optional and if omitted you will simply get back and emptyGrapher.Context.t/0
struct.
Examples
iex> Context.new(headers: ["request-id": "33"])
%Context{headers: ["request-id": "33"]}
iex> Context.new(args: %{user_id: "33"})
%Context{args: %{user_id: "33"}}
iex> Context.new(headers: ["request-id": "33"], args: %{user_id: "33"})
%Context{headers: ["request-id": "33"], args: %{user_id: "33"}}
update(Grapher.Context.t(), data()) :: Grapher.Context.t()
Updates the given struct by merging the given parameters.
Parameters
updates
: AKeyword.t
of data to be updated (Grapher.Context.data/0
), the values of the given keys are merged into any existing data.
Examples
iex> Context.update(existing(), headers: ["request-ip": "2.3.4.5"])
%Context{headers: ["request-id": "33", "request-ip": "2.3.4.5"]}
iex> Context.update(existing(), headers: ["request-id": "42"])
%Context{headers: ["request-id": "42"]}
iex> Context.update(%Context{}, headers: ["request-ip": "2.3.4.5"])
%Context{headers: ["request-ip": "2.3.4.5"]}