Skip to content

GraphQLResponseError: Cannot return null for non-nullable field #6300

@amrogad

Description

@amrogad

Description

When we added a new field to 2 of our models, we started getting this error for other fields, even though we didn't touch them, for example, we added price_adjustments to Building and User models, then we started getting this error for AWSDateTime for the Client model, the client model wasn't touched, same goes for id or GenericStatus, we only added the price_adjustments field and it was nullable, so not sure what broke everything, here are some examples, there was 17 error messages in total for all the fields in Client, User and Building models

[GETX] [DBG] [flutter_amplifysdk/models/generic.dart:199] <String> In Update.updateData => errors: [GraphQLResponseError{
  "message": "Cannot return null for non-nullable type: 'ID' within parent 'Building' (/updateCart/building/id)",
  "path": [
    "updateCart",
    "building",
    "id"
  ]
}, GraphQLResponseError{
  "message": "Cannot return null for non-nullable type: 'String' within parent 'Building' (/updateCart/building/name)",
  "path": [
    "updateCart",
    "building",
    "name"
  ]
}, GraphQLResponseError{
  "message": "Cannot return null for non-nullable type: 'GenericStatus' within parent 'Building' (/updateCart/building/status)",
  "path": [
    "updateCart",
    "building",
    "status"
  ]
}, GraphQLResponseError{
  "message": "Cannot return null for non-nullable type: 'AWSDateTime' within parent 'Building' (/updateCart/building/createdAt)",
  "path": [
    "updateCart",
    "building",
    "createdAt"
  ]
}, GraphQLResponseError{
  "message": "Cannot return null for non-nullable type: 'AWSDateTime' within parent 'Building' (/updateCart/building/updatedAt)",
  "path": [
    "updateCart",
    "building",
    "updatedAt"
  ]
}, GraphQLResponseError{
  "message": "Cannot return null for non-nullable type: 'ID' within parent 'User' (/updateCart/user/id)",
  "path": [
    "updateCart",
    "user",
    "id"
  ]
}, GraphQLResponseError{
  "message": "Cannot return null for non-nullable type: 'String' within parent 'User' (/updateCart/user/email)",
  "path": [
    "updateCart",
    "user",
    "email"
  ]
}, GraphQLResponseError{
  "message": "Cannot return null for non-nullable type: 'GenericStatus' within parent 'User' (/updateCart/user/status)",
  "path": [
    "updateCart",
    "user",
    "status"
  ]
}, GraphQLResponseError{
  "message": "Cannot return null for non-nullable type: 'AWSDateTime' within parent 'User' (/updateCart/user/createdAt)",
  "path": [
    "updateCart",
    "user",
    "createdAt"
  ]
}, GraphQLResponseError{
  "message": "Cannot return null for non-nullable type: 'AWSDateTime' within parent 'User' (/updateCart/user/updatedAt)",
  "path": [
    "updateCart",
    "user",
    "updatedAt"
  ]
}, GraphQLResponseError{
  "message": "Cannot return null for non-nullable type: 'ID' within parent 'Client' (/updateCart/client/id)",
  "path": [
    "updateCart",
    "client",
    "id"
  ]
}, GraphQLResponseError{
  "message": "Cannot return null for non-nullable type: 'String' within parent 'Client' (/updateCart/client/firstname)",
  "path": [
    "updateCart",
    "client",
    "firstname"
  ]
}, GraphQLResponseError{
  "message": "Cannot return null for non-nullable type: 'String' within parent 'Client' (/updateCart/client/lastname)",
  "path": [
    "updateCart",
    "client",
    "lastname"
  ]
}, GraphQLResponseError{
  "message": "Cannot return null for non-nullable type: 'String' within parent 'Client' (/updateCart/client/email)",
  "path": [
    "updateCart",
    "client",
    "email"
  ]
}, GraphQLResponseError{
  "message": "Cannot return null for non-nullable type: 'String' within parent 'Client' (/updateCart/client/telephone)",
  "path": [
    "updateCart",
    "client",
    "telephone"
  ]
}, GraphQLResponseError{
  "message": "Cannot return null for non-nullable type: 'AWSDateTime' within parent 'Client' (/updateCart/client/createdAt)",
  "path": [
    "updateCart",
    "client",
    "createdAt"
  ]
}, GraphQLResponseError{
  "message": "Cannot return null for non-nullable type: 'AWSDateTime' within parent 'Client' (/updateCart/client/updatedAt)",
  "path": [
    "updateCart",
    "client",
    "updatedAt"
  ]
}]

We reverted back using cloud formation before adding the new price_adjustments fields, but the error was still there, what could've caused this error? How come it wasn't fixed by the revert? What would be the fix? Also is it possible to copy the same architecture from prod env and make a brand new dev env? We don't really care about the data we just need the fastest solution.

Categories

  • Analytics
  • API (REST)
  • API (GraphQL)
  • Auth
  • Authenticator
  • DataStore
  • Notifications (Push)
  • Storage

Steps to Reproduce

1- Add a new nullable field to the schema (e.g. price_adjustments).
2- Push the changes.
3- Make any GraphQL requests that involve the Building, User, or Client models (e.g. updateCart).

Screenshots

No response

Platforms

  • iOS
  • Android
  • Web
  • macOS
  • Windows
  • Linux

Flutter Version

3.27.1

Amplify Flutter Version

1.8.0

Deployment Method

Amplify CLI (Gen 1)

Schema

enum GenericStatus {
  ACTIVE
  INACTIVE
  DELETED
}

enum WindowStatus {
  not_yet_measured
  select_styles
  order_pending
  order_received
  order_in_progress
  order_in_transit
  wait_for_measurements
  not_yet_installed
  installed
  pairing_pending
  paired
  deleted
}

enum FamilyRole {
  OWNER
  KID
  USER
  ADMIN
}

enum AddressType {
  billing
  shipping
}

type ProductCategory @model @auth(rules: [{allow: private, operations: [read]}, {allow: private, provider: iam}]) {
  id: ID!
  name: String!
  verbose_name: String
  notes: String
  status: GenericStatus!
  data: String
  custom_fields: String
  components: [Component] @manyToMany(relationName: "ProductCategoryComponent")
  products: [Product] @manyToMany(relationName: "ProductCategoryProduct")
  genericproductID: ID @index(name: "byGenericProduct")
  genericproduct: GenericProduct @belongsTo(fields: ["genericproductID"])
}

type Component @model @auth(rules: [{allow: private, operations: [read]}, {allow: private, provider: iam}]) {
  id: ID!
  name: String!
  verbose_name: String
  notes: String
  status: GenericStatus!
  data: String
  custom_fields: String
  productcategories: [ProductCategory] @manyToMany(relationName: "ProductCategoryComponent")
}

type Product @model @auth(rules: [{allow: private, operations: [read]}, {allow: private, provider: iam}]) {
  id: ID!
  name: String!
  verbose_name: String
  description: String
  product_line: String
  external_id: String
  price: Float
  notes: String
  status: GenericStatus!
  data: String
  custom_fields: String
  manufacturerID: ID
  manufacturer: Manufacturer @hasOne(fields: ["manufacturerID"])
  componentID: ID
  component: Component @hasOne(fields: ["componentID"])
  categories: [ProductCategory] @manyToMany(relationName: "ProductCategoryProduct")
  genericproductID: ID @index(name: "byGenericProduct")
  genericproduct: GenericProduct @belongsTo(fields: ["genericproductID"])
  
  #For ticket#957
  #supplierID: ID  @index(name: "bySupplier", sortKeyFields: ["name"])
  #supplier: User @belongsTo(fields: ["supplierID"])
}

type Manufacturer @model @auth(rules: [{allow: private, operations: [read]}, {allow: private, provider: iam}]) {
  id: ID!
  name: String
  verbose_name: String
  notes: String
  status: GenericStatus!
  data: String
  custom_fields: String
}

type Partner @model @auth(rules: [{allow: private, operations: [read]}, {allow: private, provider: iam}]) {
  id: ID!
  name: String
  verbose_name: String
  address: String
  contact: String
  notes: String
  status: GenericStatus!
  data: String
  custom_fields: String
}


type GenericProduct @model @auth(rules: [{allow: private, operations: [read]}, {allow: private, provider: iam}]) {
  id: ID!
  name: String!
  verbose_name: String
  configuration: String
  notes: String
  status: GenericStatus!
  data: String
  custom_fields: String
  products: [Product] @hasMany(indexName: "byGenericProduct", fields: ["id"])
  categories: [ProductCategory] @hasMany(indexName: "byGenericProduct", fields: ["id"])
}

type Address @model @auth(rules: [{allow: owner, identityClaim: "sub", ownerField: "users"}, {allow: private, provider: iam}]) {
  id: ID!
  name: String!
  line1: String!
  line2: String
  city: String!
  state: String!
  country: String!
  postalCode: String!
  type: AddressType
  isBilling: Boolean
  isShipping: Boolean
  isSelected: Boolean
  status: GenericStatus!
  data: String
  users: [String!]
  families: [Family] @hasMany(indexName: "byAddressFamily", fields: ["id"])
}

type Window @model @auth(rules: [{allow: owner, identityClaim: "sub", ownerField: "users"}, {allow: private, provider: iam}]) {
  id: ID!
  name: String!
  status: WindowStatus!
  data: String
  users: [String!]
  roomID: ID!
  room: Room @hasOne(fields: ["roomID"])
  families: [Family] @hasMany(indexName: "byWindowFamily", fields: ["id"])
  orderID: String
  orderStatus: String #suborder status
  notes: String
}

type Room @model @auth(rules: [{allow: owner, identityClaim: "sub", ownerField: "users"}, {allow: private, provider: iam}]) {
  id: ID!
  name: String!
  status: GenericStatus!
  data: String
  buildingID: ID!
  building: Building @hasOne(fields: ["buildingID"])
  users: [String!]
  families: [Family] @hasMany(indexName: "byRoomFamily", fields: ["id"])
}

type Building @model @auth(rules: [{allow: owner, identityClaim: "sub", ownerField: "users"}, {allow: private, provider: iam}]) {
  id: ID!
  name: String!
  status: GenericStatus!
  data: String
  users: [String!]
  families: [Family] @hasMany(indexName: "byBuildingFamily", fields: ["id"])
  carts: [Cart] @hasMany(indexName: "byCartBuilding", fields: ["id"])
  notes: String
}

# @manyToMany creates a relationship table FamilyUsers
type Family @model @auth(rules: [{allow: owner, , identityClaim: "sub"}, {allow: private, provider: iam}]) {
  id: ID!
  name: String!
  status: GenericStatus!
  data: String
  #members: [User] @manyToMany(relationName: "FamilyUsers")
  members: [FamilyUser] @hasMany(indexName: "byFamilyUserFamily", fields: ["id"])
  windowID: ID @index(name: "byWindowFamily", sortKeyFields: ["name"])
  window: Window @belongsTo(fields: ["windowID"])
  roomID: ID @index(name: "byRoomFamily", sortKeyFields: ["name"])
  room: Room @belongsTo(fields: ["roomID"])
  buildingID: ID @index(name: "byBuildingFamily", sortKeyFields: ["name"])
  building: Building @belongsTo(fields: ["buildingID"])
  addressID: ID @index(name: "byAddressFamily", sortKeyFields: ["name"])
  address: Address @belongsTo(fields: ["addressID"])
}

type FamilyUser @model @auth(rules: [{ allow: owner, identityClaim: "sub"}, { allow: private, operations: [create,read,update] },{ allow: private, provider: iam }]) {
    id: ID!
    familyID: ID @index(name: "byFamilyUserFamily", sortKeyFields: ["memberID"])
    memberID: ID @index(name: "byFamilyUserUser", sortKeyFields: ["familyID"])
    family: Family @belongsTo(fields: ["familyID"])
    member: User @belongsTo(fields: ["memberID"])
    role: FamilyRole!
    status: GenericStatus!
    data: String
}

type User @model @auth(rules: [{allow: owner, identityClaim: "sub"}, {allow: private, provider: iam}]) {
  id: ID!
  email: String!
  status: GenericStatus!
  data: String
  #families: [Family] @manyToMany(relationName: "FamilyUsers")
  families: [FamilyUser] @hasMany(indexName: "byFamilyUserUser", fields: ["id"])
  carts: [Cart] @hasMany(indexName: "byCartUser", fields: ["id"])
  #For ticket#957
  #products: [Product] @hasMany(indexName: "bySupplier", fields: ["id"])
}
 
type Client @model @auth(rules: [{ allow: owner, identityClaim: "sub", ownerField: "owner"}, { allow: private, provider: iam }]) {
  id: ID!
  firstname: String!
  lastname: String!
  email: String!
  telephone: String!
  claimed: Boolean
  data: String
  status: GenericStatus
  carts: [Cart] @hasMany(indexName: "byCartClient", fields: ["id"])
  owner: String
}

type Cart @model @auth(rules: [{ allow: owner, identityClaim: "sub", ownerField: "owner"}, { allow: private, provider: iam }]) {
  id: ID!
  buildingID: ID! @index(name: "byCartBuilding", sortKeyFields: ["id"])
  userID: ID @index(name: "byCartUser", sortKeyFields: ["id"])
  clientID: ID @index(name: "byCartClient", sortKeyFields: ["id"])
  savedCart: String!
  building: Building @belongsTo(fields: ["buildingID"])
  user: User @belongsTo(fields: ["userID"])
  client: Client @belongsTo(fields: ["clientID"])
  owner: String
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    GraphQL APIIssues related to the API (GraphQL) CategoryquestionA question about the Amplify Flutter libraries

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions