UNPKG

type-graphql

Version:

Create GraphQL schema and resolvers with TypeScript, using classes and decorators!

31 lines (29 loc) • 1.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.emitSchemaDefinitionFile = exports.emitSchemaDefinitionFileSync = exports.defaultPrintSchemaOptions = void 0; const graphql_1 = require("graphql"); const filesystem_1 = require("../helpers/filesystem"); exports.defaultPrintSchemaOptions = { commentDescriptions: false, sortedSchema: true, }; const generatedSchemaWarning = /* graphql */ `\ # ----------------------------------------------- # !!! THIS FILE WAS GENERATED BY TYPE-GRAPHQL !!! # !!! DO NOT MODIFY THIS FILE BY YOURSELF !!! # ----------------------------------------------- `; function emitSchemaDefinitionFileSync(schemaFilePath, schema, options = exports.defaultPrintSchemaOptions) { const schemaFileContent = getSchemaFileContent(schema, options); filesystem_1.outputFileSync(schemaFilePath, schemaFileContent); } exports.emitSchemaDefinitionFileSync = emitSchemaDefinitionFileSync; async function emitSchemaDefinitionFile(schemaFilePath, schema, options = exports.defaultPrintSchemaOptions) { const schemaFileContent = getSchemaFileContent(schema, options); await filesystem_1.outputFile(schemaFilePath, schemaFileContent); } exports.emitSchemaDefinitionFile = emitSchemaDefinitionFile; function getSchemaFileContent(schema, options) { const schemaToEmit = options.sortedSchema ? graphql_1.lexicographicSortSchema(schema) : schema; return generatedSchemaWarning + graphql_1.printSchema(schemaToEmit, options); }