javascriptjsongraphqlresolvergraphql-yoga

my json file does not match my graphQL queries


I'm using graphql-yoga and when I run the query users I get the error TypeError: Cannot read properties of undefined (reading 'users'). Even though I surfed the internet and got help from chatgpt, I couldn't solve it.myJsonFile schema.js query.js index.js for resolvers

I'm sure my json file is not corrupt, I can print it when I want to print it to the console. When I did a little research, I thought it was context related, but I didn't know what to do.


Solution

  • I solved the problem myself, problem is in server.js server.js_before When using createYoga, I only defined the schema, I added the context parameter next to the schema as shown in the figure and added my json file into it. and its working now server.js_after