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

Add default_page_size to schema, field, and resolver #4081

Merged
merged 9 commits into from May 31, 2022

Conversation

connorshea
Copy link
Contributor

This implements #2999.

Essentially, this allows you to set default_page_size on the schema, fields, and resolvers.

class MyAppSchema < GraphQL::Schema
  default_page_size 50
end

field :items, Item.connection_type, null: false, default_page_size: 25

class ItemResolver < GraphQL::Schema::Resolver
  default_page_size 10
end

If no first: or last: values are specified, the default_page_size will be used to determine the size of a given page of results, and if default_page_size isn't set it'll fall back to the existing behavior with max_page_size. This should be backwards-compatible since the behavior is unchanged if default_page_size isn't set anywhere.

I added basic documentation and specs, and I've tested this manually with my Rails app to make sure the main use-cases all work as-expected there. I'm not sure what other specs should be written for this, if any?

cc: @rmosolgo since you asked for a ping in that issue.

This is configurable on the field-level, resolver-level, and
schema-level. Also add some _very_ basic specs. I probably need to add
quite a few more than this.

I need to figure out whether the complexity calculation logic needs to
be updated to handle this. I also need to figure out whether to add
error handling for the case where max page size < default page size. And
I need to look into how to make `default_page_size: nil` actually return
an unbounded list (or scrap that idea entirely, I guess).
Set a default_page_size value and allow tests to override it via a query
parameter.
Use default_page_size instead of max_page_size if default_page_size is
set either at the field or schema level. Also add a test for field-level
default_page_size.
@rmosolgo
Copy link
Owner

This all looks great -- thanks for the contribution!

@rmosolgo rmosolgo merged commit 12a80ad into rmosolgo:master May 31, 2022
@rmosolgo rmosolgo added this to the 2.0.9 milestone May 31, 2022
@connorshea
Copy link
Contributor Author

Thank you!

@connorshea connorshea deleted the 2999-add-default-page-size branch May 31, 2022 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants