Documentation
API
Providing Documents

Providing Documents

There are a few ways of providing operations and fragments (documents in general).

JavaScript And TypeScript Files

GraphQL Inspector supports glob pattern.

./src/app/**/*.ts

Given the example above, Inspector will search every file that matches that pattern and extract operations and fragments wrapped with gql or graphql template literal tag.

Supported extensions: .ts, .tsx, .js and .jsx.

GraphQL Files

GraphQL Inspector supports glob pattern.

./src/app/**/*.graphql

Given the example above, Inspector will search every file that matches that pattern and extract operations and fragments.

Supported extensions: .graphql, .graphqls and .gql.

⚠️

Remember to wrap a glob pattern with quotes: "./src/app/**/*.graphql"

Programmatic API

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

const { validate } = require('@graphql-inspector/core')
const { loadDocuments } = require('@graphql-tools/load')
const { GraphQLFileLoader } = require('@graphql-tools/graphql-file-loader')
const graphql = require('graphql')
 
const documents = loadDocuments('./src/**/*.graphql', {
  loaders: [new GraphQLFileLoader()]
})
 
// Convert documents to the format expected by "validate" function
const sources = documents.map(doc => {
  return new graphql.Source(graphql.print(doc.document), doc.location)
})
 
const invalidDocuments = validate(schema, sources)