graphql-dataloader-example

command module
v0.0.0-...-9ae4980 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2018 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

graphql-dataloader-example

An example project on how to use github.com/graphql-go/graphql with github.com/graph-gophers/dataloader to support batching to avoid n+1 queries.

Getting Started

To run the example:

go run main.go

Output:

2018/09/22 16:03:55 [GetCategoryBatchFn] batch size: 3
2018/09/22 16:03:55 [GetUserOrdersBatchFn] batch size: 1
2018/09/22 16:03:55 [GetProductsBatchFn] batch size: 1
2018/09/22 16:03:55 [GraphQL] result: {"data":{"categories":[{"id":1,"name":"name#1"},{"id":2,"name":"name#2"},{"id":3,"name":"name#3"}],"currentUser":{"firstName":"user#1 first name","id":1,"lastName":"user#1 last name","orders":[{"id":200,"products":[{"categories":[{"id":3,"name":"name#3"},{"id":1,"name":"name#1"},{"id":2,"name":"name#2"}],"id":100,"title":"product#100"}]}]}}}

GraphQL result pretty print using jq:


(graphql-dataloader-example)-> echo '{"data":{"categories":[{"id":1,"name":"name#1"},{"id":2,"name":"name#2"},{"id":3,"name":"name#3"}],"currentUser":{"firstName":"user#1 first name","id":1,"lastName":"user#1 last name","orders":[{"id":200,"products":[{"categories":[{"id":3,"name":"name#3"},{"id":1,"name":"name#1"},{"id":2,"name":"name#2"}],"id":100,"title":"product#100"}]}]}}}' | jq
{
  "data": {
    "categories": [
      {
        "id": 1,
        "name": "name#1"
      },
      {
        "id": 2,
        "name": "name#2"
      },
      {
        "id": 3,
        "name": "name#3"
      }
    ],
    "currentUser": {
      "firstName": "user#1 first name",
      "id": 1,
      "lastName": "user#1 last name",
      "orders": [
        {
          "id": 200,
          "products": [
            {
              "categories": [
                {
                  "id": 3,
                  "name": "name#3"
                },
                {
                  "id": 1,
                  "name": "name#1"
                },
                {
                  "id": 2,
                  "name": "name#2"
                }
              ],
              "id": 100,
              "title": "product#100"
            }
          ]
        }
      ]
    }
  }
}

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址