Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

Make pagination an option for FieldFunc #197

Merged
merged 3 commits into from
Nov 16, 2018
Merged

Make pagination an option for FieldFunc #197

merged 3 commits into from
Nov 16, 2018

Conversation

berfarah
Copy link
Contributor

Don't require PaginateFieldFunc for creating field funcs. Rather, FieldFunc takes in a Paginate option.

@berfarah berfarah requested review from stephen and willhug November 15, 2018 21:05
@coveralls
Copy link

coveralls commented Nov 15, 2018

Pull Request Test Coverage Report for Build 1205

  • 5 of 17 (29.41%) changed or added relevant lines in 3 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.07%) to 65.793%

Changes Missing Coverage Covered Lines Changed/Added Lines %
graphql/schemabuilder/pagination.go 0 3 0.0%
graphql/schemabuilder/types.go 4 7 57.14%
graphql/schemabuilder/reflect.go 1 7 14.29%
Files with Coverage Reduction New Missed Lines %
graphql/schemabuilder/reflect.go 2 73.38%
Totals Coverage Status
Change from base Build 1193: 0.07%
Covered Lines: 3566
Relevant Lines: 5420

💛 - Coveralls

Name: name,
Fn: f,
})
o.FieldFunc(name, f, Paginated)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uses the new API under the hood now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love it

@@ -914,21 +912,22 @@ func (sb *schemaBuilder) buildStruct(typ reflect.Type) error {
for _, name := range names {
method := methods[name]

if method.Paginated {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this having separate code paths for now


// NonNullable is an option that can be passed to a FieldFunc to indicate that
// its return value is required, even if the return value is a pointer type.
func NonNullable(m *method) {
var NonNullable fieldFuncOptionFunc = func(m *method) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a kinda cute pattern 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too cute

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a quick example in the commit message for what the more complicated case will look like is useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

Copy link

@willhug willhug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome! Can we add a changelog note?

graphql/schemabuilder/types.go Outdated Show resolved Hide resolved
@@ -85,6 +90,9 @@ func (s *Object) Key(f string) {
type method struct {
MarkedNonNullable bool
Fn interface{}

// Connection configuration
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? Is this meant as a header for the section?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - I can remove it for now if it's confusing

This is in preparation for some more complex options we will be
introducing as part of our pagination work.

eg:

    // thunder/graphql/...
    type PaginationSort map[string]interface{}

    // someone using thunder can pass in any option:
    schema.FieldFunc(ctx, getPaginatedResource, Pagination)

    schema.FieldFunc(ctx, getPaginatedResource, PaginationSort{
        "groupName": func(ctx, resource) string {
            return "theGroupName"
        }
    })

    // and doesn't have to do this:
    schema.FieldFunc(ctx, getPaginatedResource, PaginationSort{
        ...
    }.Option)
Copy link
Contributor

@stephen stephen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great

@berfarah berfarah merged commit 8c464f7 into master Nov 16, 2018
@berfarah berfarah deleted the bf/pagination branch November 16, 2018 17:48
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.

4 participants