@graphql-codegen/testing 5.0.1 → 5.0.2-alpha-20260913005636-8f7ee082fd39a8b6d0d4185609a4271b894394c9
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/cjs/mock-graphql-server.js +11 -33
- package/esm/mock-graphql-server.js +11 -33
- package/package.json +8 -5
|
@@ -2,48 +2,26 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mockGraphQLServer = mockGraphQLServer;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const graphql_yoga_1 = require("graphql-yoga");
|
|
6
6
|
const nock_1 = tslib_1.__importDefault(require("nock"));
|
|
7
7
|
function mockGraphQLServer({ schema, host, path, intercept, method = 'POST', }) {
|
|
8
|
+
const yoga = (0, graphql_yoga_1.createYoga)({ schema, logging: false });
|
|
8
9
|
const handler = async function (uri, body) {
|
|
9
10
|
if (intercept) {
|
|
10
11
|
intercept(this);
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
for (const [key, val] of uriObj.searchParams.entries()) {
|
|
15
|
-
queryObj[key] = val;
|
|
16
|
-
}
|
|
17
|
-
// Create a generic Request object that can be consumed by Graphql Helix's API
|
|
18
|
-
const request = {
|
|
19
|
-
body,
|
|
20
|
-
headers: this.req.headers,
|
|
13
|
+
// Create a generic Request object that can be consumed by Yoga's fetch API
|
|
14
|
+
const request = new Request(new URL(host + uri), {
|
|
21
15
|
method,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// Extract the GraphQL parameters from the request
|
|
25
|
-
const { operationName, query, variables } = (0, graphql_helix_1.getGraphQLParameters)(request);
|
|
26
|
-
// Validate and execute the query
|
|
27
|
-
const result = await (0, graphql_helix_1.processRequest)({
|
|
28
|
-
operationName,
|
|
29
|
-
query,
|
|
30
|
-
variables,
|
|
31
|
-
request,
|
|
32
|
-
schema,
|
|
16
|
+
headers: this.req.headers,
|
|
17
|
+
body: method === 'GET' ? undefined : JSON.stringify(body),
|
|
33
18
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (result.type === 'RESPONSE') {
|
|
39
|
-
const headers = {};
|
|
40
|
-
// We set the provided status and headers and just the send the payload back to the client
|
|
41
|
-
for (const { name, value } of result.headers) {
|
|
42
|
-
headers[name] = value;
|
|
43
|
-
}
|
|
44
|
-
return [result.status, result.payload, headers];
|
|
19
|
+
const response = await yoga.fetch(request);
|
|
20
|
+
const headers = {};
|
|
21
|
+
for (const [name, value] of response.headers) {
|
|
22
|
+
headers[name] = value;
|
|
45
23
|
}
|
|
46
|
-
return [
|
|
24
|
+
return [response.status, await response.json(), headers];
|
|
47
25
|
};
|
|
48
26
|
switch (method) {
|
|
49
27
|
case 'GET':
|
|
@@ -1,45 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createYoga } from 'graphql-yoga';
|
|
2
2
|
import nock from 'nock';
|
|
3
3
|
export function mockGraphQLServer({ schema, host, path, intercept, method = 'POST', }) {
|
|
4
|
+
const yoga = createYoga({ schema, logging: false });
|
|
4
5
|
const handler = async function (uri, body) {
|
|
5
6
|
if (intercept) {
|
|
6
7
|
intercept(this);
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
for (const [key, val] of uriObj.searchParams.entries()) {
|
|
11
|
-
queryObj[key] = val;
|
|
12
|
-
}
|
|
13
|
-
// Create a generic Request object that can be consumed by Graphql Helix's API
|
|
14
|
-
const request = {
|
|
15
|
-
body,
|
|
16
|
-
headers: this.req.headers,
|
|
9
|
+
// Create a generic Request object that can be consumed by Yoga's fetch API
|
|
10
|
+
const request = new Request(new URL(host + uri), {
|
|
17
11
|
method,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// Extract the GraphQL parameters from the request
|
|
21
|
-
const { operationName, query, variables } = getGraphQLParameters(request);
|
|
22
|
-
// Validate and execute the query
|
|
23
|
-
const result = await processGraphQLHelixRequest({
|
|
24
|
-
operationName,
|
|
25
|
-
query,
|
|
26
|
-
variables,
|
|
27
|
-
request,
|
|
28
|
-
schema,
|
|
12
|
+
headers: this.req.headers,
|
|
13
|
+
body: method === 'GET' ? undefined : JSON.stringify(body),
|
|
29
14
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (result.type === 'RESPONSE') {
|
|
35
|
-
const headers = {};
|
|
36
|
-
// We set the provided status and headers and just the send the payload back to the client
|
|
37
|
-
for (const { name, value } of result.headers) {
|
|
38
|
-
headers[name] = value;
|
|
39
|
-
}
|
|
40
|
-
return [result.status, result.payload, headers];
|
|
15
|
+
const response = await yoga.fetch(request);
|
|
16
|
+
const headers = {};
|
|
17
|
+
for (const [name, value] of response.headers) {
|
|
18
|
+
headers[name] = value;
|
|
41
19
|
}
|
|
42
|
-
return [
|
|
20
|
+
return [response.status, await response.json(), headers];
|
|
43
21
|
};
|
|
44
22
|
switch (method) {
|
|
45
23
|
case 'GET':
|
package/package.json
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/testing",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.2-alpha-20260913005636-8f7ee082fd39a8b6d0d4185609a4271b894394c9",
|
|
4
4
|
"description": "GraphQL Codegen Testing Utils",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"jest-diff": "^23.0.0 || ^24.0.0 || ^25.0.0 || ^26.0.0 || ^27.0.0 || ^28.0.0 || ^29.0.0 || ^30.0.0",
|
|
7
7
|
"typescript": ">=3.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
+
"@graphql-codegen/plugin-helpers": "^7.3.0",
|
|
10
11
|
"common-tags": "^1.8.0",
|
|
11
|
-
"graphql-
|
|
12
|
+
"graphql-yoga": "^5.21.0",
|
|
12
13
|
"lz-string": "^1.4.4",
|
|
13
14
|
"nock": "^14.0.0",
|
|
14
|
-
"tslib": "^2.8.0"
|
|
15
|
-
|
|
15
|
+
"tslib": "^2.8.0"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git@github.com:dotansimha/graphql-code-generator.git"
|
|
16
20
|
},
|
|
17
|
-
"repository": "git@github.com:dotansimha/graphql-code-generator.git",
|
|
18
21
|
"homepage": "https://github.com/dotansimha/graphql-code-generator#readme",
|
|
19
22
|
"author": "Dotan Simha <dotansimha@gmail.com>",
|
|
20
23
|
"license": "MIT",
|