Skip to content

bug: Custom context not available in function to provide schema  #2999

Closed
@wwarby

Description

@wwarby

Describe the bug

The workflow I want to use is:

  1. create an app context in which I parse a client ID from a JWT header
  2. use the client ID from my app context to dynamically compose the schema (or get a previously composed schema from cache) because each client needs a different schema.

According to the TypeScript typings for graphql-yoga, this should work. The argument passed in to the function I set as the schema property should receive my custom app context as it's parameter. But it doesn't.

Your Example Website or App

https://codesandbox.io/p/sandbox/tender-elgamal-jgmnm9?file=/src/main.ts:17,59

Steps to Reproduce the Bug or Issue

Run the code sandbox example. Line 17 logs undefined to the console.

Expected behavior

I expect ctx to contain the property someNumber, and the intellisense in the IDE shows me that I am right to expect that, but it isn't there.

Screenshots or Videos

image

Platform

  • OS: [e.g. macOS, Windows, Linux]
  • NodeJS: [e.g. 18.1.0]
  • @graphql-yoga/* version(s): [e.g. 2.5.1]

Additional context

I can see that my context creation function is not called before the call to the schema creation function is made. This means I have no access to the context at schema creation time, which is inconvenient for my purposes. I'm not sure whether this behaviour is intentional, but if so the TypeScript type hints are definitely wrong. The documentation also seems to be wrong, suggesting that the argument passed into the schema creation function is a request object, when as far as I can see it is actually of type {req, res, request}.

Metadata

Metadata

Assignees

Labels

stage/2-failing-testA failing test was created that describes the issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions