Skip to content

Instantly share code, notes, and snippets.

@mattfysh
Created November 24, 2022 22:16
Show Gist options
  • Save mattfysh/df76d34647ea1b0913b0664abdb8cd6d to your computer and use it in GitHub Desktop.
Save mattfysh/df76d34647ea1b0913b0664abdb8cd6d to your computer and use it in GitHub Desktop.
// const { makeExecutableSchema } = require('@graphql-tools/schema')
const { stitchSchemas } = require('@graphql-tools/stitch')
const { execute, parse, printSchema, print, buildSchema } = require('graphql')
const aSchema = buildSchema(/* GraphQL */ `
type Thing {
id: ID!
foo: String
}
type Query {
thing(id: ID!): Thing
}
`)
const bSchema = buildSchema(/* GraphQL */ `
type Thing {
id: ID!
bar: String
}
type Query {
thing(id: ID!): Thing
}
`)
const schema = stitchSchemas({
subschemas: [
{
schema: aSchema,
executor: () => {
console.log('inside a')
return { data: { thing: { id: 'a', foo: 'faz' } } }
},
},
{
schema: bSchema,
executor: () => {
console.log('inside b')
return { data: { thing: { id: 'b', bar: 'baz' } } }
},
},
],
})
console.log(printSchema(schema))
console.log(
execute({
schema,
document: parse('query { thing(id:"XYZ") { id, foo, bar } }'),
})
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment