-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Apollo Server 2: Error when setting keys on Context and using DataSources #1247
Comments
It should definitely be possible to use Is there any chance you are using query batching? If have a suspicion it might be related to that. (We 'clone' the context for every request in the batch and that might somehow include the |
Let me put you together a minimal example, because I don't believe I'm doing anything out of the ordinary like query batching. |
Ah, I think I figured it out! You're setting the context directly, instead of defining a |
As a workaround, you could change:
to:
|
Yeah okay, that's probably the issue. None of that was documented so it's hard to tell what's the proper way to use DataSources in your server config. Deleting the context key in my server options is what fixed my issue. Anyways here's the example even though we don't really need it anymore. https://repl.it/@Saeris/Apollo-Server-2-Context-Error-Example |
This should be fixed in the latest release. |
Ran into an issue in configuring my server where I would receive the following error if I set any key at all on the context object while using DataSources:
Please use the dataSources config option instead of putting dataSources on the context yourself.
Here's a snippet of my server config:
I can throw together a repl to reproduce this error if needed, but it should be pretty straight forward. From what I understand, Apollo doesn't want you to set a
dataSources
key on the context object, but instead throws an error if any key is set at all. I was able to work around this by refactoring my code to use an Images datasource instead, but this is clearly broken behavior. There's numerous reasons why you'd want to make data available via the context object, so this would be a breaking change for a lot of users if not addressed.As a side note, even with
debug: true
none of these errors get logged to the node.js console. I spent a long time trying to figure out what the problem was, because all I was getting in my Playground was"error": "Response not successful: Received status code 400"
every time I tried to run a query. Later I discovered that if I went to the network tab and inspected the response object I was getting back from the server, the actual error message would turn up there. It should also be noted that I had my server configured to use Apollo Engine as well, and I didn't see any error messages show up there either, all it was receiving was introspection queries from loading the playground. Not sure what needs to be fixed there, but I can tell you it was a total pain to try and debug.The text was updated successfully, but these errors were encountered: