@graphql-tools/links 8.3.0-alpha-ef64bfa7.0 → 8.3.0-alpha-b76ec274.0
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/AwaitVariablesLink.js +50 -0
- package/cjs/GraphQLUpload.js +27 -0
- package/cjs/createServerHttpLink.js +29 -0
- package/cjs/index.js +11 -0
- package/cjs/linkToExecutor.js +29 -0
- package/cjs/package.json +1 -0
- package/esm/AwaitVariablesLink.js +45 -0
- package/esm/GraphQLUpload.js +24 -0
- package/esm/createServerHttpLink.js +24 -0
- package/esm/index.js +4 -0
- package/esm/linkToExecutor.js +24 -0
- package/package.json +41 -19
- package/typings/AwaitVariablesLink.d.ts +6 -0
- package/{GraphQLUpload.d.ts → typings/GraphQLUpload.d.ts} +0 -0
- package/typings/createServerHttpLink.d.ts +2 -0
- package/typings/index.d.ts +4 -0
- package/typings/linkToExecutor.d.ts +3 -0
- package/AwaitVariablesLink.d.ts +0 -6
- package/README.md +0 -5
- package/createServerHttpLink.d.ts +0 -1
- package/index.d.ts +0 -4
- package/index.js +0 -121
- package/index.mjs +0 -112
- package/linkToExecutor.d.ts +0 -3
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.AwaitVariablesLink = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const apolloImport = tslib_1.__importStar(require("@apollo/client"));
|
|
7
|
+
const apollo = (_a = apolloImport === null || apolloImport === void 0 ? void 0 : apolloImport.default) !== null && _a !== void 0 ? _a : apolloImport;
|
|
8
|
+
function getFinalPromise(object) {
|
|
9
|
+
return Promise.resolve(object).then(resolvedObject => {
|
|
10
|
+
if (resolvedObject == null) {
|
|
11
|
+
return resolvedObject;
|
|
12
|
+
}
|
|
13
|
+
if (Array.isArray(resolvedObject)) {
|
|
14
|
+
return Promise.all(resolvedObject.map(o => getFinalPromise(o)));
|
|
15
|
+
}
|
|
16
|
+
else if (typeof resolvedObject === 'object') {
|
|
17
|
+
const keys = Object.keys(resolvedObject);
|
|
18
|
+
return Promise.all(keys.map(key => getFinalPromise(resolvedObject[key]))).then(awaitedValues => {
|
|
19
|
+
for (let i = 0; i < keys.length; i++) {
|
|
20
|
+
resolvedObject[keys[i]] = awaitedValues[i];
|
|
21
|
+
}
|
|
22
|
+
return resolvedObject;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return resolvedObject;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
class AwaitVariablesLink extends apollo.ApolloLink {
|
|
29
|
+
request(operation, forward) {
|
|
30
|
+
return new apollo.Observable(observer => {
|
|
31
|
+
let subscription;
|
|
32
|
+
getFinalPromise(operation.variables)
|
|
33
|
+
.then(resolvedVariables => {
|
|
34
|
+
operation.variables = resolvedVariables;
|
|
35
|
+
subscription = forward(operation).subscribe({
|
|
36
|
+
next: observer.next.bind(observer),
|
|
37
|
+
error: observer.error.bind(observer),
|
|
38
|
+
complete: observer.complete.bind(observer),
|
|
39
|
+
});
|
|
40
|
+
})
|
|
41
|
+
.catch(observer.error.bind(observer));
|
|
42
|
+
return () => {
|
|
43
|
+
if (subscription != null) {
|
|
44
|
+
subscription.unsubscribe();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.AwaitVariablesLink = AwaitVariablesLink;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphQLUpload = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const utils_1 = require("@graphql-tools/utils");
|
|
6
|
+
const GraphQLUpload = new graphql_1.GraphQLScalarType({
|
|
7
|
+
name: 'Upload',
|
|
8
|
+
description: 'The `Upload` scalar type represents a file upload.',
|
|
9
|
+
parseValue: (value) => {
|
|
10
|
+
if (value != null && 'promise' in value) {
|
|
11
|
+
// graphql-upload v10
|
|
12
|
+
return value.promise;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
// graphql-upload v9
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
// serialization requires to support schema stitching
|
|
20
|
+
serialize: value => value,
|
|
21
|
+
parseLiteral: ast => {
|
|
22
|
+
throw (0, utils_1.createGraphQLError)('Upload scalar literal unsupported', {
|
|
23
|
+
nodes: ast,
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
exports.GraphQLUpload = GraphQLUpload;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.createServerHttpLink = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const apolloImport = tslib_1.__importStar(require("@apollo/client"));
|
|
7
|
+
const apollo_upload_client_1 = require("apollo-upload-client");
|
|
8
|
+
const form_data_1 = tslib_1.__importDefault(require("form-data"));
|
|
9
|
+
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
|
|
10
|
+
const AwaitVariablesLink_js_1 = require("./AwaitVariablesLink.js");
|
|
11
|
+
const apollo = (_a = apolloImport === null || apolloImport === void 0 ? void 0 : apolloImport.default) !== null && _a !== void 0 ? _a : apolloImport;
|
|
12
|
+
const createServerHttpLink = (options) => apollo.concat(new AwaitVariablesLink_js_1.AwaitVariablesLink(), (0, apollo_upload_client_1.createUploadLink)({
|
|
13
|
+
...options,
|
|
14
|
+
fetch: node_fetch_1.default,
|
|
15
|
+
FormData: form_data_1.default,
|
|
16
|
+
isExtractableFile: (value) => (0, apollo_upload_client_1.isExtractableFile)(value) || (value === null || value === void 0 ? void 0 : value.createReadStream),
|
|
17
|
+
formDataAppendFile: (form, index, file) => {
|
|
18
|
+
if (file.createReadStream != null) {
|
|
19
|
+
form.append(index, file.createReadStream(), {
|
|
20
|
+
filename: file.filename,
|
|
21
|
+
contentType: file.mimetype,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
(0, apollo_upload_client_1.formDataAppendFile)(form, index, file);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
}));
|
|
29
|
+
exports.createServerHttpLink = createServerHttpLink;
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphQLUpload = exports.linkToExecutor = exports.AwaitVariablesLink = exports.createServerHttpLink = void 0;
|
|
4
|
+
var createServerHttpLink_js_1 = require("./createServerHttpLink.js");
|
|
5
|
+
Object.defineProperty(exports, "createServerHttpLink", { enumerable: true, get: function () { return createServerHttpLink_js_1.createServerHttpLink; } });
|
|
6
|
+
var AwaitVariablesLink_js_1 = require("./AwaitVariablesLink.js");
|
|
7
|
+
Object.defineProperty(exports, "AwaitVariablesLink", { enumerable: true, get: function () { return AwaitVariablesLink_js_1.AwaitVariablesLink; } });
|
|
8
|
+
var linkToExecutor_js_1 = require("./linkToExecutor.js");
|
|
9
|
+
Object.defineProperty(exports, "linkToExecutor", { enumerable: true, get: function () { return linkToExecutor_js_1.linkToExecutor; } });
|
|
10
|
+
var GraphQLUpload_js_1 = require("./GraphQLUpload.js");
|
|
11
|
+
Object.defineProperty(exports, "GraphQLUpload", { enumerable: true, get: function () { return GraphQLUpload_js_1.GraphQLUpload; } });
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.linkToExecutor = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const apolloImport = tslib_1.__importStar(require("@apollo/client"));
|
|
7
|
+
const utils_1 = require("@graphql-tools/utils");
|
|
8
|
+
const apollo = (_a = apolloImport === null || apolloImport === void 0 ? void 0 : apolloImport.default) !== null && _a !== void 0 ? _a : apolloImport;
|
|
9
|
+
function linkToExecutor(link) {
|
|
10
|
+
return function executorFromLink(request) {
|
|
11
|
+
const observable = apollo.execute(link, {
|
|
12
|
+
query: request.document,
|
|
13
|
+
operationName: request.operationName,
|
|
14
|
+
variables: request.variables,
|
|
15
|
+
context: {
|
|
16
|
+
graphqlContext: request.context,
|
|
17
|
+
graphqlResolveInfo: request.info,
|
|
18
|
+
clientAwareness: {},
|
|
19
|
+
},
|
|
20
|
+
extensions: request.extensions,
|
|
21
|
+
});
|
|
22
|
+
const operationAst = (0, utils_1.getOperationASTFromRequest)(request);
|
|
23
|
+
if (operationAst.operation === 'subscription') {
|
|
24
|
+
return (0, utils_1.observableToAsyncIterable)(observable);
|
|
25
|
+
}
|
|
26
|
+
return apollo.toPromise(observable);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
exports.linkToExecutor = linkToExecutor;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
import * as apolloImport from '@apollo/client';
|
|
3
|
+
const apollo = (_a = apolloImport === null || apolloImport === void 0 ? void 0 : apolloImport.default) !== null && _a !== void 0 ? _a : apolloImport;
|
|
4
|
+
function getFinalPromise(object) {
|
|
5
|
+
return Promise.resolve(object).then(resolvedObject => {
|
|
6
|
+
if (resolvedObject == null) {
|
|
7
|
+
return resolvedObject;
|
|
8
|
+
}
|
|
9
|
+
if (Array.isArray(resolvedObject)) {
|
|
10
|
+
return Promise.all(resolvedObject.map(o => getFinalPromise(o)));
|
|
11
|
+
}
|
|
12
|
+
else if (typeof resolvedObject === 'object') {
|
|
13
|
+
const keys = Object.keys(resolvedObject);
|
|
14
|
+
return Promise.all(keys.map(key => getFinalPromise(resolvedObject[key]))).then(awaitedValues => {
|
|
15
|
+
for (let i = 0; i < keys.length; i++) {
|
|
16
|
+
resolvedObject[keys[i]] = awaitedValues[i];
|
|
17
|
+
}
|
|
18
|
+
return resolvedObject;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return resolvedObject;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export class AwaitVariablesLink extends apollo.ApolloLink {
|
|
25
|
+
request(operation, forward) {
|
|
26
|
+
return new apollo.Observable(observer => {
|
|
27
|
+
let subscription;
|
|
28
|
+
getFinalPromise(operation.variables)
|
|
29
|
+
.then(resolvedVariables => {
|
|
30
|
+
operation.variables = resolvedVariables;
|
|
31
|
+
subscription = forward(operation).subscribe({
|
|
32
|
+
next: observer.next.bind(observer),
|
|
33
|
+
error: observer.error.bind(observer),
|
|
34
|
+
complete: observer.complete.bind(observer),
|
|
35
|
+
});
|
|
36
|
+
})
|
|
37
|
+
.catch(observer.error.bind(observer));
|
|
38
|
+
return () => {
|
|
39
|
+
if (subscription != null) {
|
|
40
|
+
subscription.unsubscribe();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { GraphQLScalarType } from 'graphql';
|
|
2
|
+
import { createGraphQLError } from '@graphql-tools/utils';
|
|
3
|
+
const GraphQLUpload = new GraphQLScalarType({
|
|
4
|
+
name: 'Upload',
|
|
5
|
+
description: 'The `Upload` scalar type represents a file upload.',
|
|
6
|
+
parseValue: (value) => {
|
|
7
|
+
if (value != null && 'promise' in value) {
|
|
8
|
+
// graphql-upload v10
|
|
9
|
+
return value.promise;
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
// graphql-upload v9
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
// serialization requires to support schema stitching
|
|
17
|
+
serialize: value => value,
|
|
18
|
+
parseLiteral: ast => {
|
|
19
|
+
throw createGraphQLError('Upload scalar literal unsupported', {
|
|
20
|
+
nodes: ast,
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
export { GraphQLUpload };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
import * as apolloImport from '@apollo/client';
|
|
3
|
+
import { createUploadLink, formDataAppendFile, isExtractableFile } from 'apollo-upload-client';
|
|
4
|
+
import FormData from 'form-data';
|
|
5
|
+
import fetch from 'node-fetch';
|
|
6
|
+
import { AwaitVariablesLink } from './AwaitVariablesLink.js';
|
|
7
|
+
const apollo = (_a = apolloImport === null || apolloImport === void 0 ? void 0 : apolloImport.default) !== null && _a !== void 0 ? _a : apolloImport;
|
|
8
|
+
export const createServerHttpLink = (options) => apollo.concat(new AwaitVariablesLink(), createUploadLink({
|
|
9
|
+
...options,
|
|
10
|
+
fetch,
|
|
11
|
+
FormData,
|
|
12
|
+
isExtractableFile: (value) => isExtractableFile(value) || (value === null || value === void 0 ? void 0 : value.createReadStream),
|
|
13
|
+
formDataAppendFile: (form, index, file) => {
|
|
14
|
+
if (file.createReadStream != null) {
|
|
15
|
+
form.append(index, file.createReadStream(), {
|
|
16
|
+
filename: file.filename,
|
|
17
|
+
contentType: file.mimetype,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
formDataAppendFile(form, index, file);
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
}));
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
import * as apolloImport from '@apollo/client';
|
|
3
|
+
import { observableToAsyncIterable, getOperationASTFromRequest, } from '@graphql-tools/utils';
|
|
4
|
+
const apollo = (_a = apolloImport === null || apolloImport === void 0 ? void 0 : apolloImport.default) !== null && _a !== void 0 ? _a : apolloImport;
|
|
5
|
+
export function linkToExecutor(link) {
|
|
6
|
+
return function executorFromLink(request) {
|
|
7
|
+
const observable = apollo.execute(link, {
|
|
8
|
+
query: request.document,
|
|
9
|
+
operationName: request.operationName,
|
|
10
|
+
variables: request.variables,
|
|
11
|
+
context: {
|
|
12
|
+
graphqlContext: request.context,
|
|
13
|
+
graphqlResolveInfo: request.info,
|
|
14
|
+
clientAwareness: {},
|
|
15
|
+
},
|
|
16
|
+
extensions: request.extensions,
|
|
17
|
+
});
|
|
18
|
+
const operationAst = getOperationASTFromRequest(request);
|
|
19
|
+
if (operationAst.operation === 'subscription') {
|
|
20
|
+
return observableToAsyncIterable(observable);
|
|
21
|
+
}
|
|
22
|
+
return apollo.toPromise(observable);
|
|
23
|
+
};
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/links",
|
|
3
|
-
"version": "8.3.0-alpha-
|
|
3
|
+
"version": "8.3.0-alpha-b76ec274.0",
|
|
4
4
|
"description": "A set of utils for faster development of GraphQL tools",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
7
|
-
"
|
|
8
|
-
"
|
|
7
|
+
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0",
|
|
8
|
+
"@apollo/client": "~3.2.5 || ~3.3.0 || ~3.4.0 || ~3.5.0 || ~3.6.0"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@graphql-tools/delegate": "
|
|
12
|
-
"@graphql-tools/utils": "
|
|
13
|
-
"apollo-upload-client": "
|
|
14
|
-
"
|
|
15
|
-
"form-data": "4.0.0",
|
|
16
|
-
"tslib": "
|
|
11
|
+
"@graphql-tools/delegate": "8.8.0-alpha-b76ec274.0",
|
|
12
|
+
"@graphql-tools/utils": "8.8.0-alpha-b76ec274.0",
|
|
13
|
+
"apollo-upload-client": "17.0.0",
|
|
14
|
+
"node-fetch": "^2.6.5",
|
|
15
|
+
"form-data": "^4.0.0",
|
|
16
|
+
"tslib": "^2.4.0"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
@@ -21,20 +21,42 @@
|
|
|
21
21
|
"directory": "packages/links"
|
|
22
22
|
},
|
|
23
23
|
"license": "MIT",
|
|
24
|
-
"main": "index.js",
|
|
25
|
-
"module": "index.
|
|
26
|
-
"typings": "index.d.ts",
|
|
24
|
+
"main": "cjs/index.js",
|
|
25
|
+
"module": "esm/index.js",
|
|
26
|
+
"typings": "typings/index.d.ts",
|
|
27
27
|
"typescript": {
|
|
28
|
-
"definition": "index.d.ts"
|
|
28
|
+
"definition": "typings/index.d.ts"
|
|
29
29
|
},
|
|
30
|
+
"type": "module",
|
|
30
31
|
"exports": {
|
|
31
32
|
".": {
|
|
32
|
-
"require":
|
|
33
|
-
|
|
33
|
+
"require": {
|
|
34
|
+
"types": "./typings/index.d.ts",
|
|
35
|
+
"default": "./cjs/index.js"
|
|
36
|
+
},
|
|
37
|
+
"import": {
|
|
38
|
+
"types": "./typings/index.d.ts",
|
|
39
|
+
"default": "./esm/index.js"
|
|
40
|
+
},
|
|
41
|
+
"default": {
|
|
42
|
+
"types": "./typings/index.d.ts",
|
|
43
|
+
"default": "./esm/index.js"
|
|
44
|
+
}
|
|
34
45
|
},
|
|
35
46
|
"./*": {
|
|
36
|
-
"require":
|
|
37
|
-
|
|
38
|
-
|
|
47
|
+
"require": {
|
|
48
|
+
"types": "./typings/*.d.ts",
|
|
49
|
+
"default": "./cjs/*.js"
|
|
50
|
+
},
|
|
51
|
+
"import": {
|
|
52
|
+
"types": "./typings/*.d.ts",
|
|
53
|
+
"default": "./esm/*.js"
|
|
54
|
+
},
|
|
55
|
+
"default": {
|
|
56
|
+
"types": "./typings/*.d.ts",
|
|
57
|
+
"default": "./esm/*.js"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"./package.json": "./package.json"
|
|
39
61
|
}
|
|
40
|
-
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as apolloImport from '@apollo/client';
|
|
2
|
+
declare const apollo: typeof apolloImport;
|
|
3
|
+
export declare class AwaitVariablesLink extends apollo.ApolloLink {
|
|
4
|
+
request(operation: apolloImport.Operation, forward: apolloImport.NextLink): apolloImport.Observable<apolloImport.FetchResult>;
|
|
5
|
+
}
|
|
6
|
+
export {};
|
|
File without changes
|
package/AwaitVariablesLink.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/// <reference types="zen-observable" />
|
|
2
|
-
import { ApolloLink, FetchResult, NextLink, Operation } from '@apollo/client/link/core';
|
|
3
|
-
import { Observable } from '@apollo/client/utilities';
|
|
4
|
-
export declare class AwaitVariablesLink extends ApolloLink {
|
|
5
|
-
request(operation: Operation, forward: NextLink): Observable<FetchResult>;
|
|
6
|
-
}
|
package/README.md
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
Check API Reference for more information about this package;
|
|
2
|
-
https://www.graphql-tools.com/docs/api/modules/links_src
|
|
3
|
-
|
|
4
|
-
You can also learn more about Apollo Links in Schema Wrapping in this chapter;
|
|
5
|
-
https://www.graphql-tools.com/docs/remote-schemas#wrapschemaschemaconfig
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const createServerHttpLink: (options: any) => import("@apollo/client/link/core").ApolloLink;
|
package/index.d.ts
DELETED
package/index.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
-
|
|
7
|
-
const core = require('@apollo/client/link/core');
|
|
8
|
-
const apolloUploadClient = require('apollo-upload-client');
|
|
9
|
-
const FormData = _interopDefault(require('form-data'));
|
|
10
|
-
const crossUndiciFetch = require('cross-undici-fetch');
|
|
11
|
-
const utilities = require('@apollo/client/utilities');
|
|
12
|
-
const core$1 = require('@apollo/client/core');
|
|
13
|
-
const utils = require('@graphql-tools/utils');
|
|
14
|
-
const graphql = require('graphql');
|
|
15
|
-
|
|
16
|
-
function getFinalPromise(object) {
|
|
17
|
-
return Promise.resolve(object).then(resolvedObject => {
|
|
18
|
-
if (resolvedObject == null) {
|
|
19
|
-
return resolvedObject;
|
|
20
|
-
}
|
|
21
|
-
if (Array.isArray(resolvedObject)) {
|
|
22
|
-
return Promise.all(resolvedObject.map(o => getFinalPromise(o)));
|
|
23
|
-
}
|
|
24
|
-
else if (typeof resolvedObject === 'object') {
|
|
25
|
-
const keys = Object.keys(resolvedObject);
|
|
26
|
-
return Promise.all(keys.map(key => getFinalPromise(resolvedObject[key]))).then(awaitedValues => {
|
|
27
|
-
for (let i = 0; i < keys.length; i++) {
|
|
28
|
-
resolvedObject[keys[i]] = awaitedValues[i];
|
|
29
|
-
}
|
|
30
|
-
return resolvedObject;
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
return resolvedObject;
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
class AwaitVariablesLink extends core.ApolloLink {
|
|
37
|
-
request(operation, forward) {
|
|
38
|
-
return new utilities.Observable(observer => {
|
|
39
|
-
let subscription;
|
|
40
|
-
getFinalPromise(operation.variables)
|
|
41
|
-
.then(resolvedVariables => {
|
|
42
|
-
operation.variables = resolvedVariables;
|
|
43
|
-
subscription = forward(operation).subscribe({
|
|
44
|
-
next: observer.next.bind(observer),
|
|
45
|
-
error: observer.error.bind(observer),
|
|
46
|
-
complete: observer.complete.bind(observer),
|
|
47
|
-
});
|
|
48
|
-
})
|
|
49
|
-
.catch(observer.error.bind(observer));
|
|
50
|
-
return () => {
|
|
51
|
-
if (subscription != null) {
|
|
52
|
-
subscription.unsubscribe();
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const createServerHttpLink = (options) => core.concat(new AwaitVariablesLink(), apolloUploadClient.createUploadLink({
|
|
60
|
-
...options,
|
|
61
|
-
fetch: crossUndiciFetch.fetch,
|
|
62
|
-
FormData,
|
|
63
|
-
isExtractableFile: (value) => apolloUploadClient.isExtractableFile(value) || (value === null || value === void 0 ? void 0 : value.createReadStream),
|
|
64
|
-
formDataAppendFile: (form, index, file) => {
|
|
65
|
-
if (file.createReadStream != null) {
|
|
66
|
-
form.append(index, file.createReadStream(), {
|
|
67
|
-
filename: file.filename,
|
|
68
|
-
contentType: file.mimetype,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
apolloUploadClient.formDataAppendFile(form, index, file);
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
}));
|
|
76
|
-
|
|
77
|
-
function linkToExecutor(link) {
|
|
78
|
-
return function executorFromLink(request) {
|
|
79
|
-
const observable = core.execute(link, {
|
|
80
|
-
query: request.document,
|
|
81
|
-
operationName: request.operationName,
|
|
82
|
-
variables: request.variables,
|
|
83
|
-
context: {
|
|
84
|
-
graphqlContext: request.context,
|
|
85
|
-
graphqlResolveInfo: request.info,
|
|
86
|
-
clientAwareness: {},
|
|
87
|
-
},
|
|
88
|
-
extensions: request.extensions,
|
|
89
|
-
});
|
|
90
|
-
const operationAst = utils.getOperationASTFromRequest(request);
|
|
91
|
-
if (operationAst.operation === 'subscription') {
|
|
92
|
-
return utils.observableToAsyncIterable(observable);
|
|
93
|
-
}
|
|
94
|
-
return core$1.toPromise(observable);
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const GraphQLUpload = new graphql.GraphQLScalarType({
|
|
99
|
-
name: 'Upload',
|
|
100
|
-
description: 'The `Upload` scalar type represents a file upload.',
|
|
101
|
-
parseValue: (value) => {
|
|
102
|
-
if (value != null && 'promise' in value) {
|
|
103
|
-
// graphql-upload v10
|
|
104
|
-
return value.promise;
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
// graphql-upload v9
|
|
108
|
-
return value;
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
// serialization requires to support schema stitching
|
|
112
|
-
serialize: value => value,
|
|
113
|
-
parseLiteral: ast => {
|
|
114
|
-
throw new graphql.GraphQLError('Upload literal unsupported.', ast);
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
exports.AwaitVariablesLink = AwaitVariablesLink;
|
|
119
|
-
exports.GraphQLUpload = GraphQLUpload;
|
|
120
|
-
exports.createServerHttpLink = createServerHttpLink;
|
|
121
|
-
exports.linkToExecutor = linkToExecutor;
|
package/index.mjs
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { ApolloLink, concat, execute } from '@apollo/client/link/core';
|
|
2
|
-
import { createUploadLink, isExtractableFile, formDataAppendFile } from 'apollo-upload-client';
|
|
3
|
-
import FormData from 'form-data';
|
|
4
|
-
import { fetch } from 'cross-undici-fetch';
|
|
5
|
-
import { Observable } from '@apollo/client/utilities';
|
|
6
|
-
import { toPromise } from '@apollo/client/core';
|
|
7
|
-
import { getOperationASTFromRequest, observableToAsyncIterable } from '@graphql-tools/utils';
|
|
8
|
-
import { GraphQLScalarType, GraphQLError } from 'graphql';
|
|
9
|
-
|
|
10
|
-
function getFinalPromise(object) {
|
|
11
|
-
return Promise.resolve(object).then(resolvedObject => {
|
|
12
|
-
if (resolvedObject == null) {
|
|
13
|
-
return resolvedObject;
|
|
14
|
-
}
|
|
15
|
-
if (Array.isArray(resolvedObject)) {
|
|
16
|
-
return Promise.all(resolvedObject.map(o => getFinalPromise(o)));
|
|
17
|
-
}
|
|
18
|
-
else if (typeof resolvedObject === 'object') {
|
|
19
|
-
const keys = Object.keys(resolvedObject);
|
|
20
|
-
return Promise.all(keys.map(key => getFinalPromise(resolvedObject[key]))).then(awaitedValues => {
|
|
21
|
-
for (let i = 0; i < keys.length; i++) {
|
|
22
|
-
resolvedObject[keys[i]] = awaitedValues[i];
|
|
23
|
-
}
|
|
24
|
-
return resolvedObject;
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
return resolvedObject;
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
class AwaitVariablesLink extends ApolloLink {
|
|
31
|
-
request(operation, forward) {
|
|
32
|
-
return new Observable(observer => {
|
|
33
|
-
let subscription;
|
|
34
|
-
getFinalPromise(operation.variables)
|
|
35
|
-
.then(resolvedVariables => {
|
|
36
|
-
operation.variables = resolvedVariables;
|
|
37
|
-
subscription = forward(operation).subscribe({
|
|
38
|
-
next: observer.next.bind(observer),
|
|
39
|
-
error: observer.error.bind(observer),
|
|
40
|
-
complete: observer.complete.bind(observer),
|
|
41
|
-
});
|
|
42
|
-
})
|
|
43
|
-
.catch(observer.error.bind(observer));
|
|
44
|
-
return () => {
|
|
45
|
-
if (subscription != null) {
|
|
46
|
-
subscription.unsubscribe();
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const createServerHttpLink = (options) => concat(new AwaitVariablesLink(), createUploadLink({
|
|
54
|
-
...options,
|
|
55
|
-
fetch,
|
|
56
|
-
FormData,
|
|
57
|
-
isExtractableFile: (value) => isExtractableFile(value) || (value === null || value === void 0 ? void 0 : value.createReadStream),
|
|
58
|
-
formDataAppendFile: (form, index, file) => {
|
|
59
|
-
if (file.createReadStream != null) {
|
|
60
|
-
form.append(index, file.createReadStream(), {
|
|
61
|
-
filename: file.filename,
|
|
62
|
-
contentType: file.mimetype,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
formDataAppendFile(form, index, file);
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
}));
|
|
70
|
-
|
|
71
|
-
function linkToExecutor(link) {
|
|
72
|
-
return function executorFromLink(request) {
|
|
73
|
-
const observable = execute(link, {
|
|
74
|
-
query: request.document,
|
|
75
|
-
operationName: request.operationName,
|
|
76
|
-
variables: request.variables,
|
|
77
|
-
context: {
|
|
78
|
-
graphqlContext: request.context,
|
|
79
|
-
graphqlResolveInfo: request.info,
|
|
80
|
-
clientAwareness: {},
|
|
81
|
-
},
|
|
82
|
-
extensions: request.extensions,
|
|
83
|
-
});
|
|
84
|
-
const operationAst = getOperationASTFromRequest(request);
|
|
85
|
-
if (operationAst.operation === 'subscription') {
|
|
86
|
-
return observableToAsyncIterable(observable);
|
|
87
|
-
}
|
|
88
|
-
return toPromise(observable);
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const GraphQLUpload = new GraphQLScalarType({
|
|
93
|
-
name: 'Upload',
|
|
94
|
-
description: 'The `Upload` scalar type represents a file upload.',
|
|
95
|
-
parseValue: (value) => {
|
|
96
|
-
if (value != null && 'promise' in value) {
|
|
97
|
-
// graphql-upload v10
|
|
98
|
-
return value.promise;
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
// graphql-upload v9
|
|
102
|
-
return value;
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
// serialization requires to support schema stitching
|
|
106
|
-
serialize: value => value,
|
|
107
|
-
parseLiteral: ast => {
|
|
108
|
-
throw new GraphQLError('Upload literal unsupported.', ast);
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
export { AwaitVariablesLink, GraphQLUpload, createServerHttpLink, linkToExecutor };
|
package/linkToExecutor.d.ts
DELETED