Skip to content

load public/private schema by authentication #2117

Answered by n1ru4l
ethdev279 asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @ethdev279!

Loading conditional schemas based on the request is documented here: https://the-guild.dev/graphql/yoga-server/docs/features/schema#conditional-schema

import { createServer } from 'node:http'
import { createYoga } from 'graphql-yoga'
import { getSchemaForViewer } from './schema.js'

const yoga = createYoga({
 schema: async (request) =>
 getSchemaForViewer(request.headers.get('x-schema') ?? 'default')
})
const server = createServer(yoga)

// Start the server and you're done!
server.listen(4000, () => {
 console.info('Server is running on http://localhost:4000/graphql')
})

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by n1ru4l
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