While trying to run the first tracksForHome query, I get the below error:
{
"errors": [
{
"message": "Cannot return null for non-nullable field Query.tracksForHome.",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"tracksForHome"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"stacktrace": [
"Error: Cannot return null for non-nullable field Query.tracksForHome.",
" at completeValue (/home/hemesh/Projects/odyssey-lift-off-part1/server/node_modules/graphql/execution/execute.js:559:13)",
" at resolveField (/home/hemesh/Projects/odyssey-lift-off-part1/server/node_modules/graphql/execution/execute.js:472:19)",
" at executeFields (/home/hemesh/Projects/odyssey-lift-off-part1/server/node_modules/graphql/execution/execute.js:292:18)",
" at executeOperation (/home/hemesh/Projects/odyssey-lift-off-part1/server/node_modules/graphql/execution/execute.js:236:122)",
" at executeImpl (/home/hemesh/Projects/odyssey-lift-off-part1/server/node_modules/graphql/execution/execute.js:116:14)",
" at Object.execute (/home/hemesh/Projects/odyssey-lift-off-part1/server/node_modules/graphql/execution/execute.js:60:35)",
" at execute (/home/hemesh/Projects/odyssey-lift-off-part1/server/node_modules/apollo-server-core/dist/requestPipeline.js:199:36)",
" at Object.processGraphQLRequest (/home/hemesh/Projects/odyssey-lift-off-part1/server/node_modules/apollo-server-core/dist/requestPipeline.js:139:34)",
" at processTicksAndRejections (internal/process/task_queues.js:95:5)",
" at async processHTTPRequest (/home/hemesh/Projects/odyssey-lift-off-part1/server/node_modules/apollo-server-core/dist/runHttpQuery.js:179:30)"
]
}
}
}
],
"data": null
}
I suspect this is because we are returning a null array using the […new Array(6)] to the tracksForHome query which expects a non nullable list of non nullable Tracks object - [Tracks!]!
I’m surprised it even worked in the video. Now I cannot proceed in the course… please help.
Thanks for the info! The […new Array(6)] will indeed return an array of undefined objects, by itself. However in this same mocks object, we also included a property for Track that has more mock data. This data will override the undefined objects in the array.
That said, can you paste the contents of your index.js file as well as your schema? Or link to your Github repo if you have it. I’ll see if I can spot what’s happening!
Below are the contents of my schema.js and index.js files:
schema.js:
const {gql} = require('apollo-server');
const typeDefs = gql`
type Query {
"Get tracks array for homepage grid"
tracksForHome: [Track!]!
}
"A track is a group of Modules that teaches about a specific topic"
type Track {
id: ID!
title: String!
author: Author!
thumbnail: String
length: Int
modulesCount: Int
}
"Author of a complete Track or a Module"
type Author {
id: ID!
name: String!
photo: String
}
`;
module.exports = typeDefs;
Typos are sneaky. Happy to hear it’s working now!
Lift-off III goes into a little more detail about the resolver chain we’re using here (ie why did the Track data “override” the tracksForHome data?) but feel free to let us know again if you have any other questions!
Actually the same happens if you use the code from tutorial several steps later. The complete resolver.js file in it is missing the last line - module export. Causes the same error.
Hi there @mikocot ! I’m sorry to hear that you’re running into an error. Could you let me know which module of the course you see the problem coming from? I’m happy to take a look!