[Bug? DX issue?] DataStore opaquely coerces my NonNull field to Null and silently fails without error
See original GitHub issueDescribe the bug
My schema.graphql
:
schema.graphql
:type Board @model @auth(rules: [{ allow: owner }]) {
id: ID!
name: String!
lists: [List] @connection(keyName: "byBoard", fields: ["id"])
}
type List
@model
@key(name: "byBoard", fields: ["boardID"], queryField: "listsByBoard")
@auth(rules: [{ allow: owner }]) {
id: ID!
title: String!
boardID: ID!
board: Board @connection(fields: ["boardID"])
cards: [Card] @connection(keyName: "byList", fields: ["id"])
}
type Card
@model
@key(name: "byList", fields: ["listID", "content"], queryField: "cardsByList")
@auth(rules: [{ allow: owner }]) {
id: ID!
listID: ID!
list: List @connection(fields: ["listID"])
content: String!
}
Here is what i am trying to do:
const newCard = {
id: '23',
content: cardFormState.content,
listID: listId, // i have checked that this is not null
}
await DataStore.save(new Card(newCard))
Yet when I run this code it does not error, does not save this to AppSync/DynamoDB, and logs this warning in the browser:
"Variable 'input' has coerced Null value for NonNull type 'ID!'"
the full response is {"data":null,"errors":[{"path":null,"locations":[{"line":1,"column":20,"sourceName":null}],"message":"Variable 'input' has coerced Null value for NonNull type 'ID!'"}]}
I assume this is just graphql helpfully suppressing the error for us. I would expect DataStore to surface this error.
However even this error message is not helpful, and I have no idea why DataStore is coercing what i have clearly checked is a string, to null. I am out of ideas on how to fix this.
To Reproduce
you can clone https://github.com/sw-yx/trello-amplified and add auth and add api (my attempt here)
or
you can watch my 2 minute video bug report here: https://youtu.be/25PWIBfhfZE
Expected behavior
- it should error when there is an error
- error message should give more information than this
- why is it even coercing null value for my non null input
context
- potentially related to https://github.com/aws-amplify/amplify-js/issues/5855
- yes i have reviewed the relational model docs on datastore https://docs.amplify.aws/lib/datastore/relational/q/platform/js
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (7 by maintainers)
Top GitHub Comments
I confirmed with @iartemiev that (1) is working is working “as intended” for now. Datastore does not auto populate connections you’ll have to query by connected id for now as seen in my repo.
One reason is that we don’t want to throw errors when one model fails to sync; so others continue syncing to minimize data loss. Definitely still worth more discussions.
Now, why did the model pass local validations `validateModelFields` before sending a appsync graphql request?
boardID: ID!
= null passed because it is missing a field definition in generatedmodels/schema.js
:Snippet from
schema.graphql
:Snippet from `schema.js` missing boardID field definition:
So the code snippet in my first comment is setting
boardID
to null and then the local validation is passing it without checks as theboardID
field definition is undefined.RE (1): Check out #6973 ; )
I guess it’s just not possible right now. For the time being you can work on top of my repo which is using what’s currently possible with datastore to create trello-amplified.