Running into a problem with the API generated with aws amplify.
Basically, I keep getting the following warning whenever I try to create one entity and it is not being persisted in DynamoDB.
Variable 'input' has coerced Null value for NonNull type 'String!
The following are the pertinent parts of the Graphql schema I used to create the backend.
enum EntityStatus {
ACTIVE
INACTIVE
ARCHIVED
}
type Address {
streetAddress1: String!
streetAddress2: String
city: String!
state: String!
zipCode: String!
country: String!
location: Location!
}
type Location {
lat: Float
lng: Float
}
type Tenant
@model
@auth(
rules: [
{ allow: groups, groups: ["Admin", "Coordinator", "Employees"], operations }
{ allow: groups, groups: ["Auditor"], operations: [read] }
]
) {
id: ID!
name: String!
address: Address!
phone: AWSPhone!
email: AWSEmail!
status: EntityStatus!
locale: String!
}
The code to create one of the Tenant
entities is a simple call
try {
return await DataStore.save(new Tenant({ ...values }));
} catch (error) {
console.error(error);
}
The payload going sent by Datastore is as follows:
{
"name": "Tenant 1",
"phone": "1234567890",
"email": "[email protected]",
"status": "ACTIVE",
"address": {
"city": "Anytown",
"state": "TAB",
"zipCode": "12345",
"country": "US",
"location": { "lat": 123.12, "lng": 123.12 }
},
"locale": "en-US",
"id": "f8be53bd-b1cb-4cbd-9b64-01fdf930da8a"
}
Here is the full Warning message
[WARN] 40:26.787 DataStore
Object { localModel: {…}, message: "Variable 'input' has coerced Null value for NonNull type 'String!'", operation: "Create", errorType: undefined, errorInfo: undefined, remoteModel: null }
errorInfo: undefined
errorType: undefined
localModel: Object { id: "f8be53bd-b1cb-4cbd-9b64-01fdf930da8a", name: "Tenant 1", phone: "1234567890", … }
_deleted: undefined
_lastChangedAt: undefined
_version: undefined
address: Object { city: "Anytown", state: "TAB", zipCode: "12345", … }
createdAt: undefined
email: "[email protected]"
id: "f8be53bd-b1cb-4cbd-9b64-01fdf930da8a"
locale: "en-US"
name: "Tenant 1"
phone: "1234567890"
status: "ACTIVE"
updatedAt: undefined
<prototype>: Object { … }
message: "Variable 'input' has coerced Null value for NonNull type 'String!'"
operation: "Create"
remoteModel: null
<prototype>: Object { … }
react_devtools_backend.js:3973:25
Figured it out. My payload was missing 2 fields.
Wish that the error messages would be more helpful.