graphql-schema-from-introspection-generator-core

Generate GraphQL Schema (GraphQL DSL or SDL) based on introspection query result

License

License

Categories

Categories

Introspection Application Layer Libs
GroupId

GroupId

io.github.mstachniuk
ArtifactId

ArtifactId

graphql-schema-from-introspection-generator-core
Last Version

Last Version

0.2.2
Release Date

Release Date

Type

Type

jar
Description

Description

graphql-schema-from-introspection-generator-core
Generate GraphQL Schema (GraphQL DSL or SDL) based on introspection query result
Project URL

Project URL

https://github.com/mstachniuk/graphql-schema-from-introspection-generator
Source Code Management

Source Code Management

https://github.com/mstachniuk/graphql-schema-from-introspection-generator.git

Download graphql-schema-from-introspection-generator-core

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.mstachniuk/graphql-schema-from-introspection-generator-core/ -->
<dependency>
    <groupId>io.github.mstachniuk</groupId>
    <artifactId>graphql-schema-from-introspection-generator-core</artifactId>
    <version>0.2.2</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.mstachniuk/graphql-schema-from-introspection-generator-core/
implementation 'io.github.mstachniuk:graphql-schema-from-introspection-generator-core:0.2.2'
// https://jarcasting.com/artifacts/io.github.mstachniuk/graphql-schema-from-introspection-generator-core/
implementation ("io.github.mstachniuk:graphql-schema-from-introspection-generator-core:0.2.2")
'io.github.mstachniuk:graphql-schema-from-introspection-generator-core:jar:0.2.2'
<dependency org="io.github.mstachniuk" name="graphql-schema-from-introspection-generator-core" rev="0.2.2">
  <artifact name="graphql-schema-from-introspection-generator-core" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.mstachniuk', module='graphql-schema-from-introspection-generator-core', version='0.2.2')
)
libraryDependencies += "io.github.mstachniuk" % "graphql-schema-from-introspection-generator-core" % "0.2.2"
[io.github.mstachniuk/graphql-schema-from-introspection-generator-core "0.2.2"]

Dependencies

compile (2)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.2.31
com.beust : klaxon jar 3.0.1

Project Modules

There are no modules declared in this project.

GraphQL Schema from Introspection generator

MIT License Build Status Maven Central Bintray codecov

This library helps you generate GraphQL Schema (also called GraphQL DSL or SDL) based on Introspection Query response. It's useful when you use graphql-java and Code First approach and want to migrate to Schema First approach.

How to use it?

  1. Download Command Line Tool from releases page.

  2. Run java -jar graphql-schema-from-introspection-generator-cli-X.X.X.jar input.json output.graphqls

    File input.json should contain the output of GrpahQL Introspection query. If you don't have this file yet, you can use one from: core/src/test/resources/testdata/

  3. In output.graphqls you will find generated GraphQL Schema.

How get Introspection Query result?

  1. Run your application.

  2. Run

    Introspection Query
        query IntrospectionQuery {
          __schema {
            queryType { name }
            mutationType { name }
            subscriptionType { name }
            types {
              ...FullType
            }
            directives {
              name
              description
              locations
              args {
                ...InputValue
              }
            }
          }
        }
      
        fragment FullType on __Type {
          kind
          name
          description
          fields(includeDeprecated: true) {
            name
            description
            args {
              ...InputValue
            }
            type {
              ...TypeRef
            }
            isDeprecated
            deprecationReason
          }
          inputFields {
            ...InputValue
          }
          interfaces {
            ...TypeRef
          }
          enumValues(includeDeprecated: true) {
            name
            description
            isDeprecated
            deprecationReason
          }
          possibleTypes {
            ...TypeRef
          }
        }
      
        fragment InputValue on __InputValue {
          name
          description
          type { ...TypeRef }
          defaultValue
        }
      
        fragment TypeRef on __Type {
          kind
          name
          ofType {
            kind
            name
            ofType {
              kind
              name
              ofType {
                kind
                name
                ofType {
                  kind
                  name
                  ofType {
                    kind
                    name
                    ofType {
                      kind
                      name
                      ofType {
                        kind
                        name
                      }
                    }
                  }
                }
              }
            }
          }
        }
    

    This query based on Introspection Queries in graphql-java and GraphiQL projects.

  3. Store result in a file and use Command Line tool for generating the schema (See: How to use it?).

Release Notes

Release notes: docs/release-notes.md

How to build project?

  1. Clone repo
  2. Run ./gradlew build
  3. You can find Command Line Tool in cli/build/libs
  4. You can find core library in core/build/libs

Another usage

You can use the core library in your projects if you want. Just add a dependency (in Gradle):

compile group: 'io.github.mstachniuk', name: 'graphql-schema-from-introspection-generator-core'

How to contribute?

Please Send PR's, issues and feedback via GitHub.

Alternatives

During finishing this project I found that similar tool already exists in graphql-java project, see IntrospectionResultToSchema class.

Another possibility is to use graphql-js and this code snippet (NodeJS):

const graphql = require("graphql");
const schema = require("path/to/schema.json");

const clientSchema = graphql.buildClientSchema(schema.data);
const schemaString = graphql.printSchema(clientSchema);
console.log(schemaString)

Unfortunately, I didn't know that before :-(

Versions

Version
0.2.2
0.2.1
0.2.0
0.1.7
0.1.6
0.1.5
0.1.4