View Source Artem.ImportIntrospection (Artem Introspection Schema v0.2.0)
Library to create Absinthe schema's from introspection queries.
This can be used to e.g. create Graphql clients which verify outgoing graphql documents against external schema's created from introspection. This can provide e.g. compile time safety of those documents, so you can be sure that the graphql documents you write will validate against the external schema.
It leverages the same import mechanism as the SDL schema's in Absinthe.
Installation
If available in Hex, the package can be installed
by adding artem_introspection_schema
to your list of dependencies in mix.exs
:
def deps do
[
{:artem_introspection_schema, "~> 0.1.0"}
]
end
Usage
Given the results of an introspection query you can create an Absinthe schema as follows:
defmodule TestIntrospection do
use Absinthe.Schema
import Artem.ImportIntrospection
import_introspection path: "test/fixtures/test.json"
@pipeline_modifier __MODULE__
def pipeline(pipeline) do
pipeline
|> Absinthe.Pipeline.without(Absinthe.Phase.Schema.Validation.InterfacesMustResolveTypes)
end
end
Note that a pipeline modifier is applied to not validate interfaces. Since this is an external schema we don't have any resolvers or ways to resolve interfaces, so this phase can be skipped. Depending on the external schema there may be other (validation) phases that have to be skipped because e.g. they use an older or newer version of the grapql spec and Absinthe doesn't validate them accordingly.
Schema providers
You can also use a schema provider to retrieve the schema. This is a flexible way if you want to load the introspection results more dynamically, e.g. over http.
See Artem.SchemaProvider
for an example and Artem.ImportIntrospection.import_introspection/2
Documentation
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/artem_introspection_schema.
Link to this section Summary
Functions
Import types defined using the results of the introspection query.
Link to this section Types
Specs
Link to this section Functions
Import types defined using the results of the introspection query.
Examples
import_introspection path: "/path/to/introspection.json"
import_introspection provider: {FileProvider, file: "test/fixtures/test.json"}
Specs
import_introspection(String.t() | Macro.t(), [import_introspection_option()]) :: Macro.t()