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

Link to this section Functions

Creates a new empty context

Examples

iex> Context.new()
%Context{}

Creates a new context

Parameters

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"}}

Updates the given struct by merging the given parameters.

Parameters

  • updates: A Keyword.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"]}