0.1.1 • Published 1 year ago

unplugin-graphql-parse v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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.config.ts
import graphqlParse from 'unplugin-graphql-parse/vite'

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

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

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

// 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;
}