@graphql-tools/relay-operation-optimizer 6.4.15 → 6.5.0-alpha-6c480b2d.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/index.js ADDED
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.optimizeDocuments = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const utils_1 = require("@graphql-tools/utils");
6
+ const graphql_1 = require("graphql");
7
+ const SkipRedundantNodesTransform_js_1 = require("@ardatan/relay-compiler/lib/transforms/SkipRedundantNodesTransform.js");
8
+ const InlineFragmentsTransform_js_1 = require("@ardatan/relay-compiler/lib/transforms/InlineFragmentsTransform.js");
9
+ const ApplyFragmentArgumentTransform_js_1 = require("@ardatan/relay-compiler/lib/transforms/ApplyFragmentArgumentTransform.js");
10
+ const FlattenTransform_js_1 = require("@ardatan/relay-compiler/lib/transforms/FlattenTransform.js");
11
+ const CompilerContext_js_1 = tslib_1.__importDefault(require("@ardatan/relay-compiler/lib/core/CompilerContext.js"));
12
+ const RelayParser_js_1 = require("@ardatan/relay-compiler/lib/core/RelayParser.js");
13
+ const IRPrinter_js_1 = require("@ardatan/relay-compiler/lib/core/IRPrinter.js");
14
+ const Schema_js_1 = require("@ardatan/relay-compiler/lib/core/Schema.js");
15
+ function optimizeDocuments(schema, documents, options = {}) {
16
+ options = {
17
+ noLocation: true,
18
+ ...options,
19
+ };
20
+ // @TODO way for users to define directives they use, otherwise relay will throw an unknown directive error
21
+ // Maybe we can scan the queries and add them dynamically without users having to do some extra stuff
22
+ // transformASTSchema creates a new schema instance instead of mutating the old one
23
+ const adjustedSchema = (0, Schema_js_1.create)((0, utils_1.printSchemaWithDirectives)(schema, options));
24
+ const documentAsts = (0, graphql_1.concatAST)(documents);
25
+ const relayDocuments = (0, RelayParser_js_1.transform)(adjustedSchema, documentAsts.definitions);
26
+ const result = [];
27
+ if (options.includeFragments) {
28
+ const fragmentCompilerContext = new CompilerContext_js_1.default(adjustedSchema)
29
+ .addAll(relayDocuments)
30
+ .applyTransforms([
31
+ ApplyFragmentArgumentTransform_js_1.transform,
32
+ (0, FlattenTransform_js_1.transformWithOptions)({ flattenAbstractTypes: false }),
33
+ SkipRedundantNodesTransform_js_1.transform,
34
+ ]);
35
+ result.push(...fragmentCompilerContext
36
+ .documents()
37
+ .filter(doc => doc.kind === 'Fragment')
38
+ .map(doc => (0, graphql_1.parse)((0, IRPrinter_js_1.print)(adjustedSchema, doc), options)));
39
+ }
40
+ const queryCompilerContext = new CompilerContext_js_1.default(adjustedSchema)
41
+ .addAll(relayDocuments)
42
+ .applyTransforms([
43
+ ApplyFragmentArgumentTransform_js_1.transform,
44
+ InlineFragmentsTransform_js_1.transform,
45
+ (0, FlattenTransform_js_1.transformWithOptions)({ flattenAbstractTypes: false }),
46
+ SkipRedundantNodesTransform_js_1.transform,
47
+ ]);
48
+ result.push(...queryCompilerContext.documents().map(doc => (0, graphql_1.parse)((0, IRPrinter_js_1.print)(adjustedSchema, doc), options)));
49
+ return result;
50
+ }
51
+ exports.optimizeDocuments = optimizeDocuments;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
package/esm/index.js ADDED
@@ -0,0 +1,46 @@
1
+ import { printSchemaWithDirectives } from '@graphql-tools/utils';
2
+ import { parse, concatAST } from 'graphql';
3
+ import { transform as skipRedundantNodesTransform } from '@ardatan/relay-compiler/lib/transforms/SkipRedundantNodesTransform.js';
4
+ import { transform as inlineFragmentsTransform } from '@ardatan/relay-compiler/lib/transforms/InlineFragmentsTransform.js';
5
+ import { transform as applyFragmentArgumentTransform } from '@ardatan/relay-compiler/lib/transforms/ApplyFragmentArgumentTransform.js';
6
+ import { transformWithOptions as flattenTransformWithOptions } from '@ardatan/relay-compiler/lib/transforms/FlattenTransform.js';
7
+ import CompilerContext from '@ardatan/relay-compiler/lib/core/CompilerContext.js';
8
+ import { transform as relayTransform } from '@ardatan/relay-compiler/lib/core/RelayParser.js';
9
+ import { print as relayPrint } from '@ardatan/relay-compiler/lib/core/IRPrinter.js';
10
+ import { create as relayCreate } from '@ardatan/relay-compiler/lib/core/Schema.js';
11
+ export function optimizeDocuments(schema, documents, options = {}) {
12
+ options = {
13
+ noLocation: true,
14
+ ...options,
15
+ };
16
+ // @TODO way for users to define directives they use, otherwise relay will throw an unknown directive error
17
+ // Maybe we can scan the queries and add them dynamically without users having to do some extra stuff
18
+ // transformASTSchema creates a new schema instance instead of mutating the old one
19
+ const adjustedSchema = relayCreate(printSchemaWithDirectives(schema, options));
20
+ const documentAsts = concatAST(documents);
21
+ const relayDocuments = relayTransform(adjustedSchema, documentAsts.definitions);
22
+ const result = [];
23
+ if (options.includeFragments) {
24
+ const fragmentCompilerContext = new CompilerContext(adjustedSchema)
25
+ .addAll(relayDocuments)
26
+ .applyTransforms([
27
+ applyFragmentArgumentTransform,
28
+ flattenTransformWithOptions({ flattenAbstractTypes: false }),
29
+ skipRedundantNodesTransform,
30
+ ]);
31
+ result.push(...fragmentCompilerContext
32
+ .documents()
33
+ .filter(doc => doc.kind === 'Fragment')
34
+ .map(doc => parse(relayPrint(adjustedSchema, doc), options)));
35
+ }
36
+ const queryCompilerContext = new CompilerContext(adjustedSchema)
37
+ .addAll(relayDocuments)
38
+ .applyTransforms([
39
+ applyFragmentArgumentTransform,
40
+ inlineFragmentsTransform,
41
+ flattenTransformWithOptions({ flattenAbstractTypes: false }),
42
+ skipRedundantNodesTransform,
43
+ ]);
44
+ result.push(...queryCompilerContext.documents().map(doc => parse(relayPrint(adjustedSchema, doc), options)));
45
+ return result;
46
+ }
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@graphql-tools/relay-operation-optimizer",
3
- "version": "6.4.15",
3
+ "version": "6.5.0-alpha-6c480b2d.0",
4
4
  "description": "Package for optimizing your GraphQL operations relay style.",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
7
7
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
8
8
  },
9
9
  "dependencies": {
10
+ "@graphql-tools/utils": "8.8.0-alpha-6c480b2d.0",
10
11
  "@ardatan/relay-compiler": "12.0.0",
11
- "@graphql-tools/utils": "8.7.0",
12
12
  "tslib": "^2.4.0"
13
13
  },
14
14
  "repository": {
@@ -29,21 +29,42 @@
29
29
  "url": "https://github.com/n1ru4l"
30
30
  },
31
31
  "license": "MIT",
32
- "main": "index.js",
33
- "module": "index.mjs",
34
- "typings": "index.d.ts",
32
+ "main": "cjs/index.js",
33
+ "module": "esm/index.js",
34
+ "typings": "typings/index.d.ts",
35
35
  "typescript": {
36
- "definition": "index.d.ts"
36
+ "definition": "typings/index.d.ts"
37
37
  },
38
+ "type": "module",
38
39
  "exports": {
39
40
  ".": {
40
- "require": "./index.js",
41
- "import": "./index.mjs"
41
+ "require": {
42
+ "types": "./typings/index.d.ts",
43
+ "default": "./cjs/index.js"
44
+ },
45
+ "import": {
46
+ "types": "./typings/index.d.ts",
47
+ "default": "./esm/index.js"
48
+ },
49
+ "default": {
50
+ "types": "./typings/index.d.ts",
51
+ "default": "./esm/index.js"
52
+ }
42
53
  },
43
54
  "./*": {
44
- "require": "./*.js",
45
- "import": "./*.mjs"
55
+ "require": {
56
+ "types": "./typings/*.d.ts",
57
+ "default": "./cjs/*.js"
58
+ },
59
+ "import": {
60
+ "types": "./typings/*.d.ts",
61
+ "default": "./esm/*.js"
62
+ },
63
+ "default": {
64
+ "types": "./typings/*.d.ts",
65
+ "default": "./esm/*.js"
66
+ }
46
67
  },
47
68
  "./package.json": "./package.json"
48
69
  }
49
- }
70
+ }
File without changes
package/index.js DELETED
@@ -1,55 +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 utils = require('@graphql-tools/utils');
8
- const graphql = require('graphql');
9
- const SkipRedundantNodesTransform_js = require('@ardatan/relay-compiler/lib/transforms/SkipRedundantNodesTransform.js');
10
- const InlineFragmentsTransform_js = require('@ardatan/relay-compiler/lib/transforms/InlineFragmentsTransform.js');
11
- const ApplyFragmentArgumentTransform_js = require('@ardatan/relay-compiler/lib/transforms/ApplyFragmentArgumentTransform.js');
12
- const FlattenTransform_js = require('@ardatan/relay-compiler/lib/transforms/FlattenTransform.js');
13
- const CompilerContext = _interopDefault(require('@ardatan/relay-compiler/lib/core/CompilerContext.js'));
14
- const RelayParser_js = require('@ardatan/relay-compiler/lib/core/RelayParser.js');
15
- const IRPrinter_js = require('@ardatan/relay-compiler/lib/core/IRPrinter.js');
16
- const Schema_js = require('@ardatan/relay-compiler/lib/core/Schema.js');
17
-
18
- function optimizeDocuments(schema, documents, options = {}) {
19
- options = {
20
- noLocation: true,
21
- ...options,
22
- };
23
- // @TODO way for users to define directives they use, otherwise relay will throw an unknown directive error
24
- // Maybe we can scan the queries and add them dynamically without users having to do some extra stuff
25
- // transformASTSchema creates a new schema instance instead of mutating the old one
26
- const adjustedSchema = Schema_js.create(utils.printSchemaWithDirectives(schema, options));
27
- const documentAsts = graphql.concatAST(documents);
28
- const relayDocuments = RelayParser_js.transform(adjustedSchema, documentAsts.definitions);
29
- const result = [];
30
- if (options.includeFragments) {
31
- const fragmentCompilerContext = new CompilerContext(adjustedSchema)
32
- .addAll(relayDocuments)
33
- .applyTransforms([
34
- ApplyFragmentArgumentTransform_js.transform,
35
- FlattenTransform_js.transformWithOptions({ flattenAbstractTypes: false }),
36
- SkipRedundantNodesTransform_js.transform,
37
- ]);
38
- result.push(...fragmentCompilerContext
39
- .documents()
40
- .filter(doc => doc.kind === 'Fragment')
41
- .map(doc => graphql.parse(IRPrinter_js.print(adjustedSchema, doc), options)));
42
- }
43
- const queryCompilerContext = new CompilerContext(adjustedSchema)
44
- .addAll(relayDocuments)
45
- .applyTransforms([
46
- ApplyFragmentArgumentTransform_js.transform,
47
- InlineFragmentsTransform_js.transform,
48
- FlattenTransform_js.transformWithOptions({ flattenAbstractTypes: false }),
49
- SkipRedundantNodesTransform_js.transform,
50
- ]);
51
- result.push(...queryCompilerContext.documents().map(doc => graphql.parse(IRPrinter_js.print(adjustedSchema, doc), options)));
52
- return result;
53
- }
54
-
55
- exports.optimizeDocuments = optimizeDocuments;
package/index.mjs DELETED
@@ -1,49 +0,0 @@
1
- import { printSchemaWithDirectives } from '@graphql-tools/utils';
2
- import { concatAST, parse } from 'graphql';
3
- import { transform as transform$2 } from '@ardatan/relay-compiler/lib/transforms/SkipRedundantNodesTransform.js';
4
- import { transform as transform$3 } from '@ardatan/relay-compiler/lib/transforms/InlineFragmentsTransform.js';
5
- import { transform as transform$1 } from '@ardatan/relay-compiler/lib/transforms/ApplyFragmentArgumentTransform.js';
6
- import { transformWithOptions } from '@ardatan/relay-compiler/lib/transforms/FlattenTransform.js';
7
- import CompilerContext from '@ardatan/relay-compiler/lib/core/CompilerContext.js';
8
- import { transform } from '@ardatan/relay-compiler/lib/core/RelayParser.js';
9
- import { print } from '@ardatan/relay-compiler/lib/core/IRPrinter.js';
10
- import { create } from '@ardatan/relay-compiler/lib/core/Schema.js';
11
-
12
- function optimizeDocuments(schema, documents, options = {}) {
13
- options = {
14
- noLocation: true,
15
- ...options,
16
- };
17
- // @TODO way for users to define directives they use, otherwise relay will throw an unknown directive error
18
- // Maybe we can scan the queries and add them dynamically without users having to do some extra stuff
19
- // transformASTSchema creates a new schema instance instead of mutating the old one
20
- const adjustedSchema = create(printSchemaWithDirectives(schema, options));
21
- const documentAsts = concatAST(documents);
22
- const relayDocuments = transform(adjustedSchema, documentAsts.definitions);
23
- const result = [];
24
- if (options.includeFragments) {
25
- const fragmentCompilerContext = new CompilerContext(adjustedSchema)
26
- .addAll(relayDocuments)
27
- .applyTransforms([
28
- transform$1,
29
- transformWithOptions({ flattenAbstractTypes: false }),
30
- transform$2,
31
- ]);
32
- result.push(...fragmentCompilerContext
33
- .documents()
34
- .filter(doc => doc.kind === 'Fragment')
35
- .map(doc => parse(print(adjustedSchema, doc), options)));
36
- }
37
- const queryCompilerContext = new CompilerContext(adjustedSchema)
38
- .addAll(relayDocuments)
39
- .applyTransforms([
40
- transform$1,
41
- transform$3,
42
- transformWithOptions({ flattenAbstractTypes: false }),
43
- transform$2,
44
- ]);
45
- result.push(...queryCompilerContext.documents().map(doc => parse(print(adjustedSchema, doc), options)));
46
- return result;
47
- }
48
-
49
- export { optimizeDocuments };