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

The query set in secondaryIndexes cannot be executed. #2477

Closed
rnrnstar2 opened this issue Apr 19, 2024 · 6 comments
Closed

The query set in secondaryIndexes cannot be executed. #2477

rnrnstar2 opened this issue Apr 19, 2024 · 6 comments
Labels
bug Something isn't working data-schema duplicate This issue or pull request already exists pending-response transferred

Comments

@rnrnstar2
Copy link

Environment information

npx amplify info                                                                                                          【 main 】
System:
  OS: macOS 14.0
  CPU: (10) arm64 Apple M2 Pro
  Memory: 220.56 MB / 16.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 20.5.0 - /usr/local/bin/node
  Yarn: 1.22.19 - /usr/local/bin/yarn
  npm: 9.8.0 - /usr/local/bin/npm
  pnpm: 8.15.5 - ~/Library/pnpm/pnpm
NPM Packages:
  @aws-amplify/backend: 0.13.0-beta.20
  @aws-amplify/backend-cli: 0.12.0-beta.22
  aws-amplify: 6.0.28
  aws-cdk: 2.138.0
  aws-cdk-lib: 2.138.0
  typescript: 5.4.5
AWS environment variables:
  AWS_PROFILE = cloudteam
  AWS_DEFAULT_PROFILE = cloudteam
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables

Description

The query set in secondaryIndexes cannot be executed.

OnePieceItem: a
 .model({
   name: a.string().required(),
   getInfo: a.string(),
 })
 .secondaryIndexes((index) => [
   index("getInfo").sortKeys(["name"]).queryField("listByGetInfo"),
 ])
 .authorization([
   a.allow.owner(),
   a.allow.private().to(["read", "update", "create"]),
 ]),

const res = await client.models.OnePieceItem.listByGetInfo({
   getInfo,
 });

Property 'listByGetInfo' has type '{ create: (model: { [x: string]: { [x: number]: string; toString: () => string; charAt: (pos: number) => string; charCodeAt: (index: number) => number; concat: (...args: (string | ConcatArray)[]) => string[]; ... 71 more ...; readonly [Symbol.unscopables]: { ...; }; }; }, options?: { ...; }) => Does not exist in SingularRetur...'.

@edwardfoyle edwardfoyle transferred this issue from aws-amplify/amplify-backend Apr 19, 2024
@AnilMaktala
Copy link

Hey @rnrnstar2, Thank you for raising this. We have a follow up question, Have you deployed your backend resources? Can you verify in AppSync console and confirm listByGetInfo query exist?

@rnrnstar2
Copy link
Author

Yes, appsync has listByGetInfo.

スクリーンショット 2024-04-22 12 10 43

@rnrnstar2
Copy link
Author

I selected multiple sortKeys for secondaryIndexes.
Then I couldn't get the list.

Post: a
      .model({
        name: a.string().required(),
        categoryId: a.id().required(),
        s3ImgKey: a.string(),
        message: a.string().required(),
        gender: a.string().required(),
        prefecture: a.string().required(),
        ageGroup: a.string().required(),
        category: a.belongsTo("Category", "categoryId"),
      })
      .secondaryIndexes((index) => [
        index("categoryId")
          .sortKeys(["gender", "prefecture", "ageGroup"])
          .queryField("listByCategoryId"),
      ]),
// @ts-ignore
      const { data: posts, errors } = await client.models.Post.listByCategoryId(
        {
          categoryId,
          gender: {
            eq: gender,
          },
          prefecture: {
            eq: prefecture,
          },
        }
      );
indexQuery.mjs:76 Uncaught (in promise) TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)

@chrisbonifacio
Copy link

Hi @rnrnstar2 thanks for raising this issue.

This seems to be a duplicate of another issue that was opened regarding composite identifiers.

Please track this issue for updates: #2526

@chrisbonifacio chrisbonifacio added duplicate This issue or pull request already exists pending-response and removed pending-triage labels May 7, 2024
@AnilMaktala AnilMaktala added the bug Something isn't working label May 8, 2024
@iartemiev
Copy link
Contributor

iartemiev commented May 14, 2024

We've patched this bug in the latest release of @aws-amplify/data-schema.
Please make sure you're using at least @aws-amplify/backend@1.0.0 and aws-amplify@6.3.0 and then run npm update @aws-amplify/data-schema to consume the patch.

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 duplicate This issue or pull request already exists pending-response transferred
Projects
None yet
Development

No branches or pull requests

5 participants