@graphql-mesh/raml 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/index.js ADDED
@@ -0,0 +1,91 @@
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 raml_1 = require("@omnigraph/raml");
8
+ class RAMLHandler {
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.bundleProxy = store.proxy('jsonSchemaBundle', store_1.PredefinedProxyOptions.JsonWithoutValidation);
15
+ this.pubsub = pubsub;
16
+ this.importFn = importFn;
17
+ this.logger = logger;
18
+ }
19
+ async getNonExecutableSchema() {
20
+ if (this.config.source.endsWith('.graphql')) {
21
+ this.logger.info(`Fetching GraphQL Schema with annotations`);
22
+ const sdl = await (0, utils_1.readFileOrUrl)(this.config.source, {
23
+ allowUnknownExtensions: true,
24
+ cwd: this.baseDir,
25
+ fetch: this.fetchFn,
26
+ importFn: this.importFn,
27
+ logger: this.logger,
28
+ headers: this.config.schemaHeaders,
29
+ });
30
+ return (0, graphql_1.buildSchema)(sdl, {
31
+ assumeValidSDL: true,
32
+ assumeValid: true,
33
+ });
34
+ }
35
+ return this.schemaWithAnnotationsProxy.getWithSet(async () => {
36
+ var _a;
37
+ this.logger.info(`Generating GraphQL schema from RAML schema`);
38
+ const schema = await (0, raml_1.loadNonExecutableGraphQLSchemaFromRAML)(this.name, {
39
+ ...this.config,
40
+ cwd: this.baseDir,
41
+ fetch: this.fetchFn,
42
+ logger: this.logger,
43
+ ignoreErrorResponses: this.config.ignoreErrorResponses,
44
+ selectQueryOrMutationField: (_a = this.config.selectQueryOrMutationField) === null || _a === void 0 ? void 0 : _a.map(({ type, fieldName }) => ({
45
+ type: type.toLowerCase(),
46
+ fieldName,
47
+ })),
48
+ pubsub: this.pubsub,
49
+ bundle: this.config.bundle,
50
+ });
51
+ if (this.config.bundle) {
52
+ await this.bundleProxy.set(schema.extensions.bundle);
53
+ }
54
+ return schema;
55
+ });
56
+ }
57
+ async getMeshSource({ fetchFn }) {
58
+ this.fetchFn = fetchFn;
59
+ this.logger.debug('Getting the schema with annotations');
60
+ const nonExecutableSchema = await this.getNonExecutableSchema();
61
+ const schemaWithDirectives$ = Promise.resolve().then(() => {
62
+ this.logger.info(`Processing annotations for the execution layer`);
63
+ return (0, raml_1.processDirectives)({
64
+ ...this.config,
65
+ schema: nonExecutableSchema,
66
+ pubsub: this.pubsub,
67
+ logger: this.logger,
68
+ globalFetch: fetchFn,
69
+ });
70
+ });
71
+ return {
72
+ schema: nonExecutableSchema,
73
+ executor: async (executionRequest) => {
74
+ const args = {
75
+ schema: await schemaWithDirectives$,
76
+ document: executionRequest.document,
77
+ variableValues: executionRequest.variables,
78
+ operationName: executionRequest.operationName,
79
+ contextValue: executionRequest.context,
80
+ rootValue: executionRequest.rootValue,
81
+ };
82
+ const operationAST = (0, utils_2.getOperationASTFromRequest)(executionRequest);
83
+ if (operationAST.operation === graphql_1.OperationTypeNode.SUBSCRIPTION) {
84
+ return (0, graphql_1.subscribe)(args);
85
+ }
86
+ return (0, graphql_1.execute)(args);
87
+ },
88
+ };
89
+ }
90
+ }
91
+ exports.default = RAMLHandler;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
package/esm/index.js ADDED
@@ -0,0 +1,88 @@
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 { loadNonExecutableGraphQLSchemaFromRAML, processDirectives } from '@omnigraph/raml';
6
+ export default class RAMLHandler {
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.bundleProxy = store.proxy('jsonSchemaBundle', PredefinedProxyOptions.JsonWithoutValidation);
13
+ this.pubsub = pubsub;
14
+ this.importFn = importFn;
15
+ this.logger = logger;
16
+ }
17
+ async getNonExecutableSchema() {
18
+ if (this.config.source.endsWith('.graphql')) {
19
+ this.logger.info(`Fetching GraphQL Schema with annotations`);
20
+ const sdl = await readFileOrUrl(this.config.source, {
21
+ allowUnknownExtensions: true,
22
+ cwd: this.baseDir,
23
+ fetch: this.fetchFn,
24
+ importFn: this.importFn,
25
+ logger: this.logger,
26
+ headers: this.config.schemaHeaders,
27
+ });
28
+ return buildSchema(sdl, {
29
+ assumeValidSDL: true,
30
+ assumeValid: true,
31
+ });
32
+ }
33
+ return this.schemaWithAnnotationsProxy.getWithSet(async () => {
34
+ var _a;
35
+ this.logger.info(`Generating GraphQL schema from RAML schema`);
36
+ const schema = await loadNonExecutableGraphQLSchemaFromRAML(this.name, {
37
+ ...this.config,
38
+ cwd: this.baseDir,
39
+ fetch: this.fetchFn,
40
+ logger: this.logger,
41
+ ignoreErrorResponses: this.config.ignoreErrorResponses,
42
+ selectQueryOrMutationField: (_a = this.config.selectQueryOrMutationField) === null || _a === void 0 ? void 0 : _a.map(({ type, fieldName }) => ({
43
+ type: type.toLowerCase(),
44
+ fieldName,
45
+ })),
46
+ pubsub: this.pubsub,
47
+ bundle: this.config.bundle,
48
+ });
49
+ if (this.config.bundle) {
50
+ await this.bundleProxy.set(schema.extensions.bundle);
51
+ }
52
+ return schema;
53
+ });
54
+ }
55
+ async getMeshSource({ fetchFn }) {
56
+ this.fetchFn = fetchFn;
57
+ this.logger.debug('Getting the schema with annotations');
58
+ const nonExecutableSchema = await this.getNonExecutableSchema();
59
+ const schemaWithDirectives$ = Promise.resolve().then(() => {
60
+ this.logger.info(`Processing annotations for the execution layer`);
61
+ return processDirectives({
62
+ ...this.config,
63
+ schema: nonExecutableSchema,
64
+ pubsub: this.pubsub,
65
+ logger: this.logger,
66
+ globalFetch: fetchFn,
67
+ });
68
+ });
69
+ return {
70
+ schema: nonExecutableSchema,
71
+ executor: async (executionRequest) => {
72
+ const args = {
73
+ schema: await schemaWithDirectives$,
74
+ document: executionRequest.document,
75
+ variableValues: executionRequest.variables,
76
+ operationName: executionRequest.operationName,
77
+ contextValue: executionRequest.context,
78
+ rootValue: executionRequest.rootValue,
79
+ };
80
+ const operationAST = getOperationASTFromRequest(executionRequest);
81
+ if (operationAST.operation === OperationTypeNode.SUBSCRIPTION) {
82
+ return subscribe(args);
83
+ }
84
+ return execute(args);
85
+ },
86
+ };
87
+ }
88
+ }
package/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "@graphql-mesh/raml",
3
- "version": "1.0.0-alpha-3fc47d119.0",
3
+ "version": "1.0.0-alpha-20230420181317-a95037648",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@graphql-mesh/types": "0.79.0-alpha-3fc47d119.0",
7
- "@graphql-mesh/utils": "1.0.0-alpha-3fc47d119.0",
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/store": "1.0.0-alpha-3fc47d119.0",
12
- "@omnigraph/raml": "1.0.0-alpha-3fc47d119.0",
13
- "tslib": "^2.4.0"
14
+ "@omnigraph/raml": "1.0.0-alpha-20230420181317-a95037648"
14
15
  },
15
16
  "repository": {
16
17
  "type": "git",
@@ -18,21 +19,28 @@
18
19
  "directory": "packages/handlers/raml"
19
20
  },
20
21
  "license": "MIT",
21
- "main": "index.js",
22
- "module": "index.mjs",
23
- "typings": "index.d.ts",
22
+ "main": "cjs/index.js",
23
+ "module": "esm/index.js",
24
+ "typings": "typings/index.d.ts",
24
25
  "typescript": {
25
- "definition": "index.d.ts"
26
+ "definition": "typings/index.d.ts"
26
27
  },
28
+ "type": "module",
27
29
  "exports": {
28
30
  ".": {
29
- "require": "./index.js",
30
- "import": "./index.mjs"
31
- },
32
- "./*": {
33
- "require": "./*.js",
34
- "import": "./*.mjs"
31
+ "require": {
32
+ "types": "./typings/index.d.cts",
33
+ "default": "./cjs/index.js"
34
+ },
35
+ "import": {
36
+ "types": "./typings/index.d.ts",
37
+ "default": "./esm/index.js"
38
+ },
39
+ "default": {
40
+ "types": "./typings/index.d.ts",
41
+ "default": "./esm/index.js"
42
+ }
35
43
  },
36
44
  "./package.json": "./package.json"
37
45
  }
38
- }
46
+ }
@@ -0,0 +1,16 @@
1
+ import { GraphQLSchema } from 'graphql';
2
+ import { GetMeshSourcePayload, MeshHandler, MeshHandlerOptions, MeshSource, YamlConfig } from '@graphql-mesh/types';
3
+ export default class RAMLHandler 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.RAMLHandler>);
14
+ getNonExecutableSchema(): Promise<GraphQLSchema>;
15
+ getMeshSource({ fetchFn }: GetMeshSourcePayload): Promise<MeshSource>;
16
+ }
@@ -0,0 +1,16 @@
1
+ import { GraphQLSchema } from 'graphql';
2
+ import { GetMeshSourcePayload, MeshHandler, MeshHandlerOptions, MeshSource, YamlConfig } from '@graphql-mesh/types';
3
+ export default class RAMLHandler 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.RAMLHandler>);
14
+ getNonExecutableSchema(): Promise<GraphQLSchema>;
15
+ getMeshSource({ fetchFn }: GetMeshSourcePayload): Promise<MeshSource>;
16
+ }
package/index.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import { GetMeshSourceOptions, MeshHandler, MeshSource, YamlConfig } from '@graphql-mesh/types';
2
- import { RAMLLoaderBundle } from '@omnigraph/raml';
3
- export default class RAMLHandler implements MeshHandler {
4
- private name;
5
- private config;
6
- private bundleStoreProxy;
7
- private baseDir;
8
- private logger;
9
- private fetch;
10
- private pubsub;
11
- constructor({ name, config, baseDir, fetchFn, store, pubsub, logger }: GetMeshSourceOptions<YamlConfig.RAMLHandler>);
12
- getDereferencedBundle(): Promise<RAMLLoaderBundle>;
13
- getMeshSource(): Promise<MeshSource>;
14
- }
package/index.js DELETED
@@ -1,48 +0,0 @@
1
- 'use strict';
2
-
3
- const store = require('@graphql-mesh/store');
4
- const raml = require('@omnigraph/raml');
5
-
6
- class RAMLHandler {
7
- constructor({ name, config, baseDir, fetchFn, store: store$1, pubsub, logger }) {
8
- this.name = name;
9
- this.config = config;
10
- this.baseDir = baseDir;
11
- this.fetch = fetchFn;
12
- this.bundleStoreProxy = store$1.proxy('jsonSchemaBundle', store.PredefinedProxyOptions.JsonWithoutValidation);
13
- this.pubsub = pubsub;
14
- this.logger = logger;
15
- }
16
- async getDereferencedBundle() {
17
- return this.bundleStoreProxy.getWithSet(() => {
18
- var _a;
19
- return raml.createBundle(this.name, {
20
- ...this.config,
21
- cwd: this.baseDir,
22
- fetch: this.fetch,
23
- logger: this.logger,
24
- ignoreErrorResponses: this.config.ignoreErrorResponses,
25
- selectQueryOrMutationField: (_a = this.config.selectQueryOrMutationField) === null || _a === void 0 ? void 0 : _a.map(({ type, fieldName }) => ({
26
- type: type.toLowerCase(),
27
- fieldName,
28
- })),
29
- });
30
- });
31
- }
32
- async getMeshSource() {
33
- const bundle = await this.getDereferencedBundle();
34
- const schema = await raml.getGraphQLSchemaFromBundle(bundle, {
35
- cwd: this.baseDir,
36
- fetch: this.fetch,
37
- pubsub: this.pubsub,
38
- logger: this.logger,
39
- baseUrl: this.config.baseUrl,
40
- operationHeaders: this.config.operationHeaders,
41
- });
42
- return {
43
- schema,
44
- };
45
- }
46
- }
47
-
48
- module.exports = RAMLHandler;
package/index.mjs DELETED
@@ -1,46 +0,0 @@
1
- import { PredefinedProxyOptions } from '@graphql-mesh/store';
2
- import { createBundle, getGraphQLSchemaFromBundle } from '@omnigraph/raml';
3
-
4
- class RAMLHandler {
5
- constructor({ name, config, baseDir, fetchFn, store, pubsub, logger }) {
6
- this.name = name;
7
- this.config = config;
8
- this.baseDir = baseDir;
9
- this.fetch = fetchFn;
10
- this.bundleStoreProxy = store.proxy('jsonSchemaBundle', PredefinedProxyOptions.JsonWithoutValidation);
11
- this.pubsub = pubsub;
12
- this.logger = logger;
13
- }
14
- async getDereferencedBundle() {
15
- return this.bundleStoreProxy.getWithSet(() => {
16
- var _a;
17
- return createBundle(this.name, {
18
- ...this.config,
19
- cwd: this.baseDir,
20
- fetch: this.fetch,
21
- logger: this.logger,
22
- ignoreErrorResponses: this.config.ignoreErrorResponses,
23
- selectQueryOrMutationField: (_a = this.config.selectQueryOrMutationField) === null || _a === void 0 ? void 0 : _a.map(({ type, fieldName }) => ({
24
- type: type.toLowerCase(),
25
- fieldName,
26
- })),
27
- });
28
- });
29
- }
30
- async getMeshSource() {
31
- const bundle = await this.getDereferencedBundle();
32
- const schema = await getGraphQLSchemaFromBundle(bundle, {
33
- cwd: this.baseDir,
34
- fetch: this.fetch,
35
- pubsub: this.pubsub,
36
- logger: this.logger,
37
- baseUrl: this.config.baseUrl,
38
- operationHeaders: this.config.operationHeaders,
39
- });
40
- return {
41
- schema,
42
- };
43
- }
44
- }
45
-
46
- export default RAMLHandler;