Error when running a mutation: Expected non-null value, found null


#1

I’m receiving the following error when running a mutation:

Error: Variable ‘$data’ expected value of type ‘MSvalueCreateInput!’ but got: {“data”:{“rowNo”:200,“stock”:{“connect”:{“id”:“cjt24hsxm02fm0665upqjicld”}},“msField”:{“connect”:{“id”:“cjt0xb53m00ha06659a91d6ad”}},“financialYear”:{“connect”:{“id”:“cjt0uqer201h60665jzxpdfdt”}},“value”:1.12}}. Reason: ‘rowNo’ Expected non-null value, found null. (line 1, column 11):
mutation ($data: MSvalueCreateInput!)

datamodel.prisma:

type MSvalue {
  id: ID! @unique
  rowNo: Int!
  stock: Stock! @relation(name: "MSvalueStock", onDelete: CASCADE)
  msField: MSfield! @relation(name: "MSfieldValues", onDelete: CASCADE)
  financialYear: FinancialYear! @relation(name: "MSvalueYears")
  value: Float
}

Resolver functions:

function createMSvalue(parent, args, context, info) {
  return context.prisma.createMSvalue(args, info)
}
 > function stock(parent, args, context) {
 >   console.log(parent.id)
 >   return context.prisma.mSvalue({ id: parent.id }).stock()
 > }
 > 
 > function msField(parent, args, context) {
 >   console.log(parent.id)
 >   return context.prisma.mSvalue({ id: parent.id }).msField()
 > }
 > 
 > function financialYear(parent, args, context) {
 >   console.log(parent.id)
 >   return context.prisma.mSvalue({ id: parent.id }).financialYear()
 > }

The mutation:

mutation {
  createMSvalue (
    data: {
      rowNo:200,
      stock: {
        connect:{          
          id:"cjt24hsxm02fm0665upqjicld"
        }
      },
      msField:{        
        connect:{          
          id:"cjt0xb53m00ha06659a91d6ad"
        }
      },
      financialYear:{
        connect:{          
          id:"cjt0uqer201h60665jzxpdfdt"
        }
      },
      value:1.12
    }
  )
   {
    id
  }
}

Any help will be appreciated, thanks


#2

I’ve updated the datamodel.prisma definition as follows to make the fields non-mandatory:

type MSvalue {
  id: ID! @unique
  rowNo: Int
  stock: Stock @relation(name: "MSvalueStock", onDelete: CASCADE)
  msField: MSfield @relation(name: "MSfieldValues", onDelete: CASCADE)
  financialYear: FinancialYear @relation(name: "MSvalueYears")
  value: Float
}

and the error has now changed to:

`

{ Error: Variable ‘$data’ expected value of type ‘MSvalueCreateInput!’ but got: {“data”:{“rowNo”:1,“stock”:{“connect”:{“ticker”:“ZYB”}},“msField”:{“connect”:{“id”:“cjt0xb53m00ha06659a91d6ad”}},“financialYear”:{“connect”:{“year”:2011}},“value”:50141}}. Reason: ‘data’ Field ‘data’ is not defined in the input type ‘MSvalueCreateInput’. (line 1, column 11):

`


#3

Resolved it by changing my resolver from:

function createMSvalue(parent, args, context, info) {
  console.log(args.data)
  return context.prisma.createMSvalue(args, info)
}

to:

function createMSvalue(parent, args, context, info) {
  console.log(args.data)
  return context.prisma.createMSvalue(args.data, info)
}