/graphql-mask

GraphQL Mask lets you subtract everything outside a schema from a query

Primary LanguageJavaScript

graphql-mask

Greenkeeper badge

CircleCI npm package npm downloads

Graphql Mask is a simple utility for removing everything in a query that is not defined in a schema. Use it the same way you would use the library function for graphql-js e.g. graphqlMask(schema, query) but instead of getting back results, you will get back a trimmed down query.

Usage

$ npm install graphql-mask
# or 
$ yarn add graphql-mask
const graphqlMask = require("graphql-mask");
// const graphqlMask = require("graphql-mask/es5"); if you need to use this in a browser

const result = graphqlMask(`
  type Query {
    something: String!
    somethingElse: Int
  }
`,`
  query ExampleQuery {
    something
    somethingElse
    somethingNotInSchema
  }
`)

console.log(result)

This will print...

query ExampleQuery {
  something
  somethingElse
}