graphql-http 1.23.0 → 1.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/use/@netlify/functions.d.mts +1 -1
- package/lib/use/express.d.mts +32 -2
- package/lib/use/express.d.ts +32 -2
- package/lib/use/express.js +26 -2
- package/lib/use/express.mjs +26 -2
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../../handler
|
|
1
|
+
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../../handler.mjs';
|
|
2
2
|
import type { Handler as NetlifyHandler, HandlerEvent as NetlifyHandlerEvent, HandlerContext as NetlifyHandlerContext } from '@netlify/functions';
|
|
3
3
|
/**
|
|
4
4
|
* Handler options when using the netlify adapter
|
package/lib/use/express.d.mts
CHANGED
|
@@ -7,6 +7,12 @@ import { RequestParams } from '../common.mjs';
|
|
|
7
7
|
* @category Server/express
|
|
8
8
|
*/
|
|
9
9
|
export interface RequestContext {
|
|
10
|
+
/**
|
|
11
|
+
* The Express response object for the current request.
|
|
12
|
+
*
|
|
13
|
+
* This can be used to manipulate the HTTP response, for example to set
|
|
14
|
+
* response headers or cookies.
|
|
15
|
+
*/
|
|
10
16
|
res: Response;
|
|
11
17
|
}
|
|
12
18
|
/**
|
|
@@ -59,16 +65,40 @@ export type HandlerOptions<Context extends OperationContext = undefined> = RawHa
|
|
|
59
65
|
* Create a GraphQL over HTTP spec compliant request handler for
|
|
60
66
|
* the express framework.
|
|
61
67
|
*
|
|
68
|
+
* The Express response is available through `req.context.res`. To expose it
|
|
69
|
+
* to GraphQL resolvers, return it from the `context` option. This can be used
|
|
70
|
+
* to manipulate the HTTP response, for example to set response headers or
|
|
71
|
+
* cookies.
|
|
72
|
+
*
|
|
62
73
|
* ```js
|
|
63
74
|
* import express from 'express'; // yarn add express
|
|
64
75
|
* import { createHandler } from 'graphql-http/lib/use/express';
|
|
65
76
|
* import { schema } from './my-graphql-schema/index.mjs';
|
|
66
77
|
*
|
|
67
78
|
* const app = express();
|
|
68
|
-
*
|
|
79
|
+
*
|
|
80
|
+
* app.all(
|
|
81
|
+
* '/graphql',
|
|
82
|
+
* createHandler({
|
|
83
|
+
* schema,
|
|
84
|
+
* context(req) {
|
|
85
|
+
* return {
|
|
86
|
+
* res: req.context.res,
|
|
87
|
+
* };
|
|
88
|
+
* },
|
|
89
|
+
* }),
|
|
90
|
+
* );
|
|
69
91
|
*
|
|
70
92
|
* app.listen({ port: 4000 });
|
|
71
|
-
*
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* A resolver can then manipulate the response:
|
|
96
|
+
*
|
|
97
|
+
* ```js
|
|
98
|
+
* resolve(_, __, { res }) {
|
|
99
|
+
* res.setHeader('set-cookie', 'session=; Max-Age=0; Path=/');
|
|
100
|
+
* return true;
|
|
101
|
+
* }
|
|
72
102
|
* ```
|
|
73
103
|
*
|
|
74
104
|
* @category Server/express
|
package/lib/use/express.d.ts
CHANGED
|
@@ -7,6 +7,12 @@ import { RequestParams } from '../common';
|
|
|
7
7
|
* @category Server/express
|
|
8
8
|
*/
|
|
9
9
|
export interface RequestContext {
|
|
10
|
+
/**
|
|
11
|
+
* The Express response object for the current request.
|
|
12
|
+
*
|
|
13
|
+
* This can be used to manipulate the HTTP response, for example to set
|
|
14
|
+
* response headers or cookies.
|
|
15
|
+
*/
|
|
10
16
|
res: Response;
|
|
11
17
|
}
|
|
12
18
|
/**
|
|
@@ -59,16 +65,40 @@ export type HandlerOptions<Context extends OperationContext = undefined> = RawHa
|
|
|
59
65
|
* Create a GraphQL over HTTP spec compliant request handler for
|
|
60
66
|
* the express framework.
|
|
61
67
|
*
|
|
68
|
+
* The Express response is available through `req.context.res`. To expose it
|
|
69
|
+
* to GraphQL resolvers, return it from the `context` option. This can be used
|
|
70
|
+
* to manipulate the HTTP response, for example to set response headers or
|
|
71
|
+
* cookies.
|
|
72
|
+
*
|
|
62
73
|
* ```js
|
|
63
74
|
* import express from 'express'; // yarn add express
|
|
64
75
|
* import { createHandler } from 'graphql-http/lib/use/express';
|
|
65
76
|
* import { schema } from './my-graphql-schema';
|
|
66
77
|
*
|
|
67
78
|
* const app = express();
|
|
68
|
-
*
|
|
79
|
+
*
|
|
80
|
+
* app.all(
|
|
81
|
+
* '/graphql',
|
|
82
|
+
* createHandler({
|
|
83
|
+
* schema,
|
|
84
|
+
* context(req) {
|
|
85
|
+
* return {
|
|
86
|
+
* res: req.context.res,
|
|
87
|
+
* };
|
|
88
|
+
* },
|
|
89
|
+
* }),
|
|
90
|
+
* );
|
|
69
91
|
*
|
|
70
92
|
* app.listen({ port: 4000 });
|
|
71
|
-
*
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* A resolver can then manipulate the response:
|
|
96
|
+
*
|
|
97
|
+
* ```js
|
|
98
|
+
* resolve(_, __, { res }) {
|
|
99
|
+
* res.setHeader('set-cookie', 'session=; Max-Age=0; Path=/');
|
|
100
|
+
* return true;
|
|
101
|
+
* }
|
|
72
102
|
* ```
|
|
73
103
|
*
|
|
74
104
|
* @category Server/express
|
package/lib/use/express.js
CHANGED
|
@@ -56,16 +56,40 @@ exports.parseRequestParams = parseRequestParams;
|
|
|
56
56
|
* Create a GraphQL over HTTP spec compliant request handler for
|
|
57
57
|
* the express framework.
|
|
58
58
|
*
|
|
59
|
+
* The Express response is available through `req.context.res`. To expose it
|
|
60
|
+
* to GraphQL resolvers, return it from the `context` option. This can be used
|
|
61
|
+
* to manipulate the HTTP response, for example to set response headers or
|
|
62
|
+
* cookies.
|
|
63
|
+
*
|
|
59
64
|
* ```js
|
|
60
65
|
* import express from 'express'; // yarn add express
|
|
61
66
|
* import { createHandler } from 'graphql-http/lib/use/express';
|
|
62
67
|
* import { schema } from './my-graphql-schema';
|
|
63
68
|
*
|
|
64
69
|
* const app = express();
|
|
65
|
-
*
|
|
70
|
+
*
|
|
71
|
+
* app.all(
|
|
72
|
+
* '/graphql',
|
|
73
|
+
* createHandler({
|
|
74
|
+
* schema,
|
|
75
|
+
* context(req) {
|
|
76
|
+
* return {
|
|
77
|
+
* res: req.context.res,
|
|
78
|
+
* };
|
|
79
|
+
* },
|
|
80
|
+
* }),
|
|
81
|
+
* );
|
|
66
82
|
*
|
|
67
83
|
* app.listen({ port: 4000 });
|
|
68
|
-
*
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* A resolver can then manipulate the response:
|
|
87
|
+
*
|
|
88
|
+
* ```js
|
|
89
|
+
* resolve(_, __, { res }) {
|
|
90
|
+
* res.setHeader('set-cookie', 'session=; Max-Age=0; Path=/');
|
|
91
|
+
* return true;
|
|
92
|
+
* }
|
|
69
93
|
* ```
|
|
70
94
|
*
|
|
71
95
|
* @category Server/express
|
package/lib/use/express.mjs
CHANGED
|
@@ -52,16 +52,40 @@ export async function parseRequestParams(req, res) {
|
|
|
52
52
|
* Create a GraphQL over HTTP spec compliant request handler for
|
|
53
53
|
* the express framework.
|
|
54
54
|
*
|
|
55
|
+
* The Express response is available through `req.context.res`. To expose it
|
|
56
|
+
* to GraphQL resolvers, return it from the `context` option. This can be used
|
|
57
|
+
* to manipulate the HTTP response, for example to set response headers or
|
|
58
|
+
* cookies.
|
|
59
|
+
*
|
|
55
60
|
* ```js
|
|
56
61
|
* import express from 'express'; // yarn add express
|
|
57
62
|
* import { createHandler } from 'graphql-http/lib/use/express';
|
|
58
63
|
* import { schema } from './my-graphql-schema/index.mjs';
|
|
59
64
|
*
|
|
60
65
|
* const app = express();
|
|
61
|
-
*
|
|
66
|
+
*
|
|
67
|
+
* app.all(
|
|
68
|
+
* '/graphql',
|
|
69
|
+
* createHandler({
|
|
70
|
+
* schema,
|
|
71
|
+
* context(req) {
|
|
72
|
+
* return {
|
|
73
|
+
* res: req.context.res,
|
|
74
|
+
* };
|
|
75
|
+
* },
|
|
76
|
+
* }),
|
|
77
|
+
* );
|
|
62
78
|
*
|
|
63
79
|
* app.listen({ port: 4000 });
|
|
64
|
-
*
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* A resolver can then manipulate the response:
|
|
83
|
+
*
|
|
84
|
+
* ```js
|
|
85
|
+
* resolve(_, __, { res }) {
|
|
86
|
+
* res.setHeader('set-cookie', 'session=; Max-Age=0; Path=/');
|
|
87
|
+
* return true;
|
|
88
|
+
* }
|
|
65
89
|
* ```
|
|
66
90
|
*
|
|
67
91
|
* @category Server/express
|