@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.
28 lines (25 loc) • 832 B
JavaScript
import { writeFileSync } from 'fs';
import { convert } from '../schema/convert.js';
import { parseGraphqlSchema } from '../schema/parse.js';
async function parseSchema(options) {
const schema = await parseGraphqlSchema({
globPaths: options.paths,
});
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 parseGraphQLSchema(options) {
return {
name: 'parse-graphql-schema',
buildStart: async () => {
await parseSchema(options);
},
};
}
export { parseGraphQLSchema as default, parseSchema };
//# sourceMappingURL=parse.js.map