Created
November 24, 2022 22:16
-
-
Save mattfysh/df76d34647ea1b0913b0664abdb8cd6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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