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 single instance of option CustomType array #2809

Open
MKlaeui opened this issue Aug 27, 2024 · 4 comments
Open

Selection Set returns single instance of option CustomType array #2809

MKlaeui opened this issue Aug 27, 2024 · 4 comments
Assignees
Labels
bug Something isn't working data-schema Gen 2

Comments

@MKlaeui
Copy link

MKlaeui commented Aug 27, 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: 5.55 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.8.2 - ~/.config/nvm/versions/node/v20.10.0/bin/npm
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/auth-construct: 1.2.2
  @aws-amplify/backend: 1.1.1
  @aws-amplify/backend-auth: 1.1.2
  @aws-amplify/backend-cli: 1.2.5
  @aws-amplify/backend-data: 1.1.1
  @aws-amplify/backend-deployer: 1.1.0
  @aws-amplify/backend-function: 1.3.2
  @aws-amplify/backend-output-schemas: 1.2.0
  @aws-amplify/backend-output-storage: 1.1.1
  @aws-amplify/backend-secret: 1.1.0
  @aws-amplify/backend-storage: 1.1.1
  @aws-amplify/cli-core: 1.1.2
  @aws-amplify/client-config: 1.2.1
  @aws-amplify/deployed-backend-client: 1.4.0
  @aws-amplify/form-generator: 1.0.1
  @aws-amplify/model-generator: 1.0.5
  @aws-amplify/platform-core: 1.0.6
  @aws-amplify/plugin-types: 1.2.1
  @aws-amplify/sandbox: 1.2.0
  @aws-amplify/schema-generator: 1.2.1
  aws-amplify: 6.5.3
  aws-cdk: 2.154.0
  aws-cdk-lib: 2.152.0
  typescript: 5.5.4
AWS environment variables:
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
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

Selection Set of an optional array of custom types returns unexpected values. Taking the sample app listed here: [(https://github.com//issues/2368)] , if you replace the line verbiage: a.ref('Verbiage').required().array().required(), with verbiage: a.ref('Verbiage').array().required(), , then the result will be (Verbiage | null)[]. If you replace it with verbiage: a.ref('Verbiage').required().array(), then you get (Verbiage | null). I'm looking for something that returns (Verbiage[] | null). Is that not how it was meant to work?

@AnilMaktala AnilMaktala added question Further information is requested data-schema labels Aug 27, 2024
@MKlaeui
Copy link
Author

MKlaeui commented Aug 28, 2024

Just to elaborate on what I was expecting vs what is happening in each scenario:

  • a.ref("Verbiage").required().array().required() returns Verbiage[], as expected
  • a.ref("Verbiage").array().required() returns (Verbiage | null)[], as expected
  • a.ref("Verbiage").required().array() returns Verbiage | null, I expected Verbiage[] | null
  • a.ref("Verbiage").array() returns Verbiage | null, I expected (Verbiage | null)[] | null

@chrisbonifacio
Copy link
Member

Hi @MKlaeui we were not able to reproduce the issue described. We tried each scenario listed but the type from Schema['Customer']['type']['verbiage'] seems to be correctly mapped to the schema definition.

It seems that your @aws-amplify/backend and @aws-amplify/backend-cli are up to date. Can you check if your @aws-amplify/data-schema is up to date?

@MKlaeui
Copy link
Author

MKlaeui commented Aug 29, 2024

Thanks for looking into this. Data Schema is version 1.3.10

Just want to reiterate that my problem is specific to Selection Set. The Schema is as I expect (for verbiage: a.ref('Verbiage').required().array()):

const v: Schema['Customer']['type']['verbiage'] ; // v = verbiage[] | null | undefined

But using the Selection Set I get:

const { data: customerSet } = await client.models.Customer.list({
selectionSet: ['id', 'name', 'verbiage.', 'orders.',],
});

const abc = customerSet[0].verbiage; // abc = verbiage | null

@chrisbonifacio
Copy link
Member

chrisbonifacio commented Sep 4, 2024

@MKlaeui thank you for reiterating that the issue was with selection set! I had forgotten that was specifically mentioned the first time I tried to reproduce this issue. Using selection set, I definitely see the problem and was able to reproduce consistently even on the latest versions of @aws-amplify/backend packages.

with this schema:

const schema = a.schema({
  AlphabetEnum: a.enum(["A", "B", "C", "D"]),
  Verbiage: a.customType({
    name: a.ref("AlphabetEnum").required(),
    paragraphs: a.string().required().array().required(),
  }),
  Customer: a
    .model({
      id: a.id().required(),
      name: a.string().required(),
      verbiage: a.ref("Verbiage").required().array(),
    })
    .authorization((allow) => [allow.publicApiKey()]),
});

I see verbiage | null when try to get the list of verbiage from a Customer record:

CleanShot 2024-09-04 at 09 47 43@2x

The type should be verbiage[] | null

If I change the type of Customer.verbiage in the schema to this:

verbiage: a.ref("Verbiage").required().array().required(),

Then I see the correct type of verbiage[] | null from the query results:

CleanShot 2024-09-04 at 09 52 20@2x

I will mark this as a bug for the team to look into further

@chrisbonifacio chrisbonifacio added the bug Something isn't working label Sep 4, 2024
@iartemiev iartemiev self-assigned this Sep 9, 2024
@iartemiev iartemiev removed the question Further information is requested label Sep 9, 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 data-schema Gen 2
Projects
None yet
Development

No branches or pull requests

4 participants