question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug? DX issue?] DataStore opaquely coerces my NonNull field to Null and silently fails without error

See original GitHub issue

Describe the bug

My 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

  1. it should error when there is an error
  2. error message should give more information than this
  3. why is it even coercing null value for my non null input

context

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
weicommented, Dec 3, 2020
  1. 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.

  2. 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 generated models/schema.js:

Snippet from schema.graphql:

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"])
}
Snippet from `schema.js` missing boardID field definition:
"List": {
    "name": "List",
    "fields": {
        "id": {
            "name": "id",
            "isArray": false,
            "type": "ID",
            "isRequired": true,
            "attributes": []
        },
        "title": {
            "name": "title",
            "isArray": false,
            "type": "String",
            "isRequired": true,
            "attributes": []
        },
        "board": {
            "name": "board",
            "isArray": false,
            "type": {
                "model": "Board"
            },
            "isRequired": false,
            "attributes": [],
            "association": {
                "connectionType": "BELONGS_TO",
                "targetName": "boardID"
            }
        },
        "cards": {
            "name": "cards",
            "isArray": true,
            "type": {
                "model": "Card"
            },
            "isRequired": false,
            "attributes": [],
            "isArrayNullable": true,
            "association": {
                "connectionType": "HAS_MANY",
                "associatedWith": "list"
            }
        },
        "owner": {
            "name": "owner",
            "isArray": false,
            "type": "String",
            "isRequired": false,
            "attributes": []
        }
    },
    "syncable": true,
    "pluralName": "Lists",
    "attributes": [
        {
            "type": "model",
            "properties": {}
        },
        {
            "type": "key",
            "properties": {
                "name": "byBoard",
                "fields": [
                    "boardID"
                ],
                "queryField": "listsByBoard"
            }
        },
        {
            "type": "auth",
            "properties": {
                "rules": [
                    {
                        "provider": "userPools",
                        "ownerField": "owner",
                        "allow": "owner",
                        "identityClaim": "cognito:username",
                        "operations": [
                            "create",
                            "update",
                            "delete",
                            "read"
                        ]
                    }
                ]
            }
        }
    ]
},

So the code snippet in my first comment is setting boardID to null and then the local validation is passing it without checks as the boardID field definition is undefined.

1reaction
weicommented, Nov 9, 2020

thats a separate issue i ran into that was a dealbreaker for me 😦

RE (1): Check out #6973 ; )

DataStore doesn’t currently support syncing any connections to a model

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Bug? DX issue?] DataStore opaquely coerces my NonNull field to ...
[Bug? DX issue?] DataStore opaquely coerces my NonNull field to Null and silently fails without error. ... Describe the bug. My schema.graphql :....
Read more >
Graphql + Datastore: Variable 'input' has coerced Null value ...
Basically, I keep getting the following warning whenever I try to create one entity and it is not being persisted in DynamoDB. Variable...
Read more >
Oracle Database List of Bugs Fixed - Eygle
This document lists the generic bugs fixed in the Oracle Database 10g Release (10.2.0.4) Patch Set and all previous Oracle Database patch sets....
Read more >
Diff - 1fb8a450ee..97c11a4d77 - chromium/src - Git at Google
Registering a non-null - // hook when a non-null hook is already registered indicates somebody is - // trying to overwrite a hook....
Read more >
hg
Mercurial will update the working directory to the first applicable revision from this list: null if -U or the source repository has no...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found