Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maartenvanvliet/artem_introspection_schema
Artem Introspection Schema is a library to build Absinthe schema's from introspection query results
https://github.com/maartenvanvliet/artem_introspection_schema
Last synced: 28 days ago
JSON representation
Artem Introspection Schema is a library to build Absinthe schema's from introspection query results
- Host: GitHub
- URL: https://github.com/maartenvanvliet/artem_introspection_schema
- Owner: maartenvanvliet
- License: mit
- Created: 2021-01-03T21:14:03.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-03-03T04:58:19.000Z (almost 2 years ago)
- Last Synced: 2024-11-20T12:58:17.288Z (about 1 month ago)
- Language: Erlang
- Size: 65.4 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Artem.IntrospectionSchema
## [![Hex pm](http://img.shields.io/hexpm/v/artem_introspection_schema.svg?style=flat)](https://hex.pm/packages/artem_introspection_schema) [![Hex Docs](https://img.shields.io/badge/hex-docs-9768d1.svg)](https://hexdocs.pm/artem_introspection_schema) [![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)![.github/workflows/elixir.yml](https://github.com/maartenvanvliet/artem_introspection_schema/workflows/.github/workflows/elixir.yml/badge.svg)
---
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](https://hex.pm/docs/publish), the package can be installed
by adding `artem_introspection_schema` to your list of dependencies in `mix.exs`:```elixir
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:
```elixir
defmodule TestIntrospection do
use Absinthe.Schema
import Artem.ImportIntrospectionimport_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](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/artem_introspection_schema](https://hexdocs.pm/artem_introspection_schema).