unplugin-graphql-parse
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

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

Package Sidebar

Install

npm i unplugin-graphql-parse

Weekly Downloads

38

Version

0.1.1

License

MIT

Unpacked Size

19.3 kB

Total Files

37

Last publish

Collaborators

  • gympass_josie_bot