You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+11-19
Original file line number
Diff line number
Diff line change
@@ -6,18 +6,6 @@ Performant, batched GraphQL queries from within the resolvers of a [`graphql-rub
6
6
7
7
## Snippet
8
8
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
-
deflogin
15
-
GitHubLoader.load_value("viewer", "login")
16
-
end
17
-
```
18
-
19
-
If you need error handling, post-processing, or complex queries:
20
-
21
9
```ruby
22
10
field :login, String, null:false, description:"The currently authenticated GitHub user's login."
23
11
@@ -32,29 +20,29 @@ def login
32
20
end
33
21
```
34
22
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
-
39
23
## 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.
41
25
42
26
This can be used to create GraphQL APIs that depend on data from other GraphQL APIs, either remote or local.
43
27
44
28
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.
45
29
46
30
You can think of it as a lightweight version of schema-stitching.
47
31
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
+
48
36
## How to use
49
37
First, you'll need to install the gem. Either do `gem install graphql-remote_loader` or add this to your Gemfile:
50
38
51
39
```
52
40
gem "graphql-remote_loader"
53
41
```
54
42
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.
56
44
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`.
58
46
59
47
Example:
60
48
@@ -75,6 +63,10 @@ This example uses [`graphql-client`](https://github.com/github/graphql-client).
75
63
76
64
With your loader setup, you can begin using `#load` or `#load_value` in your `graphql-ruby` resolvers.
77
65
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).
0 commit comments