# `Grephql.Result`
[🔗](https://github.com/fahchen/grephql/blob/v0.10.1/lib/grephql/result.ex#L1)

Represents a GraphQL response.

Contains the decoded `data` (typed per-query), any `errors`
returned by the server, and an `assigns` map for user-defined
metadata populated via Req response steps.

## Examples

    {:ok, %Grephql.Result{data: %MyClient.GetUser.Result.User{name: "Alice"}, errors: []}}
    {:ok, %Grephql.Result{data: nil, errors: [%Grephql.Error{message: "Not found"}]}}

## Assigns

The `assigns` field lets you capture arbitrary response metadata
(e.g. rate-limit info from a GraphQL `extensions` field) by using
a Req response step in your client's `prepare_req/1` callback:

    defmodule MyApp.Shopify do
      use Grephql,
        otp_app: :my_app,
        source: "priv/shopify_schema.json"

      def prepare_req(req) do
        Req.Request.append_response_steps(req,
          shopify_extensions: fn {req, resp} ->
            extensions = resp.body["extensions"]
            {req, Grephql.Result.put_resp_assign(resp, :extensions, extensions)}
          end
        )
      end

      defgql :get_products, ~GQL"""
        query { products(first: 10) { edges { node { title } } } }
      """
    end

    {:ok, result} = MyApp.Shopify.get_products()
    result.assigns[:extensions]["cost"]["throttleStatus"]

# `t`

```elixir
@type t() :: t(struct())
```

# `t`

```elixir
@type t(data_type) :: %Grephql.Result{
  assigns: map(),
  data: data_type | nil,
  errors: [Grephql.Error.t()]
}
```

# `put_resp_assign`

```elixir
@spec put_resp_assign(Req.Response.t(), atom(), term()) :: Req.Response.t()
```

Stores a key-value pair in the Grephql assigns area of a `Req.Response`.

Intended for use inside Req response steps. The stored assigns are
automatically transferred to `%Grephql.Result{assigns: ...}` after
the response is decoded.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
