Lift-Off II: QUERYING LIVE DATA - Error while running the query in Apollo Sandbox

After running the sample query, I’m receiving the following error:

{
  "data": {},
  "errors": [
    {
      "message": "Cannot return null for non-nullable field Query.tracksForHome.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "tracksForHome"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "stacktrace": [
          "Error: Cannot return null for non-nullable field Query.tracksForHome.",
          "    at completeValue (C:\\Users\\SreelakshmiSuresh\\Desktop\\Training\\Backend Training\\GraphQL\\odyssey-lift-off-part2\\server\\node_modules\\graphql\\execution\\execute.js:594:13)",
          "    at executeField (C:\\Users\\SreelakshmiSuresh\\Desktop\\Training\\Backend Training\\GraphQL\\odyssey-lift-off-part2\\server\\node_modules\\graphql\\execution\\execute.js:489:19)",
          "    at executeFields (C:\\Users\\SreelakshmiSuresh\\Desktop\\Training\\Backend Training\\GraphQL\\odyssey-lift-off-part2\\server\\node_modules\\graphql\\execution\\execute.js:413:20)",
          "    at executeOperation (C:\\Users\\SreelakshmiSuresh\\Desktop\\Training\\Backend Training\\GraphQL\\odyssey-lift-off-part2\\server\\node_modules\\graphql\\execution\\execute.js:344:14)",
          "    at execute (C:\\Users\\SreelakshmiSuresh\\Desktop\\Training\\Backend Training\\GraphQL\\odyssey-lift-off-part2\\server\\node_modules\\graphql\\execution\\execute.js:136:20)",
          "    at executeIncrementally (C:\\Users\\SreelakshmiSuresh\\Desktop\\Training\\Backend Training\\GraphQL\\odyssey-lift-off-part2\\server\\node_modules\\@apollo\\server\\dist\\cjs\\incrementalDeliveryPolyfill.js:47:34)",
          "    at processTicksAndRejections (node:internal/process/task_queues:96:5)",
          "    at async execute (C:\\Users\\SreelakshmiSuresh\\Desktop\\Training\\Backend Training\\GraphQL\\odyssey-lift-off-part2\\server\\node_modules\\@apollo\\server\\dist\\cjs\\requestPipeline.js:223:37)",
          "    at async processGraphQLRequest (C:\\Users\\SreelakshmiSuresh\\Desktop\\Training\\Backend Training\\GraphQL\\odyssey-lift-off-part2\\server\\node_modules\\@apollo\\server\\dist\\cjs\\requestPipeline.js:158:32)",
          "    at async internalExecuteOperation (C:\\Users\\SreelakshmiSuresh\\Desktop\\Training\\Backend Training\\GraphQL\\odyssey-lift-off-part2\\server\\node_modules\\@apollo\\server\\dist\\cjs\\ApolloServer.js:615:16)"
        ]
      }
    }
  ]
}Preformatted text

I checked all the files for typos but couldn’t find any. Any help would be appreciated. Thanks !

1 Like

Hey there @Sreelakshmi_Suresh ! This error usually points to something wrong with the resolver function for Query.tracksForHome. Here are some things you can check:

  • Are you importing the resolvers.js file correctly?
  • Is the resolver function defined correctly?
  • Is the resolver function calling the datasource correctly?

If you could provide a link to your GitHub repo, I can also take a second look for you!

Let me know.

1 Like

Thank you so much for your reply.
I went through the code once again but maybe it’s a small error and that’s why I’m not able to point what went wrong.
Here is the link to my GitHub repo: GitHub - sreelakshmi-suresh/odyssey-lift-off-part2

Thank you so much!

Your repo seems to be missing the file contents of the server folder! So I’m not able to check your code.

I did run what was in final/server and that ran successfully with the query returning data back. That could also be another reference point to check against your own code.

Let me know when you push your server files though, I’m still happy to take a look.

1 Like

I’m so sorry, I turned the server folder into a submodule by mistake. I have uploaded the folder again. Please do check.
Thank you so much for looking into it.

Hey @Sreelakshmi_Suresh sorry for the delay! I took a look at your code and identified the problem in resolvers.js. In the very last line, it should be:

module.exports = resolvers;

Note the s in exports. Your file current has export. This means that the resolvers weren’t being exported correctly, so the resolvers weren’t connected to ApolloServer, resulting in the error.

Hope that helps!

1 Like

Holy smoke!
Thank you so much, I was trying to find if there was anything wrong with the logic.
Appreciate your help!!

1 Like