Skip to content

Commit 799c7b2

Browse files
author
Nathaniel Woodthorpe
authoredNov 24, 2018
Update README.md
1 parent 9f07a49 commit 799c7b2

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed
 

‎README.md

+11-19
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,6 @@ Performant, batched GraphQL queries from within the resolvers of a [`graphql-rub
66

77
## Snippet
88

9-
For default error handling(null if errors) and no post-processing:
10-
11-
```ruby
12-
field :login, String, null: true, description: "The currently authenticated GitHub user's login."
13-
14-
def login
15-
GitHubLoader.load_value("viewer", "login")
16-
end
17-
```
18-
19-
If you need error handling, post-processing, or complex queries:
20-
219
```ruby
2210
field :login, String, null: false, description: "The currently authenticated GitHub user's login."
2311

@@ -32,29 +20,29 @@ def login
3220
end
3321
```
3422

35-
## Full example
36-
37-
To see a working example of how `graphql-remote_loader` works, see the [complete, working example application](https://github.com/d12/graphql-remote_loader_example).
38-
3923
## Description
40-
`graphql-remote_loader` allows for querying GraphQL APIs from within resolvers of a [`graphql-ruby`](https://github.com/rmosolgo/graphql-ruby) API.
24+
`graphql-remote_loader` allows for querying GraphQL APIs from within resolvers of a [`graphql-ruby`](https://github.com/rmosolgo/graphql-ruby) API.
4125

4226
This can be used to create GraphQL APIs that depend on data from other GraphQL APIs, either remote or local.
4327

4428
A promise-based resolution strategy from Shopify's [`graphql-batch`](https://github.com/Shopify/graphql-batch) is used to batch all requested data into a single GraphQL query. Promises are fulfilled with only the data they requested.
4529

4630
You can think of it as a lightweight version of schema-stitching.
4731

32+
## Performance
33+
34+
Each `Loader#load` invocation does not send a GraphQL query to the remote. The Gem uses graphql-batch to collect all GraphQL queries together, then combines them and sends a single query to the upstream. The gem splits the response JSON up so that each promise is only resolved with data that it asked for.
35+
4836
## How to use
4937
First, you'll need to install the gem. Either do `gem install graphql-remote_loader` or add this to your Gemfile:
5038

5139
```
5240
gem "graphql-remote_loader"
5341
```
5442

55-
The gem provides a base loader `GraphQL::RemoteLoader::Loader` which does most of the heavy lifting. In order to remain client-agnostic, there's an unimplemented no-op that queries the external GraphQL API.
43+
The gem provides a base loader `GraphQL::RemoteLoader::Loader` which does most of the heavy lifting. In order to remain client-agnostic, there's an unimplemented no-op that takes a query string and queries the remote GraphQL API.
5644

57-
To use, create a new class that inherits from `GraphQL::RemoteLoader::Loader` and define `def query(query_string)`. The method takes a query String as input. The expected output is a response `Hash`, or some object that responds to `#to_h`.
45+
To use, create a new class that inherits from `GraphQL::RemoteLoader::Loader` and define `def query(query_string)`. The method takes a query String as input. The expected output is a response `Hash`, or an object that responds to `#to_h`.
5846

5947
Example:
6048

@@ -75,6 +63,10 @@ This example uses [`graphql-client`](https://github.com/github/graphql-client).
7563

7664
With your loader setup, you can begin using `#load` or `#load_value` in your `graphql-ruby` resolvers.
7765

66+
## Full example
67+
68+
To see a working example of how `graphql-remote_loader` works, see the [complete, working example application](https://github.com/d12/graphql-remote_loader_example).
69+
7870
## Running tests
7971

8072
```

0 commit comments

Comments
 (0)