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

Multi-level item in selectionSet is not received. #12665

Closed
3 tasks done
erickriva opened this issue Dec 2, 2023 · 8 comments
Closed
3 tasks done

Multi-level item in selectionSet is not received. #12665

erickriva opened this issue Dec 2, 2023 · 8 comments
Assignees
Labels
Gen 2 Issues related to Gen 2 Amplify projects GraphQL Related to GraphQL API issues investigating This issue is being investigated V6 V6 of Amplify JS

Comments

@erickriva
Copy link
Contributor

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

GraphQL API

Amplify Categories

No response

Environment information

  System:
    OS: Windows 11 10.0.23590
    CPU: (16) x64 AMD Ryzen 9 5900HX with Radeon Graphics
    Memory: 13.21 GB / 23.91 GB
  Binaries:
    Node: 18.18.2 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 9.8.1 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.11.0 - ~\AppData\Local\pnpm\pnpm.EXE
    bun: Not Found
    Watchman: Not Found
  npmPackages:
    @aws-amplify/backend: 0.5.5
    @aws-amplify/backend-cli: 0.9.1
    aws-amplify: 6.0.5
    aws-cdk: Not Found
    aws-cdk-lib: 2.111.0
    typescript: 5.3.2

Describe the bug

A multi-level item in selectionSet is not received.

Expected behavior

Expected to receive data for any level of nested query.

Reproduction steps

  • Declare schema as following:
import { a } from "@aws-amplify/backend";

const schema = a.schema({
  CommunityPost: a.model({
    id: a.id().required(),
    poll: a.hasOne("CommunityPoll"),
  }),

  CommunityPoll: a.model({
    id: a.id().required(),
    question: a.string().required(),
    answers: a.hasMany("CommunityPollAnswer").arrayRequired().valueRequired(),
  }),

  CommunityPollAnswer: a.model({
    id: a.id().required(),
    answer: a.string().required(),
    votes: a.hasMany("CommunityPollVote").arrayRequired().valueRequired(),
  }),

  CommunityPollVote: a.model({ id: a.id().required() }),
});
  • Try to get data using:
amplifyClient.models.CommunityPost.get(
    { id: 'post id' },
    {
      selectionSet: [
        "id",
        "poll.id",
        "poll.question",
        "poll.answers.id",
        "poll.answers.answer",
        "poll.answers.votes.id",
      ],
    }
  );
  • CommunityPost is received.
  • poll properties are received.
  • poll.answers properties are received, except for poll.answers.votes

Code Snippet

// Put your code below this line.

Log output

// Put your logs below this line


aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

@erickriva erickriva added the pending-triage Issue is pending triage label Dec 2, 2023
@erickriva
Copy link
Contributor Author

Testing directly through AppSync, with query:

query MyQuery {
  listCommunityPosts {
    items {
      id
      poll {
        question
        answers {
          items {
            answer
            votes {
              items {
                id
              }
            }
          }
        }
      }
    }
  }
}

Following data is returned:

{
  "data": {
    "listCommunityPosts": {
      "items": [
        {
          "id": "2",
          "poll": null
        },
        {
          "id": "1",
          "poll": {
            "question": "Is this a good question for showing in issue?",
            "answers": {
              "items": [
                { "answer": "Yes", "votes": { "items": [] } },
                { "answer": "No",  "votes": { "items": [ { "id": "f0396484-e3c8-4fbc-87cb-1811bad7b4af" } ]  }
                }
              ]
            }
          }
        }
      ]
    }
  }
}

@nadetastic nadetastic added the GraphQL Related to GraphQL API issues label Dec 4, 2023
@chrisbonifacio
Copy link
Contributor

chrisbonifacio commented Dec 4, 2023

Hi @erickriva 👋 thanks for raising this issue. Can you inspect the network request that is made when using the client?

Is the shape of the graphql request the same as the one you tried in the AppSync console?

@chrisbonifacio chrisbonifacio added investigating This issue is being investigated pending-response Issue is pending response from the issue requestor and removed pending-triage Issue is pending triage labels Dec 4, 2023
@erickriva
Copy link
Contributor Author

I think I may have confused up things (sorry, it was almost midnight 🥱), but seems there's a bug here still.

Request:

{
  "query": "query ($id: ID!) {\n  getCommunityPost(id: $id) {\n    id\n      poll {\n      id\n      question\n      answers {\n        items {\n          votes {\n            items {\n              id\n            }\n          }\n        }\n      }\n    }\n  }\n}\n",
  "variables": {
    "id": "1"
  }
}

Response:

{
  "data": {
    "getCommunityPost": {
      "id": "1",
      "poll": {
        "id": "1",
        "question": "Is this a good question for showing in issue?",
        "answers": {
          "items": [
            {
              "votes": {
                "items": []
              }
            },
            {
              "votes": {
                "items": [
                  {
                    "id": "f0396484-e3c8-4fbc-87cb-1811bad7b4af"
                  }
                ]
              }
            }
          ]
        }
      }
    }
  }
}

They seems to match between them, but not with my code: selectionSet: [ "id", "poll.id", "poll.question", "poll.answers.id", "poll.answers.answer", "poll.answers.votes.id" ]

answers.id and answers.answer aren't present in the request, so no response too. But answers.votes.id is present.

@chrisbonifacio chrisbonifacio added the Gen 2 Issues related to Gen 2 Amplify projects label Dec 4, 2023
@chrisbonifacio chrisbonifacio self-assigned this Dec 4, 2023
@cwomack cwomack removed the pending-response Issue is pending response from the issue requestor label Dec 11, 2023
@erickriva
Copy link
Contributor Author

@chrisbonifacio I've been trying to modify the lib's code for the last days and I think I have solved the issue. Don't know about performance yet. I will open a PR soon.

@erickriva
Copy link
Contributor Author

In the case this PR is approved, I'll send another to fix this issue, at least the execution part of it. Maybe I can fix TS too.

@chrisbonifacio
Copy link
Contributor

Hey @erickriva thank you for looking into this and submitting a PR! I will bring it to the team's attention.

@erickriva
Copy link
Contributor Author

PR #12701 was merged, released in 6.0.9, and this problem was solved.
Thank you @chrisbonifacio!

@chrisbonifacio
Copy link
Contributor

@erickriva thank YOU, sir! Excellent work 🙏

@nadetastic nadetastic added the V6 V6 of Amplify JS label Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gen 2 Issues related to Gen 2 Amplify projects GraphQL Related to GraphQL API issues investigating This issue is being investigated V6 V6 of Amplify JS
Projects
None yet
Development

No branches or pull requests

4 participants