useSchemaByContext
Package name | Weekly Downloads | Version | License | Updated |
---|---|---|---|---|
@envelop/core (opens in a new tab) | Feb 20th, 2023 |
useLazyLoadedSchema
This plugin is the simplest plugin for specifying your GraphQL schema. You can specify a schema created from any tool that emits GraphQLSchema
object, and you can choose to load the schema based on the initial context (or the incoming request).
import { envelop, useSchemaByContext, useEngine } from '@envelop/core'
import { parse, validate, specifiedRules, execute, subscribe } from 'graphql'
async function getSchema({ req }): GraphQLSchema {
if (req.isAdmin) {
return adminSchema
}
return userSchema
}
const getEnveloped = envelop({
plugins: [
useEngine({ parse, validate, specifiedRules, execute, subscribe }),
useSchemaByContext(getSchema)
// ... other plugins ...
]
})