Skip to content

Better Codegen: Pagination Support #187

Open
@karrettgelley

Description

@karrettgelley

Is your feature request related to a problem? Please describe.
Is there any chance codegen can be enhanced to allow for pagination out of the box? It'd be great to not have to write my own queries.ts with this ability.

Describe the solution you'd like
Take a model like this:

type User @model {
  id: ID!
  todos: [Todo] @connection(fields:["id"])
}

type Todo @model {
  id: ID!
  userID: ID!
  user: User @connection(fields:["userID"]
}

As codegen operates currently, a queries file will be generated that looks something lik:

export const getUser = 
  GetUser($id: ID!) {
    getUser($id: ID!) {
      id
      todos  {
        items {
          id
        }
      } 
    }
  }

To my understanding, pagination can only be achieved by then implementing a custom query like so:

export const getUser = 
  GetUser($id: ID!, $limit: Int, $nextToken: String) {
    getUser($id: ID!, $limit: Int, $nextToken: String) {
      id
      todos(limit: $limit, nextToken: $nextToken)  {
        items {
          id
        }
      } 
    }
  }

I think this is a fairly easy opportunity to automate this process with codegen.

Describe alternatives you've considered
I use string interpolation to implement this functionality but it's really annoying when the schema changes to have to re-update the query.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requestNew feature or requesttype-genIssues on graphql-type-generator

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions