UNPKG

@magidoc/rollup-plugin-gql-schema

Version:

A Rollup and ViteJS plugin that allows to parse a GraphQL Schema from a target URL and save it to a target output folder, or to parse it from the disk and convert it to a desired format.

30 lines (27 loc) 903 B
import { writeFileSync } from 'fs'; import { convert } from '../schema/convert.js'; import queryGraphQLSchema from '../schema/query.js'; async function fetchSchema(options) { const schema = await queryGraphQLSchema(options.url, { query: options.query, method: options.method, headers: options.headers, }); const format = options.format ?? 'introspection'; const extension = format === 'sdl' ? 'graphqls' : 'json'; const output = options.target || `src/_schema.${extension}`; writeFileSync(output, convert(schema, format), { encoding: 'utf-8', flag: 'w', }); } function fetchGraphQLSchema(options) { return { name: 'fetch-graphql-schema', buildStart: async () => { await fetchSchema(options); }, }; } export { fetchGraphQLSchema as default, fetchSchema }; //# sourceMappingURL=fetch.js.map