@graphql-mesh/json-schema 1.0.0-alpha-3fc47d119.0 → 1.0.0-alpha-20230420181317-a95037648
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/JsonSchemaWithDiff.js +9 -0
- package/cjs/index.js +100 -0
- package/cjs/package.json +1 -0
- package/esm/JsonSchemaWithDiff.js +6 -0
- package/esm/index.js +97 -0
- package/package.json +31 -24
- package/typings/JsonSchemaWithDiff.d.ts +3 -0
- package/typings/index.d.cts +15 -0
- package/typings/index.d.ts +15 -0
- package/index.d.ts +0 -17
- package/index.js +0 -65
- package/index.mjs +0 -63
- /package/{JsonSchemaWithDiff.d.ts → typings/JsonSchemaWithDiff.d.cts} +0 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JsonSchemaWithDiff = void 0;
|
|
4
|
+
const json_machete_1 = require("json-machete");
|
|
5
|
+
const store_1 = require("@graphql-mesh/store");
|
|
6
|
+
exports.JsonSchemaWithDiff = {
|
|
7
|
+
...store_1.PredefinedProxyOptions.JsonWithoutValidation,
|
|
8
|
+
validate: json_machete_1.compareJSONSchemas,
|
|
9
|
+
};
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const graphql_1 = require("graphql");
|
|
4
|
+
const store_1 = require("@graphql-mesh/store");
|
|
5
|
+
const utils_1 = require("@graphql-mesh/utils");
|
|
6
|
+
const utils_2 = require("@graphql-tools/utils");
|
|
7
|
+
const json_schema_1 = require("@omnigraph/json-schema");
|
|
8
|
+
class JsonSchemaHandler {
|
|
9
|
+
constructor({ name, config, baseDir, store, pubsub, logger, importFn, }) {
|
|
10
|
+
this.name = name;
|
|
11
|
+
this.config = config;
|
|
12
|
+
this.baseDir = baseDir;
|
|
13
|
+
this.schemaWithAnnotationsProxy = store.proxy('schemaWithAnnotations', store_1.PredefinedProxyOptions.GraphQLSchemaWithDiffing);
|
|
14
|
+
this.pubsub = pubsub;
|
|
15
|
+
this.logger = logger;
|
|
16
|
+
this.importFn = importFn;
|
|
17
|
+
}
|
|
18
|
+
async getNonExecutableSchema() {
|
|
19
|
+
if (this.config.source) {
|
|
20
|
+
this.logger.info(`Fetching GraphQL Schema with annotations`);
|
|
21
|
+
const sdl = await (0, utils_1.readFileOrUrl)(this.config.source, {
|
|
22
|
+
allowUnknownExtensions: true,
|
|
23
|
+
cwd: this.baseDir,
|
|
24
|
+
fetch: this.fetchFn,
|
|
25
|
+
importFn: this.importFn,
|
|
26
|
+
logger: this.logger,
|
|
27
|
+
headers: this.config.schemaHeaders,
|
|
28
|
+
});
|
|
29
|
+
return (0, graphql_1.buildSchema)(sdl, {
|
|
30
|
+
assumeValidSDL: true,
|
|
31
|
+
assumeValid: true,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return this.schemaWithAnnotationsProxy.getWithSet(async () => {
|
|
35
|
+
if (this.config.bundlePath) {
|
|
36
|
+
this.logger.info(`Fetching JSON Schema bundle`);
|
|
37
|
+
const bundle = await (0, utils_1.readFileOrUrl)(this.config.bundlePath, {
|
|
38
|
+
allowUnknownExtensions: true,
|
|
39
|
+
cwd: this.baseDir,
|
|
40
|
+
fetch: this.fetchFn,
|
|
41
|
+
importFn: this.importFn,
|
|
42
|
+
logger: this.logger,
|
|
43
|
+
headers: this.config.bundleHeaders,
|
|
44
|
+
});
|
|
45
|
+
return (0, json_schema_1.getGraphQLSchemaFromBundle)(bundle, {
|
|
46
|
+
cwd: this.baseDir,
|
|
47
|
+
logger: this.logger,
|
|
48
|
+
fetch: this.fetchFn,
|
|
49
|
+
endpoint: this.config.endpoint,
|
|
50
|
+
operationHeaders: this.config.operationHeaders,
|
|
51
|
+
queryParams: this.config.queryParams,
|
|
52
|
+
queryStringOptions: this.config.queryStringOptions,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
this.logger.info(`Generating GraphQL schema from JSON Schemas`);
|
|
56
|
+
return (0, json_schema_1.loadNonExecutableGraphQLSchemaFromJSONSchemas)(this.name, {
|
|
57
|
+
...this.config,
|
|
58
|
+
operations: this.config.operations,
|
|
59
|
+
cwd: this.baseDir,
|
|
60
|
+
fetch: this.fetchFn,
|
|
61
|
+
logger: this.logger,
|
|
62
|
+
pubsub: this.pubsub,
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
async getMeshSource({ fetchFn }) {
|
|
67
|
+
this.fetchFn = fetchFn;
|
|
68
|
+
this.logger.debug('Getting the schema with annotations');
|
|
69
|
+
const nonExecutableSchema = await this.getNonExecutableSchema();
|
|
70
|
+
const schemaWithDirectives$ = Promise.resolve().then(() => {
|
|
71
|
+
this.logger.info(`Processing annotations for the execution layer`);
|
|
72
|
+
return (0, json_schema_1.processDirectives)({
|
|
73
|
+
...this.config,
|
|
74
|
+
schema: nonExecutableSchema,
|
|
75
|
+
pubsub: this.pubsub,
|
|
76
|
+
logger: this.logger,
|
|
77
|
+
globalFetch: fetchFn,
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
return {
|
|
81
|
+
schema: nonExecutableSchema,
|
|
82
|
+
executor: async (executionRequest) => {
|
|
83
|
+
const args = {
|
|
84
|
+
schema: await schemaWithDirectives$,
|
|
85
|
+
document: executionRequest.document,
|
|
86
|
+
variableValues: executionRequest.variables,
|
|
87
|
+
operationName: executionRequest.operationName,
|
|
88
|
+
contextValue: executionRequest.context,
|
|
89
|
+
rootValue: executionRequest.rootValue,
|
|
90
|
+
};
|
|
91
|
+
const operationAST = (0, utils_2.getOperationASTFromRequest)(executionRequest);
|
|
92
|
+
if (operationAST.operation === graphql_1.OperationTypeNode.SUBSCRIPTION) {
|
|
93
|
+
return (0, graphql_1.subscribe)(args);
|
|
94
|
+
}
|
|
95
|
+
return (0, graphql_1.execute)(args);
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.default = JsonSchemaHandler;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { buildSchema, execute, OperationTypeNode, subscribe, } from 'graphql';
|
|
2
|
+
import { PredefinedProxyOptions } from '@graphql-mesh/store';
|
|
3
|
+
import { readFileOrUrl } from '@graphql-mesh/utils';
|
|
4
|
+
import { getOperationASTFromRequest } from '@graphql-tools/utils';
|
|
5
|
+
import { getGraphQLSchemaFromBundle, loadNonExecutableGraphQLSchemaFromJSONSchemas, processDirectives, } from '@omnigraph/json-schema';
|
|
6
|
+
export default class JsonSchemaHandler {
|
|
7
|
+
constructor({ name, config, baseDir, store, pubsub, logger, importFn, }) {
|
|
8
|
+
this.name = name;
|
|
9
|
+
this.config = config;
|
|
10
|
+
this.baseDir = baseDir;
|
|
11
|
+
this.schemaWithAnnotationsProxy = store.proxy('schemaWithAnnotations', PredefinedProxyOptions.GraphQLSchemaWithDiffing);
|
|
12
|
+
this.pubsub = pubsub;
|
|
13
|
+
this.logger = logger;
|
|
14
|
+
this.importFn = importFn;
|
|
15
|
+
}
|
|
16
|
+
async getNonExecutableSchema() {
|
|
17
|
+
if (this.config.source) {
|
|
18
|
+
this.logger.info(`Fetching GraphQL Schema with annotations`);
|
|
19
|
+
const sdl = await readFileOrUrl(this.config.source, {
|
|
20
|
+
allowUnknownExtensions: true,
|
|
21
|
+
cwd: this.baseDir,
|
|
22
|
+
fetch: this.fetchFn,
|
|
23
|
+
importFn: this.importFn,
|
|
24
|
+
logger: this.logger,
|
|
25
|
+
headers: this.config.schemaHeaders,
|
|
26
|
+
});
|
|
27
|
+
return buildSchema(sdl, {
|
|
28
|
+
assumeValidSDL: true,
|
|
29
|
+
assumeValid: true,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return this.schemaWithAnnotationsProxy.getWithSet(async () => {
|
|
33
|
+
if (this.config.bundlePath) {
|
|
34
|
+
this.logger.info(`Fetching JSON Schema bundle`);
|
|
35
|
+
const bundle = await readFileOrUrl(this.config.bundlePath, {
|
|
36
|
+
allowUnknownExtensions: true,
|
|
37
|
+
cwd: this.baseDir,
|
|
38
|
+
fetch: this.fetchFn,
|
|
39
|
+
importFn: this.importFn,
|
|
40
|
+
logger: this.logger,
|
|
41
|
+
headers: this.config.bundleHeaders,
|
|
42
|
+
});
|
|
43
|
+
return getGraphQLSchemaFromBundle(bundle, {
|
|
44
|
+
cwd: this.baseDir,
|
|
45
|
+
logger: this.logger,
|
|
46
|
+
fetch: this.fetchFn,
|
|
47
|
+
endpoint: this.config.endpoint,
|
|
48
|
+
operationHeaders: this.config.operationHeaders,
|
|
49
|
+
queryParams: this.config.queryParams,
|
|
50
|
+
queryStringOptions: this.config.queryStringOptions,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
this.logger.info(`Generating GraphQL schema from JSON Schemas`);
|
|
54
|
+
return loadNonExecutableGraphQLSchemaFromJSONSchemas(this.name, {
|
|
55
|
+
...this.config,
|
|
56
|
+
operations: this.config.operations,
|
|
57
|
+
cwd: this.baseDir,
|
|
58
|
+
fetch: this.fetchFn,
|
|
59
|
+
logger: this.logger,
|
|
60
|
+
pubsub: this.pubsub,
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async getMeshSource({ fetchFn }) {
|
|
65
|
+
this.fetchFn = fetchFn;
|
|
66
|
+
this.logger.debug('Getting the schema with annotations');
|
|
67
|
+
const nonExecutableSchema = await this.getNonExecutableSchema();
|
|
68
|
+
const schemaWithDirectives$ = Promise.resolve().then(() => {
|
|
69
|
+
this.logger.info(`Processing annotations for the execution layer`);
|
|
70
|
+
return processDirectives({
|
|
71
|
+
...this.config,
|
|
72
|
+
schema: nonExecutableSchema,
|
|
73
|
+
pubsub: this.pubsub,
|
|
74
|
+
logger: this.logger,
|
|
75
|
+
globalFetch: fetchFn,
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
schema: nonExecutableSchema,
|
|
80
|
+
executor: async (executionRequest) => {
|
|
81
|
+
const args = {
|
|
82
|
+
schema: await schemaWithDirectives$,
|
|
83
|
+
document: executionRequest.document,
|
|
84
|
+
variableValues: executionRequest.variables,
|
|
85
|
+
operationName: executionRequest.operationName,
|
|
86
|
+
contextValue: executionRequest.context,
|
|
87
|
+
rootValue: executionRequest.rootValue,
|
|
88
|
+
};
|
|
89
|
+
const operationAST = getOperationASTFromRequest(executionRequest);
|
|
90
|
+
if (operationAST.operation === OperationTypeNode.SUBSCRIPTION) {
|
|
91
|
+
return subscribe(args);
|
|
92
|
+
}
|
|
93
|
+
return execute(args);
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
package/package.json
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/json-schema",
|
|
3
|
-
"version": "1.0.0-alpha-
|
|
3
|
+
"version": "1.0.0-alpha-20230420181317-a95037648",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@graphql-mesh/
|
|
7
|
-
"@graphql-mesh/
|
|
8
|
-
"graphql": "
|
|
6
|
+
"@graphql-mesh/cross-helpers": "^0.3.4",
|
|
7
|
+
"@graphql-mesh/store": "1.0.0-alpha-20230420181317-a95037648",
|
|
8
|
+
"@graphql-mesh/types": "1.0.0-alpha-20230420181317-a95037648",
|
|
9
|
+
"@graphql-mesh/utils": "1.0.0-alpha-20230420181317-a95037648",
|
|
10
|
+
"@graphql-tools/utils": "^9.2.1",
|
|
11
|
+
"graphql": "*",
|
|
12
|
+
"tslib": "^2.4.0"
|
|
9
13
|
},
|
|
10
14
|
"dependencies": {
|
|
11
|
-
"@graphql-mesh/
|
|
12
|
-
"@
|
|
13
|
-
"@
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"@omnigraph/json-schema": "1.0.0-alpha-3fc47d119.0",
|
|
17
|
-
"graphql-compose": "9.0.8",
|
|
18
|
-
"json-machete": "1.0.0-alpha-3fc47d119.0",
|
|
19
|
-
"tslib": "^2.4.0"
|
|
15
|
+
"@graphql-mesh/string-interpolation": "0.4.4",
|
|
16
|
+
"@json-schema-tools/meta-schema": "1.7.0",
|
|
17
|
+
"@omnigraph/json-schema": "1.0.0-alpha-20230420181317-a95037648",
|
|
18
|
+
"graphql-compose": "9.0.10",
|
|
19
|
+
"json-machete": "1.0.0-alpha-20230420181317-a95037648"
|
|
20
20
|
},
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|
|
@@ -24,21 +24,28 @@
|
|
|
24
24
|
"directory": "packages/handlers/json-schema"
|
|
25
25
|
},
|
|
26
26
|
"license": "MIT",
|
|
27
|
-
"main": "index.js",
|
|
28
|
-
"module": "index.
|
|
29
|
-
"typings": "index.d.ts",
|
|
27
|
+
"main": "cjs/index.js",
|
|
28
|
+
"module": "esm/index.js",
|
|
29
|
+
"typings": "typings/index.d.ts",
|
|
30
30
|
"typescript": {
|
|
31
|
-
"definition": "index.d.ts"
|
|
31
|
+
"definition": "typings/index.d.ts"
|
|
32
32
|
},
|
|
33
|
+
"type": "module",
|
|
33
34
|
"exports": {
|
|
34
35
|
".": {
|
|
35
|
-
"require":
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
|
|
36
|
+
"require": {
|
|
37
|
+
"types": "./typings/index.d.cts",
|
|
38
|
+
"default": "./cjs/index.js"
|
|
39
|
+
},
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./typings/index.d.ts",
|
|
42
|
+
"default": "./esm/index.js"
|
|
43
|
+
},
|
|
44
|
+
"default": {
|
|
45
|
+
"types": "./typings/index.d.ts",
|
|
46
|
+
"default": "./esm/index.js"
|
|
47
|
+
}
|
|
41
48
|
},
|
|
42
49
|
"./package.json": "./package.json"
|
|
43
50
|
}
|
|
44
|
-
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { GetMeshSourcePayload, MeshHandler, MeshHandlerOptions, MeshSource, YamlConfig } from '@graphql-mesh/types';
|
|
3
|
+
export default class JsonSchemaHandler implements MeshHandler {
|
|
4
|
+
private name;
|
|
5
|
+
private config;
|
|
6
|
+
private schemaWithAnnotationsProxy;
|
|
7
|
+
private baseDir;
|
|
8
|
+
private logger;
|
|
9
|
+
private fetchFn;
|
|
10
|
+
private pubsub;
|
|
11
|
+
private importFn;
|
|
12
|
+
constructor({ name, config, baseDir, store, pubsub, logger, importFn, }: MeshHandlerOptions<YamlConfig.Handler['jsonSchema']>);
|
|
13
|
+
getNonExecutableSchema(): Promise<GraphQLSchema>;
|
|
14
|
+
getMeshSource({ fetchFn }: GetMeshSourcePayload): Promise<MeshSource>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { GetMeshSourcePayload, MeshHandler, MeshHandlerOptions, MeshSource, YamlConfig } from '@graphql-mesh/types';
|
|
3
|
+
export default class JsonSchemaHandler implements MeshHandler {
|
|
4
|
+
private name;
|
|
5
|
+
private config;
|
|
6
|
+
private schemaWithAnnotationsProxy;
|
|
7
|
+
private baseDir;
|
|
8
|
+
private logger;
|
|
9
|
+
private fetchFn;
|
|
10
|
+
private pubsub;
|
|
11
|
+
private importFn;
|
|
12
|
+
constructor({ name, config, baseDir, store, pubsub, logger, importFn, }: MeshHandlerOptions<YamlConfig.Handler['jsonSchema']>);
|
|
13
|
+
getNonExecutableSchema(): Promise<GraphQLSchema>;
|
|
14
|
+
getMeshSource({ fetchFn }: GetMeshSourcePayload): Promise<MeshSource>;
|
|
15
|
+
}
|
package/index.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { GetMeshSourceOptions, MeshHandler, YamlConfig } from '@graphql-mesh/types';
|
|
2
|
-
import { JSONSchemaLoaderBundle } from '@omnigraph/json-schema';
|
|
3
|
-
export default class JsonSchemaHandler implements MeshHandler {
|
|
4
|
-
private name;
|
|
5
|
-
private config;
|
|
6
|
-
private bundleStoreProxy;
|
|
7
|
-
private baseDir;
|
|
8
|
-
private logger;
|
|
9
|
-
private fetchFn;
|
|
10
|
-
private importFn;
|
|
11
|
-
private pubsub;
|
|
12
|
-
constructor({ name, config, baseDir, store, pubsub, logger, importFn, fetchFn, }: GetMeshSourceOptions<YamlConfig.Handler['jsonSchema']>);
|
|
13
|
-
getDereferencedBundle(): Promise<JSONSchemaLoaderBundle>;
|
|
14
|
-
getMeshSource(): Promise<{
|
|
15
|
-
schema: import("graphql").GraphQLSchema;
|
|
16
|
-
}>;
|
|
17
|
-
}
|
package/index.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const store = require('@graphql-mesh/store');
|
|
4
|
-
const jsonSchema = require('@omnigraph/json-schema');
|
|
5
|
-
const utils = require('@graphql-mesh/utils');
|
|
6
|
-
const stringInterpolation = require('@graphql-mesh/string-interpolation');
|
|
7
|
-
const crossHelpers = require('@graphql-mesh/cross-helpers');
|
|
8
|
-
|
|
9
|
-
class JsonSchemaHandler {
|
|
10
|
-
constructor({ name, config, baseDir, store: store$1, pubsub, logger, importFn, fetchFn, }) {
|
|
11
|
-
this.name = name;
|
|
12
|
-
this.config = config;
|
|
13
|
-
this.baseDir = baseDir;
|
|
14
|
-
this.fetchFn = fetchFn;
|
|
15
|
-
this.importFn = importFn;
|
|
16
|
-
this.bundleStoreProxy = store$1.proxy('jsonSchemaBundle', store.PredefinedProxyOptions.JsonWithoutValidation);
|
|
17
|
-
this.pubsub = pubsub;
|
|
18
|
-
this.logger = logger;
|
|
19
|
-
}
|
|
20
|
-
async getDereferencedBundle() {
|
|
21
|
-
const config = this.config;
|
|
22
|
-
if ('bundlePath' in config) {
|
|
23
|
-
const headersFactory = stringInterpolation.getInterpolatedHeadersFactory(config.bundleHeaders);
|
|
24
|
-
const bundle = await utils.readFileOrUrl(config.bundlePath, {
|
|
25
|
-
cwd: this.baseDir,
|
|
26
|
-
fetch: this.fetchFn,
|
|
27
|
-
logger: this.logger,
|
|
28
|
-
headers: headersFactory({
|
|
29
|
-
env: crossHelpers.process.env,
|
|
30
|
-
}),
|
|
31
|
-
fallbackFormat: 'json',
|
|
32
|
-
importFn: this.importFn,
|
|
33
|
-
});
|
|
34
|
-
return bundle;
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
return this.bundleStoreProxy.getWithSet(() => {
|
|
38
|
-
return jsonSchema.createBundle(this.name, {
|
|
39
|
-
...config,
|
|
40
|
-
operations: config.operations,
|
|
41
|
-
cwd: this.baseDir,
|
|
42
|
-
fetch: this.fetchFn,
|
|
43
|
-
logger: this.logger,
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
async getMeshSource() {
|
|
49
|
-
const bundle = await this.getDereferencedBundle();
|
|
50
|
-
const schema = await jsonSchema.getGraphQLSchemaFromBundle(bundle, {
|
|
51
|
-
cwd: this.baseDir,
|
|
52
|
-
fetch: this.fetchFn,
|
|
53
|
-
pubsub: this.pubsub,
|
|
54
|
-
logger: this.logger,
|
|
55
|
-
baseUrl: this.config.baseUrl,
|
|
56
|
-
operationHeaders: this.config.operationHeaders,
|
|
57
|
-
queryStringOptions: this.config.queryStringOptions,
|
|
58
|
-
});
|
|
59
|
-
return {
|
|
60
|
-
schema,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
module.exports = JsonSchemaHandler;
|
package/index.mjs
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { PredefinedProxyOptions } from '@graphql-mesh/store';
|
|
2
|
-
import { createBundle, getGraphQLSchemaFromBundle } from '@omnigraph/json-schema';
|
|
3
|
-
import { readFileOrUrl } from '@graphql-mesh/utils';
|
|
4
|
-
import { getInterpolatedHeadersFactory } from '@graphql-mesh/string-interpolation';
|
|
5
|
-
import { process } from '@graphql-mesh/cross-helpers';
|
|
6
|
-
|
|
7
|
-
class JsonSchemaHandler {
|
|
8
|
-
constructor({ name, config, baseDir, store, pubsub, logger, importFn, fetchFn, }) {
|
|
9
|
-
this.name = name;
|
|
10
|
-
this.config = config;
|
|
11
|
-
this.baseDir = baseDir;
|
|
12
|
-
this.fetchFn = fetchFn;
|
|
13
|
-
this.importFn = importFn;
|
|
14
|
-
this.bundleStoreProxy = store.proxy('jsonSchemaBundle', PredefinedProxyOptions.JsonWithoutValidation);
|
|
15
|
-
this.pubsub = pubsub;
|
|
16
|
-
this.logger = logger;
|
|
17
|
-
}
|
|
18
|
-
async getDereferencedBundle() {
|
|
19
|
-
const config = this.config;
|
|
20
|
-
if ('bundlePath' in config) {
|
|
21
|
-
const headersFactory = getInterpolatedHeadersFactory(config.bundleHeaders);
|
|
22
|
-
const bundle = await readFileOrUrl(config.bundlePath, {
|
|
23
|
-
cwd: this.baseDir,
|
|
24
|
-
fetch: this.fetchFn,
|
|
25
|
-
logger: this.logger,
|
|
26
|
-
headers: headersFactory({
|
|
27
|
-
env: process.env,
|
|
28
|
-
}),
|
|
29
|
-
fallbackFormat: 'json',
|
|
30
|
-
importFn: this.importFn,
|
|
31
|
-
});
|
|
32
|
-
return bundle;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
return this.bundleStoreProxy.getWithSet(() => {
|
|
36
|
-
return createBundle(this.name, {
|
|
37
|
-
...config,
|
|
38
|
-
operations: config.operations,
|
|
39
|
-
cwd: this.baseDir,
|
|
40
|
-
fetch: this.fetchFn,
|
|
41
|
-
logger: this.logger,
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
async getMeshSource() {
|
|
47
|
-
const bundle = await this.getDereferencedBundle();
|
|
48
|
-
const schema = await getGraphQLSchemaFromBundle(bundle, {
|
|
49
|
-
cwd: this.baseDir,
|
|
50
|
-
fetch: this.fetchFn,
|
|
51
|
-
pubsub: this.pubsub,
|
|
52
|
-
logger: this.logger,
|
|
53
|
-
baseUrl: this.config.baseUrl,
|
|
54
|
-
operationHeaders: this.config.operationHeaders,
|
|
55
|
-
queryStringOptions: this.config.queryStringOptions,
|
|
56
|
-
});
|
|
57
|
-
return {
|
|
58
|
-
schema,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export default JsonSchemaHandler;
|
|
File without changes
|