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

Apollo Federation gateway breaks upon receiving a query with empty variables section #300

Closed
rahul22048 opened this issue Dec 9, 2020 · 5 comments · Fixed by #2443
Closed

Comments

@rahul22048
Copy link

Apollo federation gateway breaks throwing Cannot convert undefined or null to object upon receiving a graphql query which does not have any variables section. (From our perspective this is a very common use case).

Passing variables as empty object {}, works fine, but it should not be mandated on the caller to explicitly pass empty object.

@trevor-scheer
Copy link
Member

trevor-scheer commented Dec 9, 2020

Hi @rahul22048, can you please provide a runnable reproduction and version info for this issue? I've tried in multiple ways to not provide a variables key and can't reproduce.

I'm mostly interested in how you're going about calling the gateway and at which location in the API your initiating execution.

Currently, with a gateway running inside of Apollo Server (as is our typical configuration), I can send a query from curl or programmatically like so:

await server.executeOperation({
  query: `query { products { id } }`,
});

...with no variables key and I have no problem doing so.

@rahul22048
Copy link
Author

@trevor-scheer :- I am not sure which client side library you are using. Just to make sure, can u confirm that the actual network request which is going, in that variables section is empty. We are using 0.20.0 version of @apollo/gateway library.

@trevor-scheer
Copy link
Member

@rahul22048 no client library, my request was handwritten and sent via curl from the command line. Here is the exact command I used to send the request to my running demo gateway (running latest version "@apollo/gateway": "^0.21.4")

curl -X POST localhost:4000 -H "content-type: application/json" --data "{ \"query\": \"{ products { id } }\" }"

Please send a reproduction if you'd like for me to look into this further.

@rahul22048
Copy link
Author

@trevor-scheer :- Upon digging into this issue , the issue was with the way query was written. In case queries have input variables, and you specify the default value inline , without explicitly passing variables , then it fails.

For ex:-

query getPosts($size:Int = 50) {
getPosts(posts:$size) {
comment
}
}

In the above example i have not passed explicit variables section, instead specified values in line, the query fails. if i would have written the same query in following way:-

query getPosts($size:Int) {
getPosts(posts:$size) {
comment
}
}
And passed in the explicit variables section, specifying the value of size variable, then the same works.

The issue is the first query was working without federation gateway in between. To me to make the behaviour compatible with apollo server, i think federation gateway should also accept first type of queries.

@smyrick
Copy link
Member

smyrick commented Mar 7, 2023

I can reproduce this issue with this codesandbox

https://codesandbox.io/p/sandbox/interesting-keldysh-sx5s2y?selection=%5B%7B%22endColumn%22%3A24%2C%22endLineNumber%22%3A17%2C%22startColumn%22%3A24%2C%22startLineNumber%22%3A17%7D%5D&file=%2Fsrc%2Findex.ts

Run the following query. With variables, it runs. With no variables it errors out

query ExampleIncludeDefault($toInclude: Boolean = true) {
  topProducts {
    name
    price @include(if: $toInclude)
  }
}

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

Successfully merging a pull request may close this issue.

3 participants