Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support non string type in sort key in Eagerly load #2985

Open
tcydig opened this issue Oct 29, 2024 · 3 comments
Open

support non string type in sort key in Eagerly load #2985

tcydig opened this issue Oct 29, 2024 · 3 comments
Labels
bug Something isn't working Gen 2

Comments

@tcydig
Copy link

tcydig commented Oct 29, 2024

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?

@chrisbonifacio
Copy link
Member

Hi @tcydig thanks for raising this issue!

based on the linked code, it seems the transformer is incorrectly casting the numeric sort key value into a string which is causing this issue.

@tcydig
Copy link
Author

tcydig commented Nov 11, 2024

Hi @chrisbonifacio thank you for checking it and i am sorry to response late.

today i fixed the issue and i made PR(#3011 )!

@AnilMaktala AnilMaktala added the bug Something isn't working label Dec 10, 2024
@AnilMaktala
Copy link
Member

Hey @tcydig, Thanks for raising the PR. We will review the PR and get back to you.

@AnilMaktala AnilMaktala removed the to-be-reproduced Pending reproduction label Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Gen 2
Projects
None yet
Development

No branches or pull requests

3 participants