GraphqlQuery.Schema.Remote.Introspection (graphql_query v0.6.2)

View Source

Converts 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 like String, Int, etc. are skipped)
  • OBJECT — object types with fields (introspection types prefixed with __ are skipped)
  • INPUT_OBJECT — input types with input fields
  • ENUM — enum types with values (introspection enums prefixed with __ are skipped)
  • INTERFACE — interface types with fields
  • UNION — 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

introspection_query()

@spec introspection_query() :: GraphqlQuery.Document.t()

Returns the introspection document.

This is the standard GraphQL introspection query including descriptions, subscription type, and directive repeatability.

to_sdl(schema)

@spec to_sdl(map()) :: {:ok, String.t()} | {:error, String.t()}

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