GraphQL schema file loading with GraphQL Tools

27 Dec 2021

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!
}