# `RiddlerGraphQL.Types.Scope`
[🔗](https://github.com/riddler/riddler_graphql/blob/v0.1.0/lib/riddler_graphql/types/scope.ex#L1)

The scope a Journey runs under, as GraphQL carries it: `JourneyScopeInput`,
the scope a client names, and `JourneyScope`, the scope a Journey answers.

Both have the two strings of a `Riddler.Journey.Scope`, `kind` and `id`,
each `String!`. GraphQL checks only that both are strings; the scope itself
is checked by `Riddler.Journey.Scope.new/2`, through `to_scope/1`, which
answers `{:error, :invalid_scope}` for a scope that function refuses (an
empty kind or id).

`JourneyScope` reads a `Riddler.Journey.Scope` struct or its data form, the
map of `"kind"` and `"id"` that `Riddler.Journey.Scope.to_data/1` gives. A
host imports the types with `import_types RiddlerGraphQL.Types.Scope`.

# `to_scope`

```elixir
@spec to_scope(term()) :: {:ok, Riddler.Journey.Scope.t()} | {:error, :invalid_scope}
```

The `Riddler.Journey.Scope` a `JourneyScopeInput` argument names.

Takes the argument as Absinthe hands it to a resolver, a map of `:kind`
and `:id`, and answers what `Riddler.Journey.Scope.new/2` answers for the
two: `{:ok, scope}`, or `{:error, :invalid_scope}` for a scope it refuses.
A value that is not that map answers `{:error, :invalid_scope}` too.

    iex> RiddlerGraphQL.Types.Scope.to_scope(%{kind: "patron", id: "P-1001"})
    {:ok, %Riddler.Journey.Scope{kind: "patron", id: "P-1001"}}

    iex> RiddlerGraphQL.Types.Scope.to_scope(%{kind: "branch", id: ""})
    {:error, :invalid_scope}

---

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