Skip to content

Latest commit

 

History

History
101 lines (74 loc) · 1.56 KB

File metadata and controls

101 lines (74 loc) · 1.56 KB

unplugin-graphql-parse

Parse GraphQL SDL files to DocumentNode AST objects. This is useful for passing it to Graphql Servers, for example.

import sdl from 'Schema.graphql';

console.log(sdl);
/**
 *  Object
 *   definitions: [{…}]
 *   kind: "Document"
 *   loc: {start: 0, end: 25}
*/

Options

  • ext (default: .graphql): Which file extension should the plugin match.

Usage

Vite
// vite.config.ts
import graphqlParse from 'unplugin-graphql-parse/vite'

export default defineConfig({
  plugins: [
    graphqlParse({ /* options */ }),
  ],
})
Rollup
// rollup.config.js
import graphqlParse from 'unplugin-graphql-parse/rollup'

export default {
  plugins: [
    graphqlParse({ /* options */ }),
    // other plugins
  ],
}


Webpack
// webpack.config.js
module.exports = {
  /* ... */
  plugins: [
    require('unplugin-graphql-parse/webpack')({ /* options */ }),
  ],
}


esbuild
// esbuild.config.js
import graphqlParse from 'unplugin-graphql-parse/esbuild'

build({
  /* ... */
  plugins: [
    graphqlParse({ /* options */ }),
  ],
})


Types

If you want to solve the ts(2307) issue and also get type safety/autocompletion, you can add this to one of your .d.ts type definitions:

declare module '*.graphql' {
  import type { DocumentNode } from 'graphql';

  const module: DocumentNode;
  export = module;
}