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

Internal Server Error when nullable input not provided to federated graph. #196

Closed
Collin3 opened this issue May 8, 2020 · 0 comments · Fixed by #167
Closed

Internal Server Error when nullable input not provided to federated graph. #196

Collin3 opened this issue May 8, 2020 · 0 comments · Fixed by #167
Labels
javascript Pull requests that update Javascript code

Comments

@Collin3
Copy link

Collin3 commented May 8, 2020

I was converting a graph that we used to hit directly over to be a federated service and some of our acceptance tests bombed out with the following error

{
  "errors": [
    {
      "message":"Cannot convert undefined or null to object",
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "TypeError: Cannot convert undefined or null to object",
            "    at hasOwnProperty (<anonymous>)",
            "    at hasOwnProperty (/app/node_modules/graphql/execution/values.js:219:42)",
            "    at _loop (/app/node_modules/graphql/execution/values.js:86:10)",
            "    at coerceVariableValues (/app/node_modules/graphql/execution/values.js:119:16)",
            "    at Object.getVariableValues (/app/node_modules/graphql/execution/values.js:48:19)",
            "    at ApolloGateway.validateIncomingRequest (/app/node_modules/@apollo/gateway/dist/index.js:365:37)",
            "    at ApolloGateway.<anonymous> (/app/node_modules/@apollo/gateway/dist/index.js:75:43)",
            "    at Generator.next (<anonymous>)",
            "    at /app/node_modules/@apollo/gateway/dist/index.js:8:71",
            "    at new Promise (<anonymous>)"
          ],
        },
      },
      "code": "INTERNAL_SERVER_ERROR",
      "exception": {
        "stacktrace": [
          "TypeError: Cannot convert undefined or null to object",
          "    at hasOwnProperty (<anonymous>)",
          "    at hasOwnProperty (/app/node_modules/graphql/execution/values.js:219:42)",
          "    at _loop (/app/node_modules/graphql/execution/values.js:86:10)",
          "    at coerceVariableValues (/app/node_modules/graphql/execution/values.js:119:16)",
          "    at Object.getVariableValues (/app/node_modules/graphql/execution/values.js:48:19)",
          "    at ApolloGateway.validateIncomingRequest (/app/node_modules/@apollo/gateway/dist/index.js:365:37)",
          "    at ApolloGateway.<anonymous> (/app/node_modules/@apollo/gateway/dist/index.js:75:43)",
          "    at Generator.next (<anonymous>)","    at /app/node_modules/@apollo/gateway/dist/index.js:8:71",
          "    at new Promise (<anonymous>)"
        ],
      },
    }
  ]
}

After some debugging I found that it was because our acceptance test was reusing a query (similar to below)

query GetProducts($storeId: String) {
  products(storeId: $storeId) {
    productId
    name
 }
}

And in one test it would pass in a storeId and in another test it would not pass in any input variables. When not providing an input variable, the query would error out, but if we provided a variable of type String, null, or undefined, the query would work. It seemed odd that this would error out when going through the federated gateway, but would work when hitting our federated service directly. Is this expected to error out? It seemed like a rather confusing error message if it is expected to not work.

Our federated gateway is running @apollo/federation@0.14.1, @apollo/gateway@0.14.1andapollo-server@2.12.0Our federated service is currently runningapollo-server-hapi@2.8.1`

@abernix abernix transferred this issue from apollographql/apollo-server Sep 30, 2020
@abernix abernix added the javascript Pull requests that update Javascript code label Sep 30, 2020
abernix added a commit that referenced this issue Sep 30, 2020
…ed (#167)

This resolves a "Cannot convert undefined or null to object" error when
the variables provided are undefined but there are nullable variables used
in the Document.

Fixes: #196
Co-authored-by: Jesse Rosenberger <git@jro.cc>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
javascript Pull requests that update Javascript code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants