Anyone care to point me to a resource on the `Erro...
# prisma-whats-new
p
Anyone care to point me to a resource on the
Error: GraphQL error: Cannot return null for non-nullable type
? I am getting this on the mobile client after firing a resolver mutation. The resolver updates two types in my db, and all fields are getting populated when I go in and look at the databrowser
I can't tell from the logs which field is causing the error, here is the model of the type that's causing the error:
Copy code
type Purchase @model{
  amount: Float!
  chargeId: String!
  createdAt: DateTime!
  currency: String!
  description: String!
  id: ID! @isUnique
  isPaid: Boolean! @defaultValue(value: false)
  metadata: Json
  outcome: Json
  quantity: Int!
  source: Json
  tickets: [Ticket!]! @relation(name: "TicketPurchase")
  updatedAt: DateTime!
  user: User @relation(name: "PurchaseOnUser")
}
I update all fields except
tickets
, which gets updated after the purchase is successful & the ticketId is generated. Could it be this? Or maybe the
@defaultValue(value: false)
?
m
Hey, can you also share your client query?
I assume you’re getting the error once you make a mutation for a field in app schema right?
p
I'm getting the error on the server I believe
Here's everything if you don't mind taking a look @matic https://gist.github.com/pcooney10/b9e8d26294f719ca62f82523b4b95c3f
m
Those two lines probably don’t resolve, right?
Can you check that?
p
They do. I am seeing new
Ticket
records in my db with the new `purchaseId`'s
And the error I am getting is on
createPurchase (line 3, column 5)
, the first of the two mutations called
m
Ah, I got an idea, what are those two functions returning?
p
They are both just returning mutation payloads I believe
m
That’s what I thought. Ok, so since your are returning an optional payload, you must return either
{ data: { createPurchase }}
, or
{ error: 'something' }
from your resolvers.
I think that should work.
p
Ok that makes sense. I'll give it a go !
👍 huge lifesaver
m
No problem, also why are you not using
graphcool-lib
?
p
From this:
Copy code
return new Promise((resolve, reject) => {
    createStripeCharge(amount, currency, description, customer, metadata)
      .then(charge => addPurchaseToCustomer(userId, charge, quantity))
      .then(response => response.json())
      .then(resp => createTicketForCustomer(eventId, resp.data.createPurchase.id, ticketOptionId, userId))
      .then(response => response.json())
      .then(resp => { resolve(resp) })
      .catch(err => {
        console.log(err)
        reject(err)
      })
  })
to this: ?
Copy code
return new Promise((resolve, reject) => {
    createStripeCharge(amount, currency, description, customer, metadata)
      .then(charge => addPurchaseToCustomer(userId, charge, quantity))
      .then(response => response.json())
      .then(resp => createTicketForCustomer(eventId, resp.data.createPurchase.id, ticketOptionId, userId))
      .then(response => response.json())
      .then(resp => { resolve({ data: {createPurchase: resp }}) })
      .catch(err => {
        console.log(err)
        reject({ data: {createPurchase: err }})
      })
  })
And this was written a long time ago (September-ish) before graphcool-lib was a thing. Was focused on front-end work for the last few months but will update
Do I use that like this?
const fromEvent = require('graphcool-lib').fromEvent
const graphcool = fromEvent(event)
const api = graphcool.api('simple/v1')
m
Nope, instead of
{ data: { createPurchase: err }}
do
{ error }
p
Ok cool thank you
m
Ping me if you need any more help 😄
p
Will do ! I feel like this is said too often, but I am on an extreme time crunch today so this was extremely helpful
m
😂 no problem