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

Query on secondary index throws without error #2525

Closed
kekami opened this issue May 3, 2024 · 6 comments
Closed

Query on secondary index throws without error #2525

kekami opened this issue May 3, 2024 · 6 comments
Assignees
Labels

Comments

@kekami
Copy link

kekami commented May 3, 2024

Environment information

System:
  OS: macOS 14.4.1
  CPU: (10) arm64 Apple M1 Max
  Memory: 184.45 MB / 32.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node
  Yarn: 1.22.22 - ~/.nvm/versions/node/v18.20.0/bin/yarn
  npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm
  pnpm: 8.15.6 - /opt/homebrew/bin/pnpm
NPM Packages:
  @aws-amplify/backend: 1.0.0
  @aws-amplify/backend-cli: 1.0.1
  aws-amplify: 6.2.0
  aws-cdk: 2.137.0
  aws-cdk-lib: 2.137.0
  typescript: 5.4.5
AWS environment variables:
  AWS_SDK_LOAD_CONFIG = 1
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
No CDK environment variables

Description

Created a simple reproducable schema:

const schema = a.schema({
  Project: a
    .model({
      userId: a.string().required(),
      publishedAt: a.datetime().required(),
    })
    .authorization((allow) => [allow.authenticated()])
    .secondaryIndexes((index) => [index("userId").sortKeys(["publishedAt"])]),
});

When trying to query using the generated .listProjectByUserIdAndPublishedAt function, it throws without an error message.

Example App.tsx

import { useEffect } from "react";

import "./App.css";
import { generateClient } from "aws-amplify/api";
import { Schema } from "../amplify/data/resource";
import { Amplify } from "aws-amplify";
import outputs from "../amplify_outputs.json";

Amplify.configure(outputs);

const client = generateClient<Schema>();

function App() {
  useEffect(() => {
    (async () => {
      try {
        const { data, errors } =
          await client.models.Project.listProjectByUserIdAndPublishedAt({
            userId: "l32khj32",
            publishedAt: { gt: new Date().toISOString() },
          });

        // Never reaches here
        console.warn({ data, errors });
      } catch (e) {
        // Logs {}
        console.warn(JSON.stringify(e));
      }
    })();
  }, []);

  return (
    <>
      <div />
    </>
  );
}

export default App;
@kekami
Copy link
Author

kekami commented May 3, 2024

Debugging Appsync I uncovered the underlying error message:

{
    "logType": "GraphQLFieldValidationError",
    "fieldInError": true,
    "path": [
        "null"
    ],
    "errors": [
        "Validation error of type UnknownType: Unknown type ModelAWSDateTimeKeyConditionInput"
    ],
    "requestId": "fe2df959-8e31-41ec-beb3-89cdd129d033",
    "graphQLAPIId": "eqbbb3ucprczjnretbat3g7zli"
}

@ykethan
Copy link

ykethan commented May 3, 2024

hey👋 thanks for raising this! I'm going to transfer this over to our API repository for better assistance 🙂

@ykethan ykethan transferred this issue from aws-amplify/amplify-backend May 3, 2024
@renebrandel
Copy link
Contributor

renebrandel commented May 7, 2024

@kekami - we're actively working on it. We've almost gotten the fix wrapped up.

@chrisbonifacio chrisbonifacio added bug Something isn't working and removed pending-triage labels May 7, 2024
@ChristopherGabba
Copy link

+1 on this error, except all of my secondary index queries are throwing: [TypeError: Cannot convert null value to object].

// model
Friendship: a
    .model({
      id: a.id().required(),
      receiverId: a.id().required(),
      receiver: a.belongsTo("User", "receiverId"),
      senderId: a.id().required(),
      sender: a.belongsTo("User", "senderId"),
      status: a.ref("FriendStatus").required(),
    })
    .authorization((allow) => [allow.publicApiKey()])
    .secondaryIndexes((index) => [
      index("senderId")
        .name("bySender")
        .sortKeys(["receiverId"])
        .queryField("listFriendshipsBySenderId"),
      index("receiverId")
        .name("byReceiver")
        .sortKeys(["senderId"])
        .queryField("listFriendshipsByReceiverId"),
    ])
    // code
    const currentUser = await getCurrentUser()

     const client = generateClient<Schema>()
    
     const response = await client.models.Friendship.listFriendshipsByReceiverId({ <--- throwing error every time
          receiverId: currentUser.userId,
     })

I have checked if the getCurrentUser is

@iartemiev
Copy link
Contributor

We've patched this bug in the latest release of @aws-amplify/data-schema.
Please 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
Projects
None yet
Development

No branches or pull requests

7 participants