Packages
absinthe
0.4.1
1.11.0
1.10.2
1.10.1
1.10.0
1.9.1
1.9.0
1.8.0
1.7.11
1.7.10
1.7.9
1.7.8
1.7.7
1.7.6
1.7.5
1.7.4
1.7.3
1.7.2
1.7.1
1.7.0
1.6.8
1.6.7
retired
1.6.6
1.6.5
1.6.4
1.6.3
1.6.2
1.6.1
1.6.0
1.6.0-rc.1
1.6.0-rc.0
1.5.5
1.5.4
1.5.3
1.5.2
1.5.1
1.5.0
1.5.0-rc.5
1.5.0-rc.4
1.5.0-rc.3
1.5.0-rc.2
1.5.0-rc.1
1.5.0-rc.0
1.5.0-beta.2
1.5.0-beta.1
1.5.0-beta.0
1.5.0-alpha.4
1.5.0-alpha.3
1.5.0-alpha.2
1.5.0-alpha.1
1.5.0-alpha.0
1.4.16
1.4.15
1.4.14
1.4.13
1.4.12
1.4.11
1.4.10
1.4.9
1.4.8
retired
1.4.7
1.4.6
1.4.5
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.4.0-rc.3
1.4.0-rc.2
1.4.0-rc.1
1.4.0-rc.0
1.4.0-beta.5
1.4.0-beta.4
1.4.0-beta.3
1.4.0-beta.2
1.4.0-beta.1
1.3.2
1.3.1
1.3.0
1.3.0-rc.0
1.3.0-beta.2
1.3.0-beta.1
1.3.0-beta.0
1.2.6
1.2.5
1.2.4
1.2.3
1.2.2
1.2.1
1.2.0
1.2.0-rc.0
1.2.0-beta.0
1.2.0-alpha0
1.2.0-alpha.2
1.2.0-alpha.1
1.1.11
1.1.10
1.1.9
1.1.8
1.1.7
1.1.6
1.1.5
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.0
0.5.2
0.5.1
0.5.0
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.2.3
0.2.2
0.2.1
0.1.0
GraphQL for Elixir
Current section
Files
Jump to
Current section
Files
lib/absinthe/introspection/types.ex
defmodule Absinthe.Introspection.Types do
@moduledoc false
use Absinthe.Type.Definitions
alias Absinthe.Flag
alias Absinthe.Type
@absinthe :type
def __schema do
%Type.Object{
name: "__Type",
description: "Represents a schema",
fields: fields(
types: [
type: list_of(:__type),
resolve: fn
_, %{schema: schema} ->
schema.types.by_identifier
|> Map.values
|> Enum.filter(&(!match?("__" <> _, &1.name)))
|> Flag.as(:ok)
end
],
query_type: [
type: :__type,
resolve: fn
_, %{schema: schema} ->
{:ok, schema.query}
end
],
mutation_type: [
type: :__type,
resolve: fn
_, %{schema: schema} ->
{:ok, schema.mutation}
end
],
directives: [
type: list_of(:__directive),
resolve: fn
_, _ ->
{:ok, []} # TODO
end
]
)
}
end
@absinthe :type
def __directive do
%Type.Object{
name: "__Directive",
description: "Represents a directive",
fields: fields(
name: [type: :string],
description: [type: :string],
args: [type: list_of(:__inputvalue)],
on_operation: [type: :boolean],
on_fragment: [type: :boolean],
on_field: [type: :boolean]
)
}
end
@absinthe :type
def __type do
%Type.Object{
name: "__Type",
description: "Represents scalars, interfaces, object types, unions, enums in the system",
fields: fields(
kind: [
type: :string,
resolve: fn
_, %{resolution: %{target: %{__struct__: type}}} ->
{:ok, type.kind}
end
],
name: [type: :string],
description: [type: :string],
fields: [
type: list_of(:__field),
args: args(
include_deprecated: [
type: :boolean,
default_value: false
]
),
resolve: fn
%{include_deprecated: show_deprecated}, %{resolution: %{target: %{__struct__: str, fields: fields}}} when str in [Type.Object, Type.Interface] ->
fields
|> Enum.flat_map(fn
{_, %{deprecation: is_deprecated} = field} ->
if !is_deprecated || (is_deprecated && show_deprecated) do
[field]
else
[]
end
end)
|> Flag.as(:ok)
_, _ ->
{:ok, nil}
end
],
interfaces: [
type: list_of(:__type),
resolve: fn
_, %{schema: schema, resolution: %{target: %{interfaces: interfaces}}} ->
structs = interfaces
|> Enum.map(fn
ident -> schema.types[ident]
end)
{:ok, structs}
_, _ ->
{:ok, nil}
end
],
possible_types: [
type: list_of(:__type),
resolve: fn
_, %{schema: schema, resolution: %{target: %Type.Union{types: types}}} ->
structs = types |> Enum.map(&(Absinthe.Schema.lookup_type(schema, &1)))
{:ok, structs}
_, %{schema: schema, resolution: %{target: %Type.Interface{reference: %{identifier: ident}}}} ->
implementors = schema.interfaces[ident]
structs = implementors |> Enum.map(fn name -> schema.types[name] end)
{:ok, structs}
_, _ ->
{:ok, nil}
end
],
enum_values: [
type: list_of(:__enumvalue),
args: args(
include_deprecated: [
type: :boolean,
default_value: false
]
),
resolve: fn
%{include_deprecated: show_deprecated}, %{resolution: %{target: %Type.Enum{values: values}}} ->
values
|> Enum.flat_map(fn
{_, %{deprecation: is_deprecated} = value} ->
if !is_deprecated || (is_deprecated && show_deprecated) do
[value]
else
[]
end
end)
|> Flag.as(:ok)
_, _ ->
{:ok, nil}
end
],
input_fields: [
type: list_of(:__inputvalue),
resolve: fn
_, %{resolution: %{target: %Type.InputObject{fields: fields}}} ->
structs = fields |> Map.values
{:ok, structs}
_, _ ->
{:ok, nil}
end
],
of_type: [
type: :__type,
resolve: fn
_, %{schema: schema, resolution: %{target: %{of_type: type}}} ->
Absinthe.Schema.lookup_type(schema, type, unwrap: false)
|> Flag.as(:ok)
_, _ ->
{:ok, nil}
end
]
)
}
end
@absinthe :type
def __field do
%Type.Object{
name: "__Field",
fields: fields(
name: [
type: :string,
resolve: fn
_, %{adapter: adapter, resolution: %{target: target}} ->
target.name
|> adapter.to_external_name(:field)
|> Flag.as(:ok)
end
],
description: [type: :string],
args: [
type: list_of(:__inputvalue),
resolve: fn
_, %{resolution: %{target: target}} ->
structs = target.args |> Map.values
{:ok, structs}
end
],
type: [
type: :__type,
resolve: fn
_, %{schema: schema, resolution: %{target: target}} ->
case target.type do
type when is_atom(type) ->
Absinthe.Schema.lookup_type(schema, target.type)
type ->
type
end
|> Flag.as(:ok)
end
],
is_deprecated: [
type: :boolean,
resolve: fn
_, %{resolution: %{target: %{deprecation: nil}}} ->
{:ok, false}
_, _ ->
{:ok, true}
end
],
deprecation_reason: [
type: :string,
resolve: fn
_, %{resolution: %{target: %{deprecation: nil}}} ->
{:ok, nil}
_, %{resolution: %{target: %{deprecation: dep}}} ->
{:ok, dep.reason}
end
]
)
}
end
@absinthe :type
def __inputvalue do
%Type.Object{
name: "__InputValue",
fields: fields(
name: [
type: :string,
resolve: fn
_, %{adapter: adapter, resolution: %{target: target}} ->
target.name
|> adapter.to_external_name(:field)
|> Flag.as(:ok)
end
],
description: [type: :string],
type: [
type: :__type,
resolve: fn
_, %{schema: schema, resolution: %{target: %{type: ident}}} ->
type = Absinthe.Schema.lookup_type(schema, ident, unwrap: false)
{:ok, type}
end
],
default_value: [
type: :string,
resolve: fn
_, %{resolution: %{target: %{default_value: nil}}} ->
{:ok, nil}
_, %{resolution: %{target: %{default_value: value}}} ->
{:ok, value |> to_string}
_, %{resolution: %{target: _}} ->
{:ok, nil}
end
]
)
}
end
@absinthe :type
def __enumvalue do
%Type.Object{
name: "__EnumValue",
fields: fields(
name: [type: :string],
description: [type: :string],
is_deprecated: [
type: :boolean,
resolve: fn
_, %{resolution: %{target: %{deprecation: nil}}} ->
{:ok, false}
_, _ ->
{:ok, true}
end
],
deprecation_reason: [
type: :string,
resolve: fn
_, %{resolution: %{target: %{deprecation: nil}}} ->
{:ok, nil}
_, %{resolution: %{target: %{deprecation: dep}}} ->
{:ok, dep.reason}
end
]
)
}
end
end