# `TypedGql.Result`
[🔗](https://github.com/fahchen/typed_gql/blob/v0.11.0/lib/typed_gql/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, %TypedGql.Result{data: %MyClient.GetUser.Result.User{name: "Alice"}, errors: []}}
    {:ok, %TypedGql.Result{data: nil, errors: [%TypedGql.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 TypedGql,
        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, TypedGql.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) :: %TypedGql.Result{
  assigns: map(),
  data: data_type | nil,
  errors: [TypedGql.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 TypedGql assigns area of a `Req.Response`.

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

---

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