GraphQL schema file loading with GraphQL Tools

Load GraphQL schema from a single file, or multiple using the GraphQL File Loader.

Jamie Barton

Published on 27 Dec 2021 by Jamie Barton

Notes

const { printSchema } = require("graphql");
const { loadSchemaSync } = require("@graphql-tools/load");
const { GraphQLFileLoader } = require("@graphql-tools/graphql-file-loader");
const typeDefs = loadSchemaSync("schema.graphql", {
loaders: [new GraphQLFileLoader()],
});
console.log(printSchema(typeDefs));
const { printSchema } = require("graphql");
const { loadSchemaSync } = require("@graphql-tools/load");
const { GraphQLFileLoader } = require("@graphql-tools/graphql-file-loader");
const typeDefs = loadSchemaSync("./**/*.graphql", {
loaders: [new GraphQLFileLoader()],
});
console.log(printSchema(typeDefs));
# import Review from "reviews.graphql"
type Query {
product(id: ID!): Product!
products: [Product!]!
}
type Product {
id: ID!
name: String!
description: String!
price: Int!
reviews: [Review!]!
}
type Review {
name: String!
message: String!
}