@inrupt/experimental-graphql-codegen-schema-node
Version:
Generate a Schema Node in Code Generation
55 lines (54 loc) • 2.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.plugin = void 0;
const utils_1 = require("@graphql-tools/utils");
// Adds the compiled schema to the source document
function plugin(schema, documents, config) {
return {
content: "",
prepend: [
`import { DocumentNode as DocumentN, buildASTSchema } from 'graphql'`,
`import { makeExecutableSchema } from '@graphql-tools/schema'`,
],
append: [
`export const _SchemaDocument = \`${(0, utils_1.printSchemaWithDirectives)(schema)}\``,
// `export const _SchemaDocument = ${JSON.stringify(parse(printSchema(schema)))} as unknown as DocumentN`,
`/** The original schema with no directives applied */`,
// `export const baseSchema = buildASTSchema(_SchemaDocument)`,
`export const baseSchema = makeExecutableSchema({ typeDefs: _SchemaDocument })`,
],
};
}
exports.plugin = plugin;
// TODO: FIX THIS
// export function plugin<T = any>(schema: GraphQLSchema, documents: Types.DocumentFile[], config: T): Types.Promisable<Types.PluginOutput> {
// return {
// content: '',
// prepend: [
// `import { DocumentNode as DocumentN, buildASTSchema } from 'graphql'`,
// `import { makeExecutableSchema } from '@graphql-tools/schema'`
// ],
// append: [
// `export const _SchemaDocument = ${JSON.stringify(schema)} as unknown as DocumentN`,
// // `export const _SchemaDocument = ${JSON.stringify(parse(printSchema(schema)))} as unknown as DocumentN`,
// `
// /** The original schema with no directives applied */
// export const baseSchema = buildASTSchema(_SchemaDocument)`
// // `export const baseSchema = makeExecutableSchema({ typeDefs: buildASTSchema(_SchemaDocument) })`
// ]
// }
// }
// export function plugin<T = any>(schema: GraphQLSchema, documents: Types.DocumentFile[], config: T): Types.Promisable<Types.PluginOutput> {
// return {
// content: '',
// prepend: [
// `import { makeExecutableSchema } from '@graphql-tools/schema'`
// ],
// append: [
// `export const _SchemaDocument = ${JSON.stringify(parse(printSchema(schema)))} as unknown as Document`,
// `
// /** The original schema with no directives applied */
// export const baseSchema = buildSchema(print(_SchemaDocument as any))`
// ]
// }
// }