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

Selection Set returns never if an array or the array field is optional and table is queried using many-to-many relations #3062

Closed
MKlaeui opened this issue Dec 10, 2024 · 3 comments
Assignees
Labels
bug Something isn't working data-schema Gen 2

Comments

@MKlaeui
Copy link

MKlaeui commented Dec 10, 2024

Environment information

System:
  OS: Linux 6.6 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
  CPU: (8) x64 AMD Ryzen 3 7320C with Radeon Graphics
  Memory: 4.07 GB / 6.38 GB
  Shell: /bin/bash
Binaries:
  Node: 20.10.0 - ~/.config/nvm/versions/node/v20.10.0/bin/node
  Yarn: 1.22.21 - ~/.config/nvm/versions/node/v20.10.0/bin/yarn
  npm: 10.9.2 - ~/.config/nvm/versions/node/v20.10.0/bin/npm
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/auth-construct: 1.5.1
  @aws-amplify/backend: 1.9.0
  @aws-amplify/backend-auth: 1.4.2
  @aws-amplify/backend-cli: 1.4.3
  @aws-amplify/backend-data: 1.2.2
  @aws-amplify/backend-deployer: 1.1.11
  @aws-amplify/backend-function: 1.9.0
  @aws-amplify/backend-output-schemas: 1.4.0
  @aws-amplify/backend-output-storage: 1.1.4
  @aws-amplify/backend-secret: 1.1.5
  @aws-amplify/backend-storage: 1.2.4
  @aws-amplify/cli-core: 1.2.1
  @aws-amplify/client-config: 1.5.3
  @aws-amplify/deployed-backend-client: 1.4.2
  @aws-amplify/form-generator: 1.0.3
  @aws-amplify/model-generator: 1.0.9
  @aws-amplify/platform-core: 1.3.0
  @aws-amplify/plugin-types: 1.6.0
  @aws-amplify/sandbox: 1.2.7
  @aws-amplify/schema-generator: 1.2.6
  aws-amplify: 6.10.2
  aws-cdk: 2.172.0
  aws-cdk-lib: 2.172.0
  typescript: 5.7.2
No AWS environment variables
No CDK environment variables

Data packages

aws-amplify-gen2@0.1.0 /home/xxx/selection-set-test
├─┬ @aws-amplify/backend-cli@1.4.3
│ └─┬ @aws-amplify/schema-generator@1.2.6
│   └── @aws-amplify/graphql-schema-generator@0.11.2
└─┬ @aws-amplify/backend@1.9.0
  └─┬ @aws-amplify/backend-data@1.2.2
    └── @aws-amplify/data-construct@1.14.2

Description

Thanks for addressing the issue here #2809

This works fine as long as I query a table directly; however, I get inconsistent results when I query many-to-many relationships. Taking the attached schema, I get correct results if I query the Customer table, but when I query Customer via the CustomerPart table, I get this instead:

    const getCustomer = async () => {
        const { data: customerPartSet } = await client.models.CustomerPart.list({
            selectionSet: [
                'id',
                'customerDetails.*',
                'experience',
                'customerId',
                'customer.*',
                'customer.verbiageReqReq.*',
                'customer.verbiageOptReq.*',
                'customer.verbiageReqOpt.*',
                'customer.verbiageOptOpt.*',
                'customer.orders.*',
            ],
        });

        const cps = customerPartSet[0].customer;
        const verbiageReqReq = cps.verbiageReqReq; // should be Verbiage[] and it is!
        const verbiageOptReq = cps.verbiageOptReq; // should be (Verbiage | null)[], but is (never[] | null)[]
        const verbiageReqOpt = cps.verbiageReqOpt; // should be Verbiage[] | null, but is never[][] | null
        const verbiageOptOpt = cps.verbiageOptOpt; // should be (Verbiage | null)[] | null, but is (never[] | null)[] | null
    };

resource.txt

@chrisbonifacio
Copy link
Member

chrisbonifacio commented Dec 12, 2024

Hi @MKlaeui 👋 thanks for raising this issue. I was able to reproduce this particular issue on the latest version of @aws-amplify/data-schema (1.17.1). However, at first I had 1.15.0 installed which did not reproduce the issue and the types seemed correct. I'll mark this as a bug for the team to investigate and fix. In the meantime, if you want to downgrade to @aws-amplify/data-schema@1.15.0 that might unblock you until we release a fix.

1.17.1
CleanShot 2024-12-12 at 14 20 44@2x

1.15.0
CleanShot 2024-12-12 at 14 24 25@2x

@zxl629
Copy link

zxl629 commented Dec 19, 2024

Hi @MKlaeui ,

Thank you for bringing up this issue! We just released a fix for this issue in the latest version of the package (@aws-amplify/data-schema version 1.17.2). Please run npm update @aws-amplify/data-schema@latest to upgrade the package in your project.

Thanks,
Jack

@zxl629 zxl629 closed this as completed Dec 19, 2024
Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working data-schema Gen 2
Projects
None yet
Development

No branches or pull requests

4 participants