@graphql-mesh/openapi 1.0.0-alpha-20220804093904-8e2e41f7f → 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/index.js +97 -0
- package/cjs/package.json +1 -0
- package/esm/index.js +94 -0
- package/package.json +27 -32
- package/typings/index.d.cts +18 -0
- package/typings/index.d.ts +18 -0
- package/index.d.ts +0 -13
- package/index.js +0 -5020
- package/index.mjs +0 -5016
- package/openapi-to-graphql/auth_builder.d.ts +0 -24
- package/openapi-to-graphql/graphql_tools.d.ts +0 -8
- package/openapi-to-graphql/index.d.ts +0 -39
- package/openapi-to-graphql/oas_3_tools.d.ts +0 -208
- package/openapi-to-graphql/preprocessor.d.ts +0 -18
- package/openapi-to-graphql/resolver_builder.d.ts +0 -60
- package/openapi-to-graphql/schema_builder.d.ts +0 -36
- package/openapi-to-graphql/types/graphql.d.ts +0 -31
- package/openapi-to-graphql/types/oas2.d.ts +0 -10
- package/openapi-to-graphql/types/oas3.d.ts +0 -243
- package/openapi-to-graphql/types/operation.d.ts +0 -122
- package/openapi-to-graphql/types/options.d.ts +0 -251
- package/openapi-to-graphql/types/preprocessing_data.d.ts +0 -71
- package/openapi-to-graphql/utils.d.ts +0 -61
package/cjs/index.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
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 string_interpolation_1 = require("@graphql-mesh/string-interpolation");
|
|
6
|
+
const utils_1 = require("@graphql-mesh/utils");
|
|
7
|
+
const utils_2 = require("@graphql-tools/utils");
|
|
8
|
+
const openapi_1 = require("@omnigraph/openapi");
|
|
9
|
+
class OpenAPIHandler {
|
|
10
|
+
constructor({ name, config, baseDir, store, pubsub, logger, importFn, }) {
|
|
11
|
+
this.name = name;
|
|
12
|
+
this.config = config;
|
|
13
|
+
this.baseDir = baseDir;
|
|
14
|
+
this.schemaWithAnnotationsProxy = store.proxy('schemaWithAnnotations', store_1.PredefinedProxyOptions.GraphQLSchemaWithDiffing);
|
|
15
|
+
this.bundleProxy = store.proxy('jsonSchemaBundle', store_1.PredefinedProxyOptions.JsonWithoutValidation);
|
|
16
|
+
this.pubsub = pubsub;
|
|
17
|
+
this.importFn = importFn;
|
|
18
|
+
this.logger = logger;
|
|
19
|
+
}
|
|
20
|
+
async getNonExecutableSchema({ interpolatedSource }) {
|
|
21
|
+
if (interpolatedSource.endsWith('.graphql')) {
|
|
22
|
+
this.logger.info(`Fetching GraphQL Schema with annotations`);
|
|
23
|
+
const sdl = await (0, utils_1.readFileOrUrl)(interpolatedSource, {
|
|
24
|
+
allowUnknownExtensions: true,
|
|
25
|
+
cwd: this.baseDir,
|
|
26
|
+
fetch: this.fetchFn,
|
|
27
|
+
importFn: this.importFn,
|
|
28
|
+
logger: this.logger,
|
|
29
|
+
headers: this.config.schemaHeaders,
|
|
30
|
+
});
|
|
31
|
+
return (0, graphql_1.buildSchema)(sdl, {
|
|
32
|
+
assumeValidSDL: true,
|
|
33
|
+
assumeValid: true,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return this.schemaWithAnnotationsProxy.getWithSet(async () => {
|
|
37
|
+
var _a;
|
|
38
|
+
this.logger.info(`Generating GraphQL schema from OpenAPI schema`);
|
|
39
|
+
const schema = await (0, openapi_1.loadNonExecutableGraphQLSchemaFromOpenAPI)(this.name, {
|
|
40
|
+
...this.config,
|
|
41
|
+
source: interpolatedSource,
|
|
42
|
+
cwd: this.baseDir,
|
|
43
|
+
fetch: this.fetchFn,
|
|
44
|
+
logger: this.logger,
|
|
45
|
+
selectQueryOrMutationField: (_a = this.config.selectQueryOrMutationField) === null || _a === void 0 ? void 0 : _a.map(({ type, fieldName }) => ({
|
|
46
|
+
type: type.toLowerCase(),
|
|
47
|
+
fieldName,
|
|
48
|
+
})),
|
|
49
|
+
pubsub: this.pubsub,
|
|
50
|
+
bundle: this.config.bundle,
|
|
51
|
+
});
|
|
52
|
+
if (this.config.bundle) {
|
|
53
|
+
await this.bundleProxy.set(schema.extensions.bundle);
|
|
54
|
+
}
|
|
55
|
+
return schema;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
async getMeshSource({ fetchFn }) {
|
|
59
|
+
const interpolatedSource = string_interpolation_1.stringInterpolator.parse(this.config.source, {
|
|
60
|
+
env: process.env,
|
|
61
|
+
});
|
|
62
|
+
this.fetchFn = fetchFn;
|
|
63
|
+
this.logger.debug('Getting the schema with annotations');
|
|
64
|
+
const nonExecutableSchema = await this.getNonExecutableSchema({
|
|
65
|
+
interpolatedSource,
|
|
66
|
+
});
|
|
67
|
+
const schemaWithDirectives$ = Promise.resolve().then(() => {
|
|
68
|
+
this.logger.info(`Processing annotations for the execution layer`);
|
|
69
|
+
return (0, openapi_1.processDirectives)({
|
|
70
|
+
...this.config,
|
|
71
|
+
schema: nonExecutableSchema,
|
|
72
|
+
pubsub: this.pubsub,
|
|
73
|
+
logger: this.logger,
|
|
74
|
+
globalFetch: fetchFn,
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
schema: nonExecutableSchema,
|
|
79
|
+
executor: async (executionRequest) => {
|
|
80
|
+
const args = {
|
|
81
|
+
schema: await schemaWithDirectives$,
|
|
82
|
+
document: executionRequest.document,
|
|
83
|
+
variableValues: executionRequest.variables,
|
|
84
|
+
operationName: executionRequest.operationName,
|
|
85
|
+
contextValue: executionRequest.context,
|
|
86
|
+
rootValue: executionRequest.rootValue,
|
|
87
|
+
};
|
|
88
|
+
const operationAST = (0, utils_2.getOperationASTFromRequest)(executionRequest);
|
|
89
|
+
if (operationAST.operation === graphql_1.OperationTypeNode.SUBSCRIPTION) {
|
|
90
|
+
return (0, graphql_1.subscribe)(args);
|
|
91
|
+
}
|
|
92
|
+
return (0, graphql_1.execute)(args);
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.default = OpenAPIHandler;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { buildSchema, execute, OperationTypeNode, subscribe, } from 'graphql';
|
|
2
|
+
import { PredefinedProxyOptions } from '@graphql-mesh/store';
|
|
3
|
+
import { stringInterpolator } from '@graphql-mesh/string-interpolation';
|
|
4
|
+
import { readFileOrUrl } from '@graphql-mesh/utils';
|
|
5
|
+
import { getOperationASTFromRequest } from '@graphql-tools/utils';
|
|
6
|
+
import { loadNonExecutableGraphQLSchemaFromOpenAPI, processDirectives } from '@omnigraph/openapi';
|
|
7
|
+
export default class OpenAPIHandler {
|
|
8
|
+
constructor({ name, config, baseDir, store, pubsub, logger, importFn, }) {
|
|
9
|
+
this.name = name;
|
|
10
|
+
this.config = config;
|
|
11
|
+
this.baseDir = baseDir;
|
|
12
|
+
this.schemaWithAnnotationsProxy = store.proxy('schemaWithAnnotations', PredefinedProxyOptions.GraphQLSchemaWithDiffing);
|
|
13
|
+
this.bundleProxy = store.proxy('jsonSchemaBundle', PredefinedProxyOptions.JsonWithoutValidation);
|
|
14
|
+
this.pubsub = pubsub;
|
|
15
|
+
this.importFn = importFn;
|
|
16
|
+
this.logger = logger;
|
|
17
|
+
}
|
|
18
|
+
async getNonExecutableSchema({ interpolatedSource }) {
|
|
19
|
+
if (interpolatedSource.endsWith('.graphql')) {
|
|
20
|
+
this.logger.info(`Fetching GraphQL Schema with annotations`);
|
|
21
|
+
const sdl = await readFileOrUrl(interpolatedSource, {
|
|
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 buildSchema(sdl, {
|
|
30
|
+
assumeValidSDL: true,
|
|
31
|
+
assumeValid: true,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return this.schemaWithAnnotationsProxy.getWithSet(async () => {
|
|
35
|
+
var _a;
|
|
36
|
+
this.logger.info(`Generating GraphQL schema from OpenAPI schema`);
|
|
37
|
+
const schema = await loadNonExecutableGraphQLSchemaFromOpenAPI(this.name, {
|
|
38
|
+
...this.config,
|
|
39
|
+
source: interpolatedSource,
|
|
40
|
+
cwd: this.baseDir,
|
|
41
|
+
fetch: this.fetchFn,
|
|
42
|
+
logger: this.logger,
|
|
43
|
+
selectQueryOrMutationField: (_a = this.config.selectQueryOrMutationField) === null || _a === void 0 ? void 0 : _a.map(({ type, fieldName }) => ({
|
|
44
|
+
type: type.toLowerCase(),
|
|
45
|
+
fieldName,
|
|
46
|
+
})),
|
|
47
|
+
pubsub: this.pubsub,
|
|
48
|
+
bundle: this.config.bundle,
|
|
49
|
+
});
|
|
50
|
+
if (this.config.bundle) {
|
|
51
|
+
await this.bundleProxy.set(schema.extensions.bundle);
|
|
52
|
+
}
|
|
53
|
+
return schema;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
async getMeshSource({ fetchFn }) {
|
|
57
|
+
const interpolatedSource = stringInterpolator.parse(this.config.source, {
|
|
58
|
+
env: process.env,
|
|
59
|
+
});
|
|
60
|
+
this.fetchFn = fetchFn;
|
|
61
|
+
this.logger.debug('Getting the schema with annotations');
|
|
62
|
+
const nonExecutableSchema = await this.getNonExecutableSchema({
|
|
63
|
+
interpolatedSource,
|
|
64
|
+
});
|
|
65
|
+
const schemaWithDirectives$ = Promise.resolve().then(() => {
|
|
66
|
+
this.logger.info(`Processing annotations for the execution layer`);
|
|
67
|
+
return processDirectives({
|
|
68
|
+
...this.config,
|
|
69
|
+
schema: nonExecutableSchema,
|
|
70
|
+
pubsub: this.pubsub,
|
|
71
|
+
logger: this.logger,
|
|
72
|
+
globalFetch: fetchFn,
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
return {
|
|
76
|
+
schema: nonExecutableSchema,
|
|
77
|
+
executor: async (executionRequest) => {
|
|
78
|
+
const args = {
|
|
79
|
+
schema: await schemaWithDirectives$,
|
|
80
|
+
document: executionRequest.document,
|
|
81
|
+
variableValues: executionRequest.variables,
|
|
82
|
+
operationName: executionRequest.operationName,
|
|
83
|
+
contextValue: executionRequest.context,
|
|
84
|
+
rootValue: executionRequest.rootValue,
|
|
85
|
+
};
|
|
86
|
+
const operationAST = getOperationASTFromRequest(executionRequest);
|
|
87
|
+
if (operationAST.operation === OperationTypeNode.SUBSCRIPTION) {
|
|
88
|
+
return subscribe(args);
|
|
89
|
+
}
|
|
90
|
+
return execute(args);
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
package/package.json
CHANGED
|
@@ -1,30 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/openapi",
|
|
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/store": "1.0.0-alpha-20230420181317-a95037648",
|
|
7
|
+
"@graphql-mesh/types": "1.0.0-alpha-20230420181317-a95037648",
|
|
8
|
+
"@graphql-mesh/utils": "1.0.0-alpha-20230420181317-a95037648",
|
|
9
|
+
"@graphql-tools/utils": "^9.2.1",
|
|
10
|
+
"graphql": "*",
|
|
11
|
+
"tslib": "^2.4.0"
|
|
9
12
|
},
|
|
10
13
|
"dependencies": {
|
|
11
|
-
"@graphql-mesh/
|
|
12
|
-
"@
|
|
13
|
-
"@graphql-mesh/string-interpolation": "0.3.0",
|
|
14
|
-
"@graphql-tools/utils": "8.9.0",
|
|
15
|
-
"@whatwg-node/fetch": "^0.2.7",
|
|
16
|
-
"deep-equal": "2.0.5",
|
|
17
|
-
"form-urlencoded": "6.1.0",
|
|
18
|
-
"graphql-scalars": "1.17.0",
|
|
19
|
-
"json-pointer": "0.6.2",
|
|
20
|
-
"jsonpath-plus": "7.0.0",
|
|
21
|
-
"openapi-diff": "0.23.5",
|
|
22
|
-
"openapi-types": "12.0.0",
|
|
23
|
-
"pluralize": "8.0.0",
|
|
24
|
-
"qs": "6.11.0",
|
|
25
|
-
"swagger2openapi": "7.0.8",
|
|
26
|
-
"tslib": "^2.4.0",
|
|
27
|
-
"url-join": "4.0.1"
|
|
14
|
+
"@graphql-mesh/string-interpolation": "0.4.4",
|
|
15
|
+
"@omnigraph/openapi": "1.0.0-alpha-20230420181317-a95037648"
|
|
28
16
|
},
|
|
29
17
|
"repository": {
|
|
30
18
|
"type": "git",
|
|
@@ -32,21 +20,28 @@
|
|
|
32
20
|
"directory": "packages/handlers/openapi"
|
|
33
21
|
},
|
|
34
22
|
"license": "MIT",
|
|
35
|
-
"main": "index.js",
|
|
36
|
-
"module": "index.
|
|
37
|
-
"typings": "index.d.ts",
|
|
23
|
+
"main": "cjs/index.js",
|
|
24
|
+
"module": "esm/index.js",
|
|
25
|
+
"typings": "typings/index.d.ts",
|
|
38
26
|
"typescript": {
|
|
39
|
-
"definition": "index.d.ts"
|
|
27
|
+
"definition": "typings/index.d.ts"
|
|
40
28
|
},
|
|
29
|
+
"type": "module",
|
|
41
30
|
"exports": {
|
|
42
31
|
".": {
|
|
43
|
-
"require":
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
|
|
32
|
+
"require": {
|
|
33
|
+
"types": "./typings/index.d.cts",
|
|
34
|
+
"default": "./cjs/index.js"
|
|
35
|
+
},
|
|
36
|
+
"import": {
|
|
37
|
+
"types": "./typings/index.d.ts",
|
|
38
|
+
"default": "./esm/index.js"
|
|
39
|
+
},
|
|
40
|
+
"default": {
|
|
41
|
+
"types": "./typings/index.d.ts",
|
|
42
|
+
"default": "./esm/index.js"
|
|
43
|
+
}
|
|
49
44
|
},
|
|
50
45
|
"./package.json": "./package.json"
|
|
51
46
|
}
|
|
52
|
-
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { GetMeshSourcePayload, MeshHandler, MeshHandlerOptions, MeshSource, YamlConfig } from '@graphql-mesh/types';
|
|
3
|
+
export default class OpenAPIHandler implements MeshHandler {
|
|
4
|
+
private name;
|
|
5
|
+
private config;
|
|
6
|
+
private schemaWithAnnotationsProxy;
|
|
7
|
+
private bundleProxy;
|
|
8
|
+
private baseDir;
|
|
9
|
+
private logger;
|
|
10
|
+
private fetchFn;
|
|
11
|
+
private pubsub;
|
|
12
|
+
private importFn;
|
|
13
|
+
constructor({ name, config, baseDir, store, pubsub, logger, importFn, }: MeshHandlerOptions<YamlConfig.OpenapiHandler>);
|
|
14
|
+
getNonExecutableSchema({ interpolatedSource }: {
|
|
15
|
+
interpolatedSource: string;
|
|
16
|
+
}): Promise<GraphQLSchema>;
|
|
17
|
+
getMeshSource({ fetchFn }: GetMeshSourcePayload): Promise<MeshSource>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { GetMeshSourcePayload, MeshHandler, MeshHandlerOptions, MeshSource, YamlConfig } from '@graphql-mesh/types';
|
|
3
|
+
export default class OpenAPIHandler implements MeshHandler {
|
|
4
|
+
private name;
|
|
5
|
+
private config;
|
|
6
|
+
private schemaWithAnnotationsProxy;
|
|
7
|
+
private bundleProxy;
|
|
8
|
+
private baseDir;
|
|
9
|
+
private logger;
|
|
10
|
+
private fetchFn;
|
|
11
|
+
private pubsub;
|
|
12
|
+
private importFn;
|
|
13
|
+
constructor({ name, config, baseDir, store, pubsub, logger, importFn, }: MeshHandlerOptions<YamlConfig.OpenapiHandler>);
|
|
14
|
+
getNonExecutableSchema({ interpolatedSource }: {
|
|
15
|
+
interpolatedSource: string;
|
|
16
|
+
}): Promise<GraphQLSchema>;
|
|
17
|
+
getMeshSource({ fetchFn }: GetMeshSourcePayload): Promise<MeshSource>;
|
|
18
|
+
}
|
package/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { MeshHandler, YamlConfig, GetMeshSourceOptions, MeshSource } from '@graphql-mesh/types';
|
|
2
|
-
export default class OpenAPIHandler implements MeshHandler {
|
|
3
|
-
private config;
|
|
4
|
-
private baseDir;
|
|
5
|
-
private fetchFn;
|
|
6
|
-
private importFn;
|
|
7
|
-
private pubsub;
|
|
8
|
-
private oasSchema;
|
|
9
|
-
private logger;
|
|
10
|
-
constructor({ name, config, baseDir, fetchFn, importFn, pubsub, store, logger, }: GetMeshSourceOptions<YamlConfig.OpenapiHandler>);
|
|
11
|
-
private getCachedSpec;
|
|
12
|
-
getMeshSource(): Promise<MeshSource>;
|
|
13
|
-
}
|