Skip to content
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

Passing context to datasource loses it's reference, meaning, we cannot mutate the context between the resolver and datasources. #7863

Open
christo8989 opened this issue Apr 2, 2024 · 2 comments

Comments

@christo8989
Copy link

christo8989 commented Apr 2, 2024

Issue Description

This worked in apollo server 3.x and I think it should still work in apollo server 4.x.

The context was mutable between the resolvers and data sources. And, if the same object is passed to Apollo Server and the Data Sources, then I would expect the reference to be the same for that request.

Link to Reproduction

https://codesandbox.io/p/devbox/green-dew-s6pz7j?file=%2Fsrc%2Findex.ts%3A31%2C6&workspaceId=9fba286e-b0a2-40d4-9a10-3ed17d6fc084

Reproduction Steps

  1. Start the application.
  2. Query "hello"
  3. Check the terminal logs.

EXPECT: console.log("context in api", this.context) to log a context with the user property filled.

ACTUAL: console.log("context in api", this.context)'s user property is null.

It should get populated from the authenticate directive. You can see that the resolver has it (which makes sense since we literally pass it though).

This worked in apollo server 3.x. And I don't see why it shouldn't work in apollo server 4.x.

@christo8989
Copy link
Author

christo8989 commented Apr 2, 2024

@glasser
Copy link
Member

glasser commented Apr 19, 2024

That is a good point. We could consider just doing the clone in the http batching codepath rather than always. This might qualify as a backwards-incompatible change, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants