Skip to content

Files

Latest commit

 

History

History
58 lines (45 loc) · 1.88 KB

README.md

File metadata and controls

58 lines (45 loc) · 1.88 KB

Documentation Actions Status Coverage Status

graphql-pagination-go

This library makes it easy to create paged fields for graphql-go. We currently have the following features:

  • Simple Pagination (data & count)
  • Separated data and count resolvers
  • Resolvers are executed only for requested fields

Example:

  fields := graphql.Fields{
    "languages": Paginated(&PaginatedField{
      Name: "Languages",
      Type: graphql.String,
      Args: nil,
      DataResolve: func(p graphql.ResolveParams) (i interface{}, e error) {
          return []string{"Go", "Javascript", "Ruby"}, nil
      },
      CountResolve: func(p graphql.ResolveParams) (i interface{}, e error) {
          return 3, nil
      },
    }),
  }
  rootQuery := graphql.ObjectConfig{Name: "RootQuery", Fields: fields}
  schemaConfig := graphql.SchemaConfig{Query: graphql.NewObject(rootQuery)}

Now you can query as below:

  query {
    languages {
      data
      count
    }
  }

Resolve only requested fields

In some datasources or databases like MongoDB, calling a count comes at an additional cost and is not always used. Thus, this library takes care of resolvers only of the required fields (data and / or count).

  query {
    languages {
      count
    }
  }

As you can see in example above, only the CountResolve you be called and the query will not have the cost of calling DataResolve because data was not requested.