amplify-js: DataStore cannot find ID field of connected record

Before opening, please confirm:

JavaScript Framework

Not applicable

Amplify APIs

DataStore

Amplify Categories

api

Environment information

# Put output below this line
npx: installed 1 in 1.21s

  System:
    OS: Linux 4.14 Amazon Linux 2
    CPU: (2) x64 Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
    Memory: 6.61 GB / 7.58 GB
    Container: Yes
    Shell: 4.2.46 - /bin/bash
  Binaries:
    Node: 10.23.1 - ~/.nvm/versions/node/v10.23.1/bin/node
    npm: 6.14.10 - ~/.nvm/versions/node/v10.23.1/bin/npm
  npmGlobalPackages:
    @aws-amplify/cli: 4.51.0
    cdk: 1.83.0
    coffeescript: 2.5.1
    esformatter: 0.11.3
    js-beautify: 1.13.2
    npm: 6.14.10
    prettier: 2.2.1
    typescript: 3.7.5

Describe the bug

See the code snippet below - but the id of the connected model is not available to query within DataStore.

In our GraphQL application, if I want to query for all assets in the same plant in GraphQL I would query for assetPlantId = the Plant ID I want and I can retrieve connected plant information.

However, in DataStore, whilst I can query for an asset and get related plant information when I query an asset, I can’t query on the ID field (ie. assetPlantId) - it shows that it doesn’t exist in the model even though it is in the GraphQL schema and I can query in GraphQL with it.

Expected behavior

That DataStore allows me to query the ID of the connected record

Reproduction steps

See code snippet below.

Code Snippet

// Put your code below this line.
type Asset @model{
  id: ID
  assetPlantId: ID
  plant: Plant @connection (field: "assetPlantId")
}

type Plant @model{
   id: ID
}

Log output

// Put your logs below this line


aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 16 (4 by maintainers)

Most upvoted comments

It would appear that I have to manually add the following code to the schema.js file then it works fine. Problem is that I have 165 connections like this - that is 165 manual entries every time I change the model. Can amplify codegen models just include this field?

        "Asset": {
            "name": "Asset",
            "fields": {
                "assetPlantId": {
                    "name": "assetPlantId",
                    "isArray": false,
                    "type": "ID",
                    "isRequired": false,
                    "attributes": []
                }
             }