Skip to content

Is there any way to reuse schema.graphql files between subgraphs? #2020

Answered by PaulRBerg
PaulRBerg asked this question in Q&A
Discussion options

You must be logged in to vote

I think I found the solution - Schema Merging using @graphql/tools packages.

const path = require('path')
const { loadFilesSync } = require('@graphql-tools/load-files')
const { mergeTypeDefs } = require('@graphql-tools/merge')
 
const typesArray = loadFilesSync(path.join(__dirname, './types'), { extensions: ['graphql'] })
const mergedSchema = mergeTypeDefs(typesArray);
 const printedSchema = print(mergedSchema);
// write printedSchema to a `schema.graphql` file

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@PaulRBerg
Comment options

@PaulRBerg
Comment options

Answer selected by PaulRBerg
@PaulRBerg
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants