Documentation
API
Providing Schema

Providing Schema

There are a few options to provide your schema in GraphQL Inspector.

JavaScript And TypeScript File

GraphQL Inspector accepts CommonJS and ESModules

// Example for loading and merging multiple .graphql files into a single schema
const { makeExecutableSchema } = require('@graphql-tools/schema')
const { loadFilesSync } = require('@graphql-tools/load-files')
 
const typeDefs = loadFilesSync('**/*.graphql')
 
module.exports = makeExecutableSchema({ typeDefs })

If you need to transpile a file, use --require option of the CLI:

graphql-inspector introspect ./schema.ts --require ts-node/register

GraphQL File

Files with those extensions: .graphql, .graphqls or .gql are supported by GraphQL Inspector.

graphql-inspector diff ./old-schema.graphql ./new-schema.gql

JSON File

A JSON file with introspection results can also be provided:

graphql-inspector diff ./old-schema.json ./new-schema.json

GraphQL Endpoint

GraphQL Inspector can also introspect your GraphQL server:

graphql-inspector diff http://api.com/graphql ./new-schema.json

Git Repository

Get GraphQL Schema file from any branch or commit of your git repository:

git:origin/branch:path/to/file

For example, you want to get schema.graphql from origin/master:

git:origin/master:./schema.graphql

GitHub Repository

Yes, GraphQL Inspector can also do that, here’s the pattern:

github:owner/name#ref:path/to/file
  • github - stays there, it tells Inspector we want to use GitHub
  • owner - your GitHub username or organization
  • name - repository’s name
  • ref - can be the name of a branch or commit sha
  • path/to/file - where Inspector can find the GraphQL file

For example, we want to fetch a .graphql file from master branch of this sample repository:

github:kamilkisiela/graphql-inspector-example#master:./schema.graphql --token 'github-token-here'
⚠️

GitHub Loader requires a GitHub token to be defined!

Programmatic API

If you are using programmatic API, you might find @graphql-tools/load package useful for loading schemas. Learn more here.