amplify-category-api icon indicating copy to clipboard operation
amplify-category-api copied to clipboard

support non string type in sort key in Eagerly load

Open tcydig opened this issue 1 year ago • 4 comments

Environment information

System:
  OS: Windows 11 10.0.22631
  CPU: (32) x64 13th Gen Intel(R) Core(TM) i9-13900K
  Memory: 112.70 GB / 127.78 GB
Binaries:
  Node: 20.11.0 - C:\Program Files\nodejs\node.EXE
  Yarn: undefined - undefined
  npm: 10.2.4 - C:\Program Files\nodejs\npm.CMD
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/auth-construct: 1.3.1
  @aws-amplify/backend: 1.5.0
  @aws-amplify/backend-auth: 1.2.0
  @aws-amplify/backend-cli: 1.2.9
  @aws-amplify/backend-data: 1.1.4
  @aws-amplify/backend-deployer: 1.1.4
  @aws-amplify/backend-function: 1.7.0
  @aws-amplify/backend-output-schemas: 1.3.0
  @aws-amplify/backend-output-storage: 1.1.2
  @aws-amplify/backend-secret: 1.1.4
  @aws-amplify/backend-storage: 1.2.1
  @aws-amplify/cli-core: 1.1.3
  @aws-amplify/client-config: 1.4.0
  @aws-amplify/deployed-backend-client: 1.4.1
  @aws-amplify/form-generator: 1.0.3
  @aws-amplify/model-generator: 1.0.8
  @aws-amplify/platform-core: 1.1.0
  @aws-amplify/plugin-types: 1.3.0
  @aws-amplify/sandbox: 1.2.3
  @aws-amplify/schema-generator: 1.2.4
  aws-amplify: 6.6.5
  aws-cdk: 2.162.1
  aws-cdk-lib: 2.162.1
  typescript: 5.6.3
AWS environment variables:
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
  AWS_STS_REGIONAL_ENDPOINTS = regional
No CDK environment variables

Data packages

├─┬ @aws-amplify/[email protected]
│ └─┬ @aws-amplify/[email protected]
│   └── @aws-amplify/[email protected]
└─┬ @aws-amplify/[email protected]
  └─┬ @aws-amplify/[email protected]
    └── @aws-amplify/[email protected]

Description

Which Category is your question related to? API

What AWS Services are you utilizing? Amplify Gen2(v6),AWS AppSync, DynamoDB

what is your goal My goal is that i can get Patient and PlanDoc Info using Eagerly load

what is a issue The problem is that when a Hasmany relation is created with PK and SK (Interger) and an Eagerly load is performed, a string type is forced on the SK of the child table and a type error occurs

Provide additional details e.g. code snippets Hi, I'm trying to create a hasmany relation between two tables as follows: (amplify/data/resource.ts)

const schema = a.schema({
  Patient:a
    .model({
      userId:a.id().required(),
      patientId:a.integer().required(),
      planDocs:a.hasMany('PlanDoc',['userId','patientId']),
      version:a.integer().required(),
    })
    .identifier(['userId','patientId'])
    .authorization((allow)=>[allow.publicApiKey()]),
  PlanDoc:a
    .model({
      userIdAndPatientId:a.string().required(),
      docCount:a.integer().required(),
      userId:a.id().required(),
      patientId:a.integer().required(),
      patient:a.belongsTo('Patient',['userId','patientId']),
      version:a.integer().required(),
    })
    .identifier(['userIdAndPatientId','docCount'])
    .secondaryIndexes((index)=>[
      index('userId')
      .sortKeys(['consultationDate'])
    ])
    .authorization((allow)=>[allow.publicApiKey()]),

Then I would like to get Patient and PlanDoc Info using Eagerly load as follows: (i'm using Typescript)

async getPatientSummary(userId:string,patientId:number) {
    const {data:result, errors} = await this._client.models.Patient.get({
        userId:userId,
        patientId:patientId
    },{ 
        selectionSet: [
            'userId',
            'patientId',
            'planDocs.userIdAndPatientId',
            'planDocs.docCount',
            'planDocs.userId',
            'planDocs.patientId',
        ]
    },)
    return result
}

I expected i get correct data without error after doing that query. But I got correct patient info and a error as follows:

{
    "data": {
        "getPatient": {
            "userId": "mask",
           ...
           "planDocs":null
        }
    },
    "errors": [
        {
            "path": [
                "getPatient",
                "planDocs"
            ],
            "data": null,
            "errorType": "DynamoDB:DynamoDbException",
            "errorInfo": null,
            "locations": [
                {
                    "line": 11,
                    "column": 5,
                    "sourceName": null
                }
            ],
            "message": "One or more parameter values were invalid: Condition parameter type does not match schema type (Service: DynamoDb, Status Code: 400, Request ID: mask)"
        }
    ]
}

After contacting the AWS support team, the reason was that the patientId attribute should be ‘N’ in the Query to the child table during the Eagerly load, but it was set to ‘S’. Therefore, we feel that the parts of the amplify-category-api package, which generates the problematic resolver, need to be fixed. amplify-category-api/packages/amplify-graphql-relational-transformer/src/resolver/ddb-generator.ts

Sorry, but I would like someone to confirm if this problem is a bug and, if so, Please could you fix it?

tcydig avatar Oct 29 '24 03:10 tcydig