Skip to content

Commit 8b9b595

Browse files
committed
Add apollo link docs
1 parent faa3cb0 commit 8b9b595

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

guides/javascript_client/sync.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ JavaScript support for GraphQL projects using [graphql-pro](http://graphql.pro)'
1212
- [`sync` CLI](#sync-utility)
1313
- [Relay support](#use-with-relay)
1414
- [Apollo Client support](#use-with-apollo-client)
15+
- [Apollo Link support](#use-with-apollo-link)
1516
- [Plain JS support](#use-with-plain-javascript)
1617
- [Authorization](#authorization)
1718

@@ -113,6 +114,47 @@ if (process.env.NODE_ENV === "production") {
113114

114115
Now, the middleware will replace query strings with `operationId`s.
115116

117+
## Use with Apollo Link
118+
119+
Use the `--path` option to point at your `.graphql` files:
120+
121+
```
122+
$ graphql-ruby-client sync --path=src/graphql/ --url=...
123+
```
124+
125+
Then, load the generated module and add its `.apolloLink` to your Apollo Link:
126+
127+
```js
128+
// load the generated module
129+
var OperationStoreClient = require("./OperationStoreClient")
130+
131+
// Integrate the link to another link:
132+
const link = ApolloLink.from([
133+
authLink,
134+
OperationStoreClient.apolloLink,
135+
httpLink,
136+
])
137+
138+
// Create a client
139+
const client = new ApolloClient({
140+
link: link,
141+
cache: new InMemoryCache(),
142+
});
143+
```
144+
145+
__Update the controller__: Apollo Link supports extra parameters _nested_ as `params[:extensions][:operationId]`, so update your controller to add that param to context:
146+
147+
```ruby
148+
# app/controllers/graphql_controller.rb
149+
context = {
150+
# ...
151+
# Support Apollo Link:
152+
operation_id: params[:extensions][:operationId]
153+
}
154+
```
155+
156+
Now, `context[:operation_id]` will be used to fetch a query from the database.
157+
116158
## Use with plain JavaScript
117159

118160
`OperationStoreClient.getOperationId` takes an operation name as input and returns the server-side alias for that operation:

guides/operation_store/getting_started.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,10 @@ Add `operation_id:` to your GraphQL context:
123123
```ruby
124124
# app/controllers/graphql_controller.rb
125125
context = {
126-
# ...
126+
# Relay / Apollo 1.x:
127127
operation_id: params[:operationId]
128+
# Or, Apollo Link:
129+
# operation_id: params[:extensions][:operationId]
128130
}
129131

130132
MySchema.execute(
@@ -133,7 +135,7 @@ MySchema.execute(
133135
)
134136
```
135137

136-
`OperationStore` will use `stored_operation` to fetch the operation from the database.
138+
`OperationStore` will use `operation_id` to fetch the operation from the database.
137139

138140
See {% internal_link "Server Management","/operation_store/server_management" %} for details about rejecting GraphQL from `params[:query]`.
139141

0 commit comments

Comments
 (0)