Skip to content

Commit ae8ea29

Browse files
committed
feat(handler): Expose getAcceptableMediaType and makeResponse for increased modularity
1 parent 17c8007 commit ae8ea29

File tree

2 files changed

+177
-151
lines changed

2 files changed

+177
-151
lines changed

docs/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ graphql-http
2222

2323
### Type Aliases
2424

25+
- [AcceptableMediaType](README.md#acceptablemediatype)
2526
- [ExecutionContext](README.md#executioncontext)
2627
- [Handler](README.md#handler)
2728
- [Response](README.md#response)
@@ -32,7 +33,9 @@ graphql-http
3233

3334
- [createClient](README.md#createclient)
3435
- [createHandler](README.md#createhandler)
36+
- [getAcceptableMediaType](README.md#getacceptablemediatype)
3537
- [isResponse](README.md#isresponse)
38+
- [makeResponse](README.md#makeresponse)
3639

3740
## Client
3841

@@ -99,6 +102,14 @@ val is Response
99102

100103
## Server
101104

105+
### AcceptableMediaType
106+
107+
Ƭ **AcceptableMediaType**: ``"application/graphql+json"`` \| ``"application/json"``
108+
109+
Request's Media-Type that the server accepts.
110+
111+
___
112+
102113
### ExecutionContext
103114

104115
Ƭ **ExecutionContext**: `object` \| `symbol` \| `number` \| `string` \| `boolean` \| `undefined` \| ``null``
@@ -216,3 +227,47 @@ console.log('Listening to port 4000');
216227
#### Returns
217228

218229
[`Handler`](README.md#handler)<`RawRequest`\>
230+
231+
___
232+
233+
### getAcceptableMediaType
234+
235+
**getAcceptableMediaType**(`acceptHeader`): [`AcceptableMediaType`](README.md#acceptablemediatype) \| ``null``
236+
237+
Inspects the request and detects the appropriate/acceptable Media-Type
238+
looking at the `Accept` header while complying with the GraphQL over HTTP Protocol.
239+
240+
#### Parameters
241+
242+
| Name | Type |
243+
| :------ | :------ |
244+
| `acceptHeader` | `undefined` \| ``null`` \| `string` |
245+
246+
#### Returns
247+
248+
[`AcceptableMediaType`](README.md#acceptablemediatype) \| ``null``
249+
250+
___
251+
252+
### makeResponse
253+
254+
**makeResponse**(`resultOrErrors`, `acceptedMediaType`): [`Response`](README.md#response)
255+
256+
Creates an appropriate GraphQL over HTTP response following the provided arguments.
257+
258+
If the first argument is an `ExecutionResult`, the operation will be treated as "successful".
259+
260+
If the first argument is a `GraphQLError` (or an array of), the operation will be treated as invalid
261+
and the response will be constructed with the help of `acceptedMediaType` complying with
262+
the GraphQL over HTTP Protocol.
263+
264+
#### Parameters
265+
266+
| Name | Type |
267+
| :------ | :------ |
268+
| `resultOrErrors` | readonly `GraphQLError`[] \| `Readonly`<`ExecutionResult`<`ObjMap`<`unknown`\>, `ObjMap`<`unknown`\>\>\> \| `Readonly`<`GraphQLError`\> |
269+
| `acceptedMediaType` | [`AcceptableMediaType`](README.md#acceptablemediatype) |
270+
271+
#### Returns
272+
273+
[`Response`](README.md#response)

0 commit comments

Comments
 (0)