Skip to content
This repository was archived by the owner on Jun 14, 2026. It is now read-only.

Add ability to format lists with paginated results including totalCount#80

Open
DaKaZ wants to merge 3 commits into
Vincit:masterfrom
DaKaZ:pagination
Open

Add ability to format lists with paginated results including totalCount#80
DaKaZ wants to merge 3 commits into
Vincit:masterfrom
DaKaZ:pagination

Conversation

@DaKaZ

@DaKaZ DaKaZ commented May 29, 2019

Copy link
Copy Markdown

In our use of objection-graphql we were having a hard time doing pagination correctly. The main reason is that we did not receive a totalCount of records available which made layout of the results difficult.

With this PR, you can build your schema passing true into the build function like this:

const rootSchema = builder()
  .allModels(allModels);
  .build(true);

and once that is constructed, you can query like this:

query fetchUsers {
  users(limit: 4, offset: 6) {
    collection {
      id
      name
      handle
      location
      pets {
        name
        type
      }
    }
    totalCount
  } 
}

and the totalCount is returned along with a list of the users.

Michael S. Kazmier added 2 commits May 29, 2019 12:54
@DaKaZ

DaKaZ commented Sep 13, 2019

Copy link
Copy Markdown
Author

@nasushkov any chance to get a review/comments on this PR?

@lookfirst

Copy link
Copy Markdown

@DaKaZ This looks nice except that I wouldn't do it with a naked boolean to build(). I'd add .paginated() or at least pass in an object into build(), which could take an argument, the name of the 'collection' and 'totalCount' properties in case someone wanted to use something else.

@DaKaZ

DaKaZ commented Dec 18, 2019

Copy link
Copy Markdown
Author

@lookfirst sorry for the incredibly slow turn around! I just revisited this and had an AH HA moment.
I don't know why I did not before, but I move the paginated option into the setBuilderOptions so you can now do this:

const graphQlSchema = graphQlBuilder()
  .model(Movie)
  .model(Person)
  .model(Review)
  .setBuilderOptions({ paginated: true })
  .build(); 

What do you think? I did not add the ability to change the collection or totalCount fields, but that could be subsequent PR if someone really wanted/needed that.

@lookfirst

Copy link
Copy Markdown

@DaKaZ 🤷‍♂ ... I'm super sorry but I moved onto using type-graphql and mikro... pretty much the ideal combination.

@DaKaZ

DaKaZ commented Dec 19, 2019

Copy link
Copy Markdown
Author

@koskimas or @nasushkov - any chance on of you could take a quick look at this and perhaps some of the other PRs that are outstanding?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants