-
Notifications
You must be signed in to change notification settings - Fork 558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
request
on YogaInitialContext
is conflicting with the request
on the Koa server context
#3145
Comments
request
on 'YogaInitialContext' is conflicting with the request
on the Koa server contextrequest
on YogaInitialContext
is conflicting with the request
on the Koa server context
Hi, thank you for raising this issue. I would recommend to either remove the context (let Yoga create a new empty one) if you don't need to access Koa's context in the GraphQL context. const response = await yoga.handleNodeRequest(ctx.req) If you actually need to access the Koa context via the context (from a resolver or from a plugin hook), I would create a new context and put the Koa context under a dedicated key: const response = await yoga.handleNodeRequest(ctx.req, { koa: ctx }) This way, you can always access Koa context in resolvers. For example: const resolvers = {
Query: {
hello: (_, __, context) => {
const user = await getUserFromHeaders(context.koa.headers)
return `Hello ${user.name}`
}
} |
Hi Valentin, thanks very much for the quick reply and solution. Actually your suggestion with I think in general it makes sense to show in the documentation how to forward the Maybe updating the example code in the framework would help others not to run in the same issue |
Describe the bug
We integrated GraphQL Yoga with the Koa server as documented here https://the-guild.dev/graphql/yoga-server/docs/integrations/integration-with-koa
and pass the Koa context like this
The Koa context contains the Koa request as a
request
property on the context. However the Yoga server assumes that therequest
property on the context it is actually the internal platform-independent Fetch Request.This causes problems e.g. in the use-schema plugin (https://github.com/dotansimha/graphql-yoga/blob/main/packages/graphql-yoga/src/plugins/use-schema.ts)
During
onRequestParseDone
the schema is placed in the WeekMap based on the Yoga request, however withinonEnveloped
the WeakMap is accessed based on the Koa request from the Context. Since this is different the schema cannot be found and the plugin fails.A potential workaround of removing
request
from the Koa context before passing it to Yoga doesn't work, because the request is internally referenced from the context and it becomes dysfunctional.BTW the same issue exists within the
useDisableIntrospection
plugin.Your Example Website or App
sorry no example, but the problem should be clear from the description
Steps to Reproduce the Bug or Issue
I hope the above description is enough to understand the issue
Expected behavior
request
property on the context is the Yogarequest
Screenshots or Videos
No response
Platform
@graphql-yoga/*
version): 5.0.2Additional context
No response
The text was updated successfully, but these errors were encountered: