How to use the printSchema function from graphql
Find comprehensive JavaScript graphql.printSchema code examples handpicked from public code repositorys.
graphql.printSchema is a function that prints the GraphQL schema in the SDL (Schema Definition Language) format.
692 693 694 695 696 697 698 699 700 701
this.buildLoaderOptionMap(services); // rebuild the options for DataLoaders this.shouldUpdateGraphqlSchema = false; this.broker.broadcast("graphql.schema.updated", { schema: GraphQL.printSchema(schema), }); } catch (err) { this.logger.error(err); throw err;
+ 9 other calls in file
156 157 158 159 160 161 162 163 164 165
* Save into a file the readable GraphQL schema. * * @return void */ const writeGenerateSchema = schema => { const printSchema = graphql.printSchema(schema); return strapi.fs.writeAppFile('exports/graphql/schema.graphql', printSchema); }; const buildResolvers = resolvers => {
How does graphql.printSchema work?
graphql.printSchema
is a function that takes a GraphQL schema object and returns a string representation of the schema, including its types, fields, and directives, that can be used for debugging, testing, and documentation purposes. The function traverses the schema object and generates the string by calling other functions from the graphql
library, such as printType
, printFields
, and printDirectives
, that handle the formatting of specific parts of the schema. The resulting string follows the GraphQL schema definition language syntax and can be parsed back into a schema object using the graphql.buildSchema
function.
GitHub: inigolabs/inigo-js
235 236 237 238 239 240 241 242 243 244
// use-case: apollo-server with gateway rootInigoInstance.updateSchema(coreSupergraphSdl) } else { // use-case: apollo-server without gateway try { const schema_str = printSchema(apiSchema) rootInigoInstance.updateSchema(schema_str) } catch(e) { console.error("inigo.js: cannot print schema.", e) }
+ 18 other calls in file
39 40 41 42 43 44 45 46 47 48
.send(body) .set('Content-Type', 'application/json') .set('Authorization', `Bearer ${token.access_token}`); if (!response.body.data) return new Error('Не удалось скачать схему!'); const clientSchema = buildClientSchema(response.body.data); const sdl = printSchema(clientSchema); fs.writeFileSync(process.env.GRAPHQL_SCHEMA_PATH, sdl); console.info('Схема обновилась!'); console.info('_____________________________________________________'); } catch (e) {
+ 2 other calls in file
Ai Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14
const { buildSchema } = require("graphql"); const { printSchema } = require("graphql"); // Define your schema const schema = buildSchema(` type Query { hello: String } `); // Print the schema as a string const schemaString = printSchema(schema); console.log(schemaString);
This code defines a simple GraphQL schema with a hello field and then prints the schema as a string using the printSchema function from the graphql library. The output will be a string representation of the schema definition.
0 1 2 3 4 5 6 7 8 9
const graphql = require("graphql"); const fs = require("fs"); const schema = require(process.argv[2]); const clientSchema = graphql.buildClientSchema(schema.data); const schemaString = graphql.printSchema(clientSchema); fs.writeFileSync('schema-'+Date.now()+'.graphql',schemaString);
graphql.GraphQLNonNull is the most popular function in graphql (4226 examples)