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
{{ message }}
This repository was archived by the owner on Oct 17, 2020. It is now read-only.
Copy file name to clipboardExpand all lines: content/GraphQL-Binding/01-Overview.md
+17-16
Original file line number
Diff line number
Diff line change
@@ -4,35 +4,36 @@
4
4
5
5
## Description
6
6
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:
11
8
12
9
```js
13
10
require('isomorphic-fetch');
14
11
12
+
constquery=`
13
+
query {
14
+
posts {
15
+
title
16
+
}
17
+
}
18
+
`;
19
+
15
20
fetch('https://1jzxrj179.lp.gql.zone/graphql', {
16
21
method:'POST',
17
22
headers: { 'Content-Type':'application/json' },
18
-
body:JSON.stringify({ query:'{ posts { title } }' }),
23
+
body:JSON.stringify({ query }),
19
24
})
20
25
.then(res=>res.json())
21
26
.then(res=>console.log(res.data));
22
27
```
23
28
24
29
GraphQL bindings provide a convenient interface for interacting with a GraphQL
25
30
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.
27
32
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.
31
35
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.
36
37
37
38

38
39
@@ -73,13 +74,13 @@ Now install the package `graphql-binding-example` through NPM or yarn:
73
74
74
75
```sh
75
76
yarnaddgraphql-binding-example
76
-
77
+
# or
77
78
npminstallgraphql-binding-example
78
79
```
79
80
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).
81
82
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.
Copy file name to clipboardExpand all lines: content/GraphQL-Binding/02-API-Reference.md
+9-9
Original file line number
Diff line number
Diff line change
@@ -83,7 +83,7 @@ const before = () => console.log(`Sending a request to the GraphQL API ...`)
83
83
constdelegate=newDelegate({ schema, before })
84
84
```
85
85
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.
87
87
88
88
### Methods
89
89
@@ -93,7 +93,7 @@ In this example, we create a new instance of the `Delegate` class. First we take
93
93
before: () =>void
94
94
```
95
95
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.
`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.
-`transforms` (optional): Allows to perform transformations on the `info` object or the `schema`.
189
189
-`context` (optional): Allows to pass additional information to the GraphQL API that's abstracted.
190
190
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**
192
192
193
193
```js
194
194
constSubscription= {
@@ -206,7 +206,7 @@ const Subscription = {
206
206
}
207
207
```
208
208
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)
210
210
211
211
#### `getAbstractResolvers`
212
212
@@ -266,16 +266,16 @@ The `Options` type has two fields:
266
266
267
267
### Transforms
268
268
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.
270
270
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.
272
272
273
273
More information on `transforms` can be found [here](https://www.apollographql.com/docs/graphql-tools/schema-transforms.html)
274
274
275
275
276
276
### Context
277
277
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.
279
279
280
280
In the example below we pass through context from the incoming GraphQL resolver to the underlying binding.
0 commit comments