Skip to content
This repository was archived by the owner on Oct 17, 2020. It is now read-only.

Commit f751b15

Browse files
committed
fix(comments): pr comments
1 parent 6128585 commit f751b15

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

content/GraphQL-Binding/01-Overview.md

+17-16
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,36 @@
44

55
## Description
66

7-
A simple way to interact with a GraphQL API is to make an HTTP `POST` request to
8-
a GraphQL server:
9-
10-
Using JavaScript's `fetch`:
7+
The most straightforward way to interact with a GraphQL API is to make an HTTP POST request to a GraphQL server, for example using JavaScript's fetch:
118

129
```js
1310
require('isomorphic-fetch');
1411

12+
const query = `
13+
query {
14+
posts {
15+
title
16+
}
17+
}
18+
`;
19+
1520
fetch('https://1jzxrj179.lp.gql.zone/graphql', {
1621
method: 'POST',
1722
headers: { 'Content-Type': 'application/json' },
18-
body: JSON.stringify({ query: '{ posts { title } }' }),
23+
body: JSON.stringify({ query }),
1924
})
2025
.then(res => res.json())
2126
.then(res => console.log(res.data));
2227
```
2328

2429
GraphQL bindings provide a convenient interface for interacting with a GraphQL
2530
API with your favorite programming language. Instead of sending queries as strings
26-
like we demonstrated above, you can invoke a binding function which constructs GraphQL requests and sends it to a GraphQL server for you.
31+
like we demonstrated above, you can invoke a binding function which constructs a GraphQL request and sends it to a GraphQL server for you.
2732

28-
The API of a GraphQL binding is very flexible, making them the perfect tool for
29-
use cases like: accessing GraphQL APIs from scripts or webhooks, `service-to-service` communication in a microservice architecture, or building
30-
GraphQL API gateways.
33+
Bindings can be useful in combination with statically
34+
typed languages that IDEs and code editors to leverage tooling that can be configured in such a way that they validate GraphQL requests at compile time or even provide auto-completion for an advanced developer experience.
3135

32-
To take it even further, bindings can be useful in combination with statically
33-
typed languages that IDEs and code editors to leverage tooling that can be configuredin such a way that they validate GraphQL requests at compile time or even provide auto-completion for an advanced developer experience.
34-
35-
A perspective that onboards both new engineers and seasoned teams is to think of GraphQL bindings as an auto-generated SDK (software development kit) for GraphQL APIs.
36+
A perspective that onboards engineers is to think of GraphQL bindings as an auto-generated [SDK](https://en.wikipedia.org/wiki/Software_development_kit) for GraphQL APIs.
3637

3738
![](../../assets/bindings.png)
3839

@@ -73,13 +74,13 @@ Now install the package `graphql-binding-example` through NPM or yarn:
7374

7475
```sh
7576
yarn add graphql-binding-example
76-
77+
# or
7778
npm install graphql-binding-example
7879
```
7980

80-
To see the code for this example binding, you can view that [here](https://github.com/graphql-binding/graphql-binding-example-service). You can learn how to create your own binding [here](./04-Creating-your-own-Binding.md)).
81+
> You can find code for the `graphql-binding-example` [here](https://github.com/graphql-binding/graphql-binding-example-service). Learn how to create your own GraphQL binding [here](https://github.com/prisma/oss.prisma.io/blob/GraphQLBinding/content/GraphQL-Binding/04-Creating-your-own-Binding.md).
8182
82-
Here are three scenarios how this binding could be used:
83+
In the following, we'll discuss three scenarios illustrating how the example binding can be used.
8384

8485
### 1. Usage in a simple Node script
8586

content/GraphQL-Binding/02-API-Reference.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const before = () => console.log(`Sending a request to the GraphQL API ...`)
8383
const delegate = new Delegate({ schema, before })
8484
```
8585

86-
In this example, we create a new instance of the `Delegate` class. First we take our remote endpoint and make an `HttpLink` which creates an `HTTP` transport for this binding. This means all requests to our GraphQL API are transported via `HTTP`. Next we make a `remote` schema, meaning the schema and it's API's exist on a remote server. The `before` function is unique to the `Delegate` class. Use this to execute code _prior_ to a GraphQL request.
86+
In this example, we create a new instance of the `Delegate` class. First we take our remote endpoint and make an `HttpLink` which creates an HTTP transport for this binding. This means all requests to our GraphQL API are transported via HTTP. Next we make a remote schema, meaning the schema and it's API's exist on a remote server. The `before` function is unique to the `Delegate` class. Use this to execute code _prior_ to a GraphQL request.
8787

8888
### Methods
8989

@@ -93,7 +93,7 @@ In this example, we create a new instance of the `Delegate` class. First we take
9393
before: () => void
9494
```
9595

96-
A function that's executed _before_ a query, mutation or subscription request is sent to the API. This applies to [`request`](#request), [`delegate`](delegate) and [`delegateSubscription`](#delegateSubscription). This lets you for example modify the `link` that's used to reach the API, implement analytics features or add a logging statement before each API request.
96+
A function that's executed _before_ a query, mutation or subscription request is sent to the API. This applies to [`request`](#request), [`delegate`](#delegate) and [`delegateSubscription`](#delegateSubscription). This lets you for example modify the link that's used to reach the API, implement analytics features or add a logging statement before each API request.
9797

9898
#### `request`
9999

@@ -148,7 +148,7 @@ delegate(operation: QueryOrMutation, fieldName: string, args: {
148148
- `transforms` (optional): Allows to perform transformations on the `info` object or the `schema`.
149149
- `context` (optional): Allows to pass additional information to the GraphQL API that's abstracted.
150150

151-
**Example: Hardcode the selection set as a string:**
151+
**Example: Hardcode the selection set as a string**
152152

153153
```js
154154
const args = { name: `Rowan` }
@@ -177,7 +177,7 @@ delegateSubscription(fieldName: string, args?: {
177177
}, infoOrQuery?: GraphQLResolveInfo | string, options?: Options): Promise<AsyncIterator<any>>;
178178
```
179179

180-
`delegateSubscription` allows you to [delegate](https://blog.graph.cool/graphql-schema-stitching-explained-schema-delegation-4c6caf468405) the execution of a subscription to the GraphQL API that's abstracted by this binding. This function is often used when building a GraphQL gateway layer.
180+
`delegateSubscription` allows you to [delegate](https://www.prisma.io/blog/graphql-schema-stitching-explained-schema-delegation-4c6caf468405/) the execution of a subscription to the GraphQL API that's abstracted by this binding. This function is often used when building a GraphQL gateway layer.
181181

182182
##### Properties
183183

@@ -188,7 +188,7 @@ delegateSubscription(fieldName: string, args?: {
188188
- `transforms` (optional): Allows to perform transformations on the `info` object or the `schema`.
189189
- `context` (optional): Allows to pass additional information to the GraphQL API that's abstracted.
190190

191-
**Example: Selection set based on the `info` object inside a GraphQL resolver**:
191+
**Example: Selection set based on the `info` object inside a GraphQL resolver**
192192

193193
```js
194194
const Subscription = {
@@ -206,7 +206,7 @@ const Subscription = {
206206
}
207207
```
208208

209-
> [Learn more about the `info` object.](https://blog.graph.cool/graphql-server-basics-demystifying-the-info-argument-in-graphql-resolvers-6f26249f613a)
209+
> [Learn more about the `info` object.](https://www.prisma.io/blog/graphql-server-basics-demystifying-the-info-argument-in-graphql-resolvers-6f26249f613a)
210210
211211
#### `getAbstractResolvers`
212212

@@ -266,16 +266,16 @@ The `Options` type has two fields:
266266

267267
### Transforms
268268

269-
Schema transforms are a tool for making modified copies of GraphQLSchema objects, while preserving the possibility of delegating back to original schema.
269+
Schema transforms are a tool for making modified copies of `GraphQLSchema` objects, while preserving the possibility of delegating back to original schema.
270270

271-
Transforms are useful when working with remote schemas, building GraphQL gateways, and working with GraphQL microservices.
271+
Transforms are useful when working with [remote schemas](https://www.prisma.io/blog/how-do-graphql-remote-schemas-work-7118237c89d7/), building GraphQL gateways, and working with GraphQL microservices.
272272

273273
More information on `transforms` can be found [here](https://www.apollographql.com/docs/graphql-tools/schema-transforms.html)
274274

275275

276276
### Context
277277

278-
In GraphQL APIs, context can be provided to every resolver that holds important contextual information like the currently logged in user, or access to a database. Utilizing context is extremely crucial for bindings to GraphQL servers that may inherit context from a HTTP request or encode user-specific information to the request.
278+
In GraphQL APIs, `context` can be provided to every resolver that holds important contextual information like the currently logged in user, or access to a database. Utilizing `context` is extremely crucial for bindings to GraphQL servers that may inherit data from HTTP request headers or encode user-specific information to the request. You then can utilize this in each of your resolvers.
279279

280280
In the example below we pass through context from the incoming GraphQL resolver to the underlying binding.
281281

0 commit comments

Comments
 (0)