What is @graphql-tools/json-file-loader?
The @graphql-tools/json-file-loader package is a utility that allows you to load and parse .json files directly into your GraphQL schema definitions. This is particularly useful for integrating static JSON data into your GraphQL server, enabling seamless schema stitching and data merging from various sources.
Load JSON files into GraphQL schema
This feature allows you to load JSON files as part of your GraphQL schema. The code sample demonstrates how to use the JsonFileLoader with the loadSchema function from @graphql-tools/load to asynchronously load a JSON file into a GraphQL schema.
const { loadSchema } = require('@graphql-tools/load');
const { JsonFileLoader } = require('@graphql-tools/json-file-loader');
async function loadSchemaFromJson() {
const schema = await loadSchema('path/to/file.json', {
loaders: [new JsonFileLoader()]
});
return schema;
}