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

Eager load nested objects in list and get queries #13900

Open
2 tasks
funes79 opened this issue Oct 9, 2024 · 0 comments
Open
2 tasks

Eager load nested objects in list and get queries #13900

funes79 opened this issue Oct 9, 2024 · 0 comments
Assignees
Labels
feature-request Request a new feature GraphQL Related to GraphQL API issues

Comments

@funes79
Copy link

funes79 commented Oct 9, 2024

Is this related to a new or existing framework?

Next.js

Is this related to a new or existing API?

GraphQL API

Is this related to another service?

No response

Describe the feature you'd like to request

In amplify gen2 the eager load allows to fetch nested (one to many) objects. However it does not fetch all the related objects. It would be nice to allow the client to initiate a full load of the related objects. Or if it is possible then it is not mentioned here:
https://docs.amplify.aws/react/build-a-backend/data/data-modeling/relationships/#eagerly-load-a-has-many-relationship

const selectionSet = [
  'id',
  'title',
  'content',
  'tags.*',
] as const;

// this only returns the first 100 tags for each post
const listResult = await client.models.Post.list({
        selectionSet,
      });


// this also does not return all the objects
for (const post of listResult.data) {
        // for each post we load the tags
        const tagsPerPost = await client.models.Post.get(
          {
            id: post.id,
          },
          {
            selectionSet: ['tags.*'] as const,
          }
        );
}

Describe the solution you'd like

const selectionSet = [
  'id',
  'title',
  'content',
  'tags.*',
] as const;

// this way the client would paginate and fetch all the tags until it reaches nextToken null
const listResult = await client.models.Post.list({
        selectionSet,
        fetchMode: {
             tags: "ALL"
        }
      });
// or 
const listResult = await client.models.Post.list({
        selectionSet,
        fetchMode: {
             tags:  {
                limit: 1000
            }
        }
      });

Describe alternatives you've considered

The alternative is to use, but then we loose the typing.

await client.graphql({
        query: /* GraphQL */ `
...

Additional context

No response

Is this something that you'd be interested in working on?

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change
@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending a response from the Amplify team. labels Oct 9, 2024
@funes79 funes79 changed the title Eager load nested objects in list queries Eager load nested objects in list and get queries Oct 9, 2024
@cwomack cwomack added the GraphQL Related to GraphQL API issues label Oct 9, 2024
@chrisbonifacio chrisbonifacio self-assigned this Oct 9, 2024
@chrisbonifacio chrisbonifacio added investigating This issue is being investigated feature-request Request a new feature and removed pending-triage Issue is pending triage investigating This issue is being investigated pending-maintainer-response Issue is pending a response from the Amplify team. labels Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request a new feature GraphQL Related to GraphQL API issues
Projects
None yet
Development

No branches or pull requests

3 participants