Someone can help me with this error? `Error: Canno...
# orm-help
a
Someone can help me with this error?
Error: Cannot return null for non-nullable field Home.name.
I am doing
Copy code
async function home(parent, args, context) {
  const home = await context.prisma.home({
    id: args.id
  })

  return home
}
and defined Home in:
Copy code
type Home {
  id: ID!
  createdAt: DateTime!
  description: String!
  url: String!
  name: String!
  location: String!
  postedBy: User
}
schema.graphql
if I do console.log(home) in the return of the resolver, it has the right data
Copy code
{
  name: 'XXX',
  location: 'XXX',
  url: '200',
  description: 'XXX',
  id: 'ckavmr5cs9jps0963eex7xl2d',
  createdAt: '2020-05-31T22:22:54.940Z'
}
Error: Cannot return null for non-nullable field Home.name.
    at completeValue (/Users/sancheza/Library/Mobile Documents/com~apple~CloudDocs/Projects/homeinroom/server/node_modules/graphql/execution/execute.js:560:13)
    at completeValueCatchingError (/Users/sancheza/Library/Mobile Documents/com~apple~CloudDocs/Projects/homeinroom/server/node_modules/graphql/execution/execute.js:495:19)
    at resolveField (/Users/sancheza/Library/Mobile Documents/com~apple~CloudDocs/Projects/homeinroom/server/node_modules/graphql/execution/execute.js:435:10)
    at executeFields (/Users/sancheza/Library/Mobile Documents/com~apple~CloudDocs/Projects/homeinroom/server/node_modules/graphql/execution/execute.js:275:18)
    at collectAndExecuteSubfields (/Users/sancheza/Library/Mobile Documents/com~apple~CloudDocs/Projects/homeinroom/server/node_modules/graphql/execution/execute.js:713:10)
    at completeObjectValue (/Users/sancheza/Library/Mobile Documents/com~apple~CloudDocs/Projects/homeinroom/server/node_modules/graphql/execution/execute.js:703:10)
    at completeValue (/Users/sancheza/Library/Mobile Documents/com~apple~CloudDocs/Projects/homeinroom/server/node_modules/graphql/execution/execute.js:591:12)
    at completeValue (/Users/sancheza/Library/Mobile Documents/com~apple~CloudDocs/Projects/homeinroom/server/node_modules/graphql/execution/execute.js:557:21)
    at /Users/sancheza/Library/Mobile Documents/com~apple~CloudDocs/Projects/homeinroom/server/node_modules/graphql/execution/execute.js:492:16
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
e
name: String!
a
What is wrong with String! ?
e
the
!
means required, so you cannot return a
null
for
name
when you return that object type
a
Ah ok, good to know
e
it must be an actual string value, even
''
would work
if you want it to be nullable, remove the
!
a
do I need to generate and deploy each time?
for example
Copy code
yarn prisma generate && yarn prisma deploy --force
e
when you make schema changes, yeah
a
How I can access to the data object? I tried data.home, data.name, ….
e
can you show me your console log?
a
I believe it is because I missed
Copy code
if (loading) return <div>Fetching</div>;
            if (error) return <div>Error</div>;
because now I can see the object and I can access after I make this change
e
yeah, the data is not there before it is marked as loaded. so you cant access it before that
async programming…
a
it is weird, I can see in the console.log(data) but it has a different format, not an Object
e
is it not undefined before it’s done loading?
a
it prints 2 times (1 undefined and one in a weird format)
now it works when I add the loading
although my jquery gallery stopped working
e
Trying to figure out how to explain this. when using the apollo-client, you make a graphql query and it will return an object that has things like
loading
,
refresh
,
subscribeToMore
, etc
eventually you’ll have some sort of property in there that has the response from your graphql server (if the request succeeds)
generally that will be an object that then has your query’s name as the first property and then the data
thats because in graphql you can make multiple queries at one time and it will return them all in the same object.
a
makes sense, thanks for the help Ethan! Excellent explanation
Learning react, apollo, prisma and graphql has some challenges 🙂
e
yeah, it takes time. Pretty complex and has a rather steep learning curve for most