GraphqlQuery.Schema.Remote.Introspection (graphql_query v0.6.2)
View SourceConverts a GraphQL introspection query result into SDL (Schema Definition Language).
Takes the JSON response from a standard introspection query and produces a
.graphql SDL string that can be saved and loaded as a schema file.
Supported Types
All standard GraphQL type kinds are handled:
SCALAR— custom scalars (built-in scalars likeString,Int, etc. are skipped)OBJECT— object types with fields (introspection types prefixed with__are skipped)INPUT_OBJECT— input types with input fieldsENUM— enum types with values (introspection enums prefixed with__are skipped)INTERFACE— interface types with fieldsUNION— union types with possible types- Directives — all directives including built-ins
- Schema definition — emitted when root type names are non-standard
Descriptions, deprecation annotations, and default values are preserved.
Summary
Functions
Returns the introspection document.
Converts an introspection query result map to a GraphQL SDL string.
Functions
@spec introspection_query() :: GraphqlQuery.Document.t()
Returns the introspection document.
This is the standard GraphQL introspection query including descriptions, subscription type, and directive repeatability.
Converts an introspection query result map to a GraphQL SDL string.
Accepts either the full response %{"data" => %{"__schema" => ...}} or
just the schema portion %{"__schema" => ...} or %{"queryType" => ..., "types" => ...}.
Returns {:ok, sdl} on success or {:error, reason} on failure.
Examples
iex> result = %{"data" => %{"__schema" => %{"queryType" => %{"name" => "Query"}, "types" => [...], "directives" => [...]}}}
iex> {:ok, sdl} = GraphqlQuery.Schema.Remote.Introspection.to_sdl(result)
iex> String.contains?(sdl, "type Query")
true