@graphcommerce/graphql-codegen-relay-optimizer-plugin 2.101.1 → 2.102.1

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.
@@ -11,7 +11,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
11
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
- exports.__esModule = true;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.plugin = void 0;
16
16
  var graphql_1 = require("graphql");
17
17
  var relay_compiler_1 = require("relay-compiler");
@@ -28,8 +28,8 @@ function isFragment(documentFile) {
28
28
  enter: {
29
29
  FragmentDefinition: function () {
30
30
  name = true;
31
- }
32
- }
31
+ },
32
+ },
33
33
  });
34
34
  return name;
35
35
  }
@@ -45,7 +45,7 @@ var plugin = function (schema, documents, _config) {
45
45
  ]);
46
46
  var documentAsts = documents.reduce(function (prev, v) { var _a, _b; return __spreadArray(__spreadArray([], prev, true), ((_b = (_a = v.document) === null || _a === void 0 ? void 0 : _a.definitions) !== null && _b !== void 0 ? _b : []), true); }, []);
47
47
  var relayDocuments = relay_compiler_1.Parser.transform(adjustedSchema, documentAsts);
48
- var fragmentCompilerContext = new CompilerContext_1["default"](adjustedSchema).addAll(relayDocuments);
48
+ var fragmentCompilerContext = new CompilerContext_1.default(adjustedSchema).addAll(relayDocuments);
49
49
  var fragmentDocuments = fragmentCompilerContext
50
50
  .applyTransforms([
51
51
  ApplyFragmentArgumentTransform_1.transform,
@@ -54,7 +54,7 @@ var plugin = function (schema, documents, _config) {
54
54
  ])
55
55
  .documents()
56
56
  .filter(function (doc) { return doc.kind === 'Fragment'; });
57
- var queryCompilerContext = new CompilerContext_1["default"](adjustedSchema)
57
+ var queryCompilerContext = new CompilerContext_1.default(adjustedSchema)
58
58
  .addAll(relayDocuments)
59
59
  .applyTransforms([
60
60
  ApplyFragmentArgumentTransform_1.transform,
@@ -64,7 +64,7 @@ var plugin = function (schema, documents, _config) {
64
64
  ]);
65
65
  var newQueryDocuments = queryCompilerContext.documents().map(function (doc) { return ({
66
66
  location: 'optimized by relay',
67
- document: (0, graphql_1.parse)((0, IRPrinter_1.print)(adjustedSchema, doc))
67
+ document: (0, graphql_1.parse)((0, IRPrinter_1.print)(adjustedSchema, doc)),
68
68
  }); });
69
69
  var newDocuments = [];
70
70
  if (newQueryDocuments.length === 0) {
@@ -76,14 +76,13 @@ var plugin = function (schema, documents, _config) {
76
76
  else {
77
77
  newDocuments = __spreadArray(__spreadArray([], fragmentDocuments.map(function (doc) { return ({
78
78
  location: 'optimized by relay',
79
- document: (0, graphql_1.parse)((0, IRPrinter_1.print)(adjustedSchema, doc))
79
+ document: (0, graphql_1.parse)((0, IRPrinter_1.print)(adjustedSchema, doc)),
80
80
  }); }), true), newQueryDocuments, true);
81
81
  }
82
82
  documents.splice(0, documents.length);
83
83
  documents.push.apply(documents, newDocuments);
84
84
  return {
85
- content: ''
85
+ content: '',
86
86
  };
87
87
  };
88
88
  exports.plugin = plugin;
89
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphcommerce/graphql-codegen-relay-optimizer-plugin",
3
- "version": "2.101.1",
3
+ "version": "2.102.1",
4
4
  "description": "GraphQL Code Generator plugin for optimizing your GraphQL queries relay style.",
5
5
  "license": "MIT",
6
6
  "main": "dist/main/index.js",
@@ -17,25 +17,26 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@graphql-codegen/plugin-helpers": "2.1.1",
20
- "relay-compiler": "11.0.2"
20
+ "relay-compiler": "12.0.0"
21
21
  },
22
22
  "devDependencies": {
23
- "@graphcommerce/eslint-config-pwa": "^3.0.1",
24
- "@graphcommerce/prettier-config-pwa": "^3.0.1",
23
+ "@graphcommerce/eslint-config-pwa": "^3.0.3",
24
+ "@graphcommerce/prettier-config-pwa": "^3.0.2",
25
25
  "@graphql-codegen/testing": "1.17.7",
26
- "@types/jest": "27.0.1",
26
+ "@types/jest": "27.0.2",
27
27
  "@types/relay-compiler": "8.0.1",
28
- "graphql": "^15.5.2",
29
- "jest": "27.1.0",
28
+ "graphql": "^15.6.0",
29
+ "jest": "27.2.2",
30
30
  "ts-jest": "27.0.5",
31
- "typescript": "^4.4.2"
31
+ "typescript": "^4.4.3"
32
32
  },
33
33
  "scripts": {
34
34
  "test": "jest",
35
35
  "dev": "tsc --preserveWatchOutput --watch --sourceMap --outDir dist/main",
36
36
  "build:module": "tsc --target es2017 --outDir dist/module",
37
37
  "build:main": "tsc --target es5 --outDir dist/main",
38
- "build": "yarn build:module && yarn build:main"
38
+ "build": "yarn build:module && yarn build:main",
39
+ "prepack": "yarn build"
39
40
  },
40
41
  "prettier": "@graphcommerce/prettier-config-pwa",
41
42
  "browserslist": [
@@ -52,7 +53,9 @@
52
53
  },
53
54
  "files": [
54
55
  "dist/**/*",
56
+ "src",
55
57
  "LICENSE",
56
58
  "README.md"
57
- ]
59
+ ],
60
+ "gitHead": "ed8f1dac5728eefc510285da312295a0e791750b"
58
61
  }
@@ -1,10 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
1
  /* eslint-disable @typescript-eslint/ban-ts-ignore */
4
- require("@graphql-codegen/testing");
5
- const graphql_1 = require("graphql");
6
- const __1 = require("..");
7
- const testSchema = (0, graphql_1.buildSchema)(/* GraphQL */ `
2
+ import '@graphql-codegen/testing'
3
+
4
+ import { Types } from '@graphql-codegen/plugin-helpers'
5
+ import { buildSchema, parse, print, ASTNode } from 'graphql'
6
+ import { plugin } from '..'
7
+
8
+ const testSchema = buildSchema(/* GraphQL */ `
8
9
  type Avatar {
9
10
  id: ID!
10
11
  url: String!
@@ -20,31 +21,34 @@ const testSchema = (0, graphql_1.buildSchema)(/* GraphQL */ `
20
21
  user: User!
21
22
  users: [User!]!
22
23
  }
23
- `);
24
+ `)
25
+
24
26
  // eslint-disable-next-line jest/expect-expect
25
27
  it('can be called', async () => {
26
- const testDocument = (0, graphql_1.parse)(/* GraphQL */ `
28
+ const testDocument = parse(/* GraphQL */ `
27
29
  query user {
28
30
  user {
29
31
  id
30
32
  }
31
33
  }
32
- `);
33
- await (0, __1.plugin)(testSchema, [{ document: testDocument }], {});
34
- });
34
+ `)
35
+ await plugin(testSchema, [{ document: testDocument }], {})
36
+ })
37
+
35
38
  // eslint-disable-next-line jest/expect-expect
36
39
  it('can be called with queries that include connection fragments', async () => {
37
- const testDocument = (0, graphql_1.parse)(/* GraphQL */ `
40
+ const testDocument = parse(/* GraphQL */ `
38
41
  query user {
39
42
  users @connection(key: "foo") {
40
43
  id
41
44
  }
42
45
  }
43
- `);
44
- await (0, __1.plugin)(testSchema, [{ document: testDocument }], {});
45
- });
46
+ `)
47
+ await plugin(testSchema, [{ document: testDocument }], {})
48
+ })
49
+
46
50
  it('can inline @argumentDefinitions/@arguments annotated fragments', async () => {
47
- const fragmentDocument = (0, graphql_1.parse)(/* GraphQL */ `
51
+ const fragmentDocument = parse(/* GraphQL */ `
48
52
  fragment UserLogin on User
49
53
  @argumentDefinitions(
50
54
  height: { type: "Int", defaultValue: 10 }
@@ -57,19 +61,20 @@ it('can inline @argumentDefinitions/@arguments annotated fragments', async () =>
57
61
  url
58
62
  }
59
63
  }
60
- `);
61
- const queryDocument = (0, graphql_1.parse)(/* GraphQL */ `
64
+ `)
65
+ const queryDocument = parse(/* GraphQL */ `
62
66
  query user {
63
67
  users {
64
68
  ...UserLogin @arguments(height: 30, width: 30)
65
69
  }
66
70
  }
67
- `);
68
- const input = [{ document: fragmentDocument }, { document: queryDocument }];
69
- await (0, __1.plugin)(testSchema, input, {});
70
- const queryDoc = input.find((doc) => { var _a; return ((_a = doc.document) === null || _a === void 0 ? void 0 : _a.definitions[0].kind) === 'OperationDefinition'; });
71
- expect(queryDoc).toBeDefined();
72
- expect((0, graphql_1.print)(queryDoc === null || queryDoc === void 0 ? void 0 : queryDoc.document)).toBeSimilarStringTo(/* GraphQL */ `
71
+ `)
72
+ const input: Types.DocumentFile[] = [{ document: fragmentDocument }, { document: queryDocument }]
73
+ await plugin(testSchema, input, {})
74
+ const queryDoc = input.find((doc) => doc.document?.definitions[0].kind === 'OperationDefinition')
75
+
76
+ expect(queryDoc).toBeDefined()
77
+ expect(print(queryDoc?.document as ASTNode)).toBeSimilarStringTo(/* GraphQL */ `
73
78
  query user {
74
79
  users {
75
80
  id
@@ -80,10 +85,11 @@ it('can inline @argumentDefinitions/@arguments annotated fragments', async () =>
80
85
  }
81
86
  }
82
87
  }
83
- `);
84
- });
88
+ `)
89
+ })
90
+
85
91
  it('handles unions with interfaces the correct way', async () => {
86
- const schema = (0, graphql_1.buildSchema)(/* GraphQL */ `
92
+ const schema = buildSchema(/* GraphQL */ `
87
93
  type User {
88
94
  id: ID!
89
95
  login: String!
@@ -106,8 +112,9 @@ it('handles unions with interfaces the correct way', async () => {
106
112
  type Query {
107
113
  user: UserResult!
108
114
  }
109
- `);
110
- const queryDocument = (0, graphql_1.parse)(/* GraphQL */ `
115
+ `)
116
+
117
+ const queryDocument = parse(/* GraphQL */ `
111
118
  query user {
112
119
  user {
113
120
  ... on User {
@@ -119,12 +126,14 @@ it('handles unions with interfaces the correct way', async () => {
119
126
  }
120
127
  }
121
128
  }
122
- `);
123
- const input = [{ document: queryDocument }];
124
- await (0, __1.plugin)(schema, input, {});
125
- const queryDoc = input.find((doc) => { var _a; return ((_a = doc.document) === null || _a === void 0 ? void 0 : _a.definitions[0].kind) === 'OperationDefinition'; });
126
- expect(queryDoc).toBeDefined();
127
- expect((0, graphql_1.print)(queryDoc === null || queryDoc === void 0 ? void 0 : queryDoc.document)).toBeSimilarStringTo(/* GraphQL */ `
129
+ `)
130
+
131
+ const input: Types.DocumentFile[] = [{ document: queryDocument }]
132
+ await plugin(schema, input, {})
133
+ const queryDoc = input.find((doc) => doc.document?.definitions[0].kind === 'OperationDefinition')
134
+
135
+ expect(queryDoc).toBeDefined()
136
+ expect(print(queryDoc?.document as ASTNode)).toBeSimilarStringTo(/* GraphQL */ `
128
137
  query user {
129
138
  user {
130
139
  ... on User {
@@ -136,5 +145,5 @@ it('handles unions with interfaces the correct way', async () => {
136
145
  }
137
146
  }
138
147
  }
139
- `);
140
- });
148
+ `)
149
+ })
package/src/index.ts ADDED
@@ -0,0 +1,104 @@
1
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
+ import { Types, PluginFunction } from '@graphql-codegen/plugin-helpers'
3
+ import { GraphQLSchema, parse, printSchema, DefinitionNode, visit } from 'graphql'
4
+
5
+ import { Parser as RelayParser } from 'relay-compiler'
6
+ import CompilerContext from 'relay-compiler/lib/core/CompilerContext'
7
+ import { print as relayPrint } from 'relay-compiler/lib/core/IRPrinter'
8
+ import { create as relayCreate } from 'relay-compiler/lib/core/Schema'
9
+
10
+ import { transform as applyFragmentArgumentTransform } from 'relay-compiler/lib/transforms/ApplyFragmentArgumentTransform'
11
+ import { transformWithOptions as flattenTransformWithOptions } from 'relay-compiler/lib/transforms/FlattenTransform'
12
+ import { transform as inlineFragmentsTransform } from 'relay-compiler/lib/transforms/InlineFragmentsTransform'
13
+ import { transform as skipRedundantNodesTransform } from 'relay-compiler/lib/transforms/SkipRedundantNodesTransform'
14
+
15
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
16
+ export interface RelayOptimizerPluginConfig {}
17
+
18
+ function isFragment(documentFile: Types.DocumentFile) {
19
+ let name = false
20
+
21
+ visit(documentFile.document!, {
22
+ enter: {
23
+ FragmentDefinition: () => {
24
+ name = true
25
+ },
26
+ },
27
+ })
28
+ return name
29
+ }
30
+
31
+ export const plugin: PluginFunction<RelayOptimizerPluginConfig> = (
32
+ schema: GraphQLSchema,
33
+ documents: Types.DocumentFile[],
34
+ _config: RelayOptimizerPluginConfig,
35
+ ) => {
36
+ const isFrag = documents.every((d) => isFragment(d))
37
+
38
+ if (isFrag) return { content: '' }
39
+
40
+ // @TODO way for users to define directives they use, otherwise relay will throw an unknown directive error
41
+ // Maybe we can scan the queries and add them dynamically without users having to do some extra stuff
42
+ // transformASTSchema creates a new schema instance instead of mutating the old one
43
+ const adjustedSchema = relayCreate(printSchema(schema)).extend([
44
+ /* GraphQL */ `
45
+ directive @connection(key: String!, filter: [String!]) on FIELD
46
+ directive @client on FIELD
47
+ `,
48
+ ])
49
+
50
+ const documentAsts = documents.reduce(
51
+ (prev, v) => [...prev, ...(v.document?.definitions ?? [])],
52
+ [] as DefinitionNode[],
53
+ )
54
+
55
+ const relayDocuments = RelayParser.transform(adjustedSchema, documentAsts)
56
+
57
+ const fragmentCompilerContext = new CompilerContext(adjustedSchema).addAll(relayDocuments)
58
+
59
+ const fragmentDocuments = fragmentCompilerContext
60
+ .applyTransforms([
61
+ applyFragmentArgumentTransform,
62
+ flattenTransformWithOptions({ flattenAbstractTypes: false }),
63
+ skipRedundantNodesTransform,
64
+ ])
65
+ .documents()
66
+ .filter((doc) => doc.kind === 'Fragment')
67
+
68
+ const queryCompilerContext = new CompilerContext(adjustedSchema)
69
+ .addAll(relayDocuments)
70
+ .applyTransforms([
71
+ applyFragmentArgumentTransform,
72
+ inlineFragmentsTransform,
73
+ flattenTransformWithOptions({ flattenAbstractTypes: false }),
74
+ skipRedundantNodesTransform,
75
+ ])
76
+
77
+ const newQueryDocuments: Types.DocumentFile[] = queryCompilerContext.documents().map((doc) => ({
78
+ location: 'optimized by relay',
79
+ document: parse(relayPrint(adjustedSchema, doc)),
80
+ }))
81
+
82
+ let newDocuments: Types.DocumentFile[] = []
83
+ if (newQueryDocuments.length === 0) {
84
+ return { content: '' }
85
+ }
86
+ if (newQueryDocuments.length === 1) {
87
+ newDocuments = newQueryDocuments
88
+ } else {
89
+ newDocuments = [
90
+ ...fragmentDocuments.map((doc) => ({
91
+ location: 'optimized by relay',
92
+ document: parse(relayPrint(adjustedSchema, doc)),
93
+ })),
94
+ ...newQueryDocuments,
95
+ ]
96
+ }
97
+
98
+ documents.splice(0, documents.length)
99
+ documents.push(...newDocuments)
100
+
101
+ return {
102
+ content: '',
103
+ }
104
+ }
package/src/tyes.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ declare module 'relay-compiler/lib/core/Schema' {
2
+ export function create(schema: string): import('relay-compiler').Schema
3
+ }
4
+
5
+ declare module 'relay-compiler/lib/core/IRPrinter' {
6
+ export function print(schema: import('relay-compiler').Schema, document: any): string
7
+ }
8
+
9
+ declare module 'relay-compiler/lib/core/CompilerContext' {
10
+ let CompilerContext: typeof import('relay-compiler').CompilerContext
11
+ export = CompilerContext
12
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,mCAAkF;AAElF,iDAAsD;AACtD,4FAAqE;AACrE,+DAAuE;AACvE,yDAAsE;AAEtE,+GAA0H;AAC1H,mFAAoH;AACpH,mGAA8G;AAC9G,yGAAoH;AAKpH,SAAS,UAAU,CAAC,YAAgC;IAClD,IAAI,IAAI,GAAG,KAAK,CAAA;IAEhB,IAAA,eAAK,EAAC,YAAY,CAAC,QAAS,EAAE;QAC5B,KAAK,EAAE;YACL,kBAAkB,EAAE;gBAClB,IAAI,GAAG,IAAI,CAAA;YACb,CAAC;SACF;KACF,CAAC,CAAA;IACF,OAAO,IAAI,CAAA;AACb,CAAC;AAEM,IAAM,MAAM,GAA+C,UAChE,MAAqB,EACrB,SAA+B,EAC/B,OAAmC;IAEnC,IAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,UAAC,CAAC,IAAK,OAAA,UAAU,CAAC,CAAC,CAAC,EAAb,CAAa,CAAC,CAAA;IAEpD,IAAI,MAAM;QAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAA;IAElC,2GAA2G;IAC3G,qGAAqG;IACrG,mFAAmF;IACnF,IAAM,cAAc,GAAG,IAAA,eAAW,EAAC,IAAA,qBAAW,EAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;QAC7D,aAAa,CAAC,i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iB,CAAC,MAAM,KAAK,CAAC,EAAE;QAClC,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAA;KACvB;IACD,IAAI,iBAAiB,CAAC,MAAM,KAAK,CAAC,EAAE;QAClC,YAAY,GAAG,iBAAiB,CAAA;KACjC;SAAM;QACL,YAAY,mCACP,iBAAiB,CAAC,GAAG,CAAC,UAAC,GAAG,IAAK,OAAA,CAAC;YACjC,QAAQ,EAAE,oBAAoB;YAC9B,QAAQ,EAAE,IAAA,eAAK,EAAC,IAAA,iBAAU,EAAC,cAAc,EAAE,GAAG,CAAC,CAAC;SACjD,CAAC,EAHgC,CAGhC,CAAC,SACA,iBAAiB,OACrB,CAAA;KACF;IAED,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,CAAA;IACrC,SAAS,CAAC,IAAI,OAAd,SAAS,EAAS,YAAY,EAAC;IAE/B,OAAO;QACL,OAAO,EAAE,EAAE;KACZ,CAAA;AACH,CAAC,CAAA;AAzEY,QAAA,MAAM,UAyElB"}
@@ -1,107 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- /* eslint-disable @typescript-eslint/ban-ts-ignore */
40
- require("@graphql-codegen/testing");
41
- var graphql_1 = require("graphql");
42
- var __1 = require("..");
43
- var testSchema = (0, graphql_1.buildSchema)(/* GraphQL */ "\n type Avatar {\n id: ID!\n url: String!\n }\n\n type User {\n id: ID!\n login: String!\n avatar(height: Int!, width: Int!): Avatar\n }\n\n type Query {\n user: User!\n users: [User!]!\n }\n");
44
- // eslint-disable-next-line jest/expect-expect
45
- it('can be called', function () { return __awaiter(void 0, void 0, void 0, function () {
46
- var testDocument;
47
- return __generator(this, function (_a) {
48
- switch (_a.label) {
49
- case 0:
50
- testDocument = (0, graphql_1.parse)(/* GraphQL */ "\n query user {\n user {\n id\n }\n }\n ");
51
- return [4 /*yield*/, (0, __1.plugin)(testSchema, [{ document: testDocument }], {})];
52
- case 1:
53
- _a.sent();
54
- return [2 /*return*/];
55
- }
56
- });
57
- }); });
58
- // eslint-disable-next-line jest/expect-expect
59
- it('can be called with queries that include connection fragments', function () { return __awaiter(void 0, void 0, void 0, function () {
60
- var testDocument;
61
- return __generator(this, function (_a) {
62
- switch (_a.label) {
63
- case 0:
64
- testDocument = (0, graphql_1.parse)(/* GraphQL */ "\n query user {\n users @connection(key: \"foo\") {\n id\n }\n }\n ");
65
- return [4 /*yield*/, (0, __1.plugin)(testSchema, [{ document: testDocument }], {})];
66
- case 1:
67
- _a.sent();
68
- return [2 /*return*/];
69
- }
70
- });
71
- }); });
72
- it('can inline @argumentDefinitions/@arguments annotated fragments', function () { return __awaiter(void 0, void 0, void 0, function () {
73
- var fragmentDocument, queryDocument, input, queryDoc;
74
- return __generator(this, function (_a) {
75
- switch (_a.label) {
76
- case 0:
77
- fragmentDocument = (0, graphql_1.parse)(/* GraphQL */ "\n fragment UserLogin on User\n @argumentDefinitions(\n height: { type: \"Int\", defaultValue: 10 }\n width: { type: \"Int\", defaultValue: 10 }\n ) {\n id\n login\n avatar(width: $width, height: $height) {\n id\n url\n }\n }\n ");
78
- queryDocument = (0, graphql_1.parse)(/* GraphQL */ "\n query user {\n users {\n ...UserLogin @arguments(height: 30, width: 30)\n }\n }\n ");
79
- input = [{ document: fragmentDocument }, { document: queryDocument }];
80
- return [4 /*yield*/, (0, __1.plugin)(testSchema, input, {})];
81
- case 1:
82
- _a.sent();
83
- queryDoc = input.find(function (doc) { var _a; return ((_a = doc.document) === null || _a === void 0 ? void 0 : _a.definitions[0].kind) === 'OperationDefinition'; });
84
- expect(queryDoc).toBeDefined();
85
- expect((0, graphql_1.print)(queryDoc === null || queryDoc === void 0 ? void 0 : queryDoc.document)).toBeSimilarStringTo(/* GraphQL */ "\n query user {\n users {\n id\n login\n avatar(width: 30, height: 30) {\n id\n url\n }\n }\n }\n ");
86
- return [2 /*return*/];
87
- }
88
- });
89
- }); });
90
- it('handles unions with interfaces the correct way', function () { return __awaiter(void 0, void 0, void 0, function () {
91
- var schema, queryDocument, input, queryDoc;
92
- return __generator(this, function (_a) {
93
- switch (_a.label) {
94
- case 0:
95
- schema = (0, graphql_1.buildSchema)(/* GraphQL */ "\n type User {\n id: ID!\n login: String!\n }\n\n interface Error {\n message: String!\n }\n\n type UserNotFoundError implements Error {\n message: String!\n }\n\n type UserBlockedError implements Error {\n message: String!\n }\n\n union UserResult = User | UserNotFoundError | UserBlockedError\n\n type Query {\n user: UserResult!\n }\n ");
96
- queryDocument = (0, graphql_1.parse)(/* GraphQL */ "\n query user {\n user {\n ... on User {\n id\n login\n }\n ... on Error {\n message\n }\n }\n }\n ");
97
- input = [{ document: queryDocument }];
98
- return [4 /*yield*/, (0, __1.plugin)(schema, input, {})];
99
- case 1:
100
- _a.sent();
101
- queryDoc = input.find(function (doc) { var _a; return ((_a = doc.document) === null || _a === void 0 ? void 0 : _a.definitions[0].kind) === 'OperationDefinition'; });
102
- expect(queryDoc).toBeDefined();
103
- expect((0, graphql_1.print)(queryDoc === null || queryDoc === void 0 ? void 0 : queryDoc.document)).toBeSimilarStringTo(/* GraphQL */ "\n query user {\n user {\n ... on User {\n id\n login\n }\n ... on Error {\n message\n }\n }\n }\n ");
104
- return [2 /*return*/];
105
- }
106
- });
107
- }); });
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.spec.js","sourceRoot":"","sources":["../../../../src/__tests__/index.spec.ts"],"names":[],"mappings":";;AAAA,qDAAqD;AACrD,oCAAiC;AAGjC,qCAA4D;AAC5D,0BAA2B;AAE3B,MAAM,UAAU,GAAG,IAAA,qBAAW,EAAC,aAAa,CAAC;;;;;;;;;;;;;;;;CAgB5C,CAAC,CAAA;AAEF,8CAA8C;AAC9C,EAAE,CAAC,eAAe,EAAE,KAAK,IAAI,EAAE;IAC7B,MAAM,YAAY,GAAG,IAAA,eAAK,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CAAC,CAAA;AAEF,EAAE,CAAC,gDAAgD,EAAE,KAAK,IAAI,EAAE;IAC9D,MAAM,MAAM,GAAG,IAAA,qBAAW,EAAC,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;GAuBxC,CAAC,CAAA;IAEF,MAAM,aAAa,GAAG,IAAA,eAAK,EAAC,aAAa,CAAC;;;;;;;;;;;;GAYzC,CAAC,CAAA;IAEF,MAAM,KAAK,GAAyB,CAAC,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC,CAAA;IACjE,MAAM,IAAA,UAAM,EAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAAA;IAC/B,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,qBAAqB,CAAC,CAAA;IAEjG,MAAM,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAA;IAC9B,MAAM,CAAC,IAAA,eAAK,EAAC,QAAQ,EAAE,QAAmB,CAAC,CAAC,CAAC,mBAAmB,CAAC,aAAa,CAAC;;;;;;;;;;;;GAY9E,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,88 +0,0 @@
1
- "use strict";
2
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
- if (ar || !(i in from)) {
5
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
- ar[i] = from[i];
7
- }
8
- }
9
- return to.concat(ar || Array.prototype.slice.call(from));
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.plugin = void 0;
16
- var graphql_1 = require("graphql");
17
- var relay_compiler_1 = require("relay-compiler");
18
- var CompilerContext_1 = __importDefault(require("relay-compiler/lib/core/CompilerContext"));
19
- var IRPrinter_1 = require("relay-compiler/lib/core/IRPrinter");
20
- var Schema_1 = require("relay-compiler/lib/core/Schema");
21
- var ApplyFragmentArgumentTransform_1 = require("relay-compiler/lib/transforms/ApplyFragmentArgumentTransform");
22
- var FlattenTransform_1 = require("relay-compiler/lib/transforms/FlattenTransform");
23
- var InlineFragmentsTransform_1 = require("relay-compiler/lib/transforms/InlineFragmentsTransform");
24
- var SkipRedundantNodesTransform_1 = require("relay-compiler/lib/transforms/SkipRedundantNodesTransform");
25
- function isFragment(documentFile) {
26
- var name = false;
27
- (0, graphql_1.visit)(documentFile.document, {
28
- enter: {
29
- FragmentDefinition: function () {
30
- name = true;
31
- },
32
- },
33
- });
34
- return name;
35
- }
36
- var plugin = function (schema, documents, _config) {
37
- var isFrag = documents.every(function (d) { return isFragment(d); });
38
- if (isFrag)
39
- return { content: '' };
40
- // @TODO way for users to define directives they use, otherwise relay will throw an unknown directive error
41
- // Maybe we can scan the queries and add them dynamically without users having to do some extra stuff
42
- // transformASTSchema creates a new schema instance instead of mutating the old one
43
- var adjustedSchema = (0, Schema_1.create)((0, graphql_1.printSchema)(schema)).extend([
44
- /* GraphQL */ "\n directive @connection(key: String!, filter: [String!]) on FIELD\n directive @client on FIELD\n ",
45
- ]);
46
- var documentAsts = documents.reduce(function (prev, v) { var _a, _b; return __spreadArray(__spreadArray([], prev, true), ((_b = (_a = v.document) === null || _a === void 0 ? void 0 : _a.definitions) !== null && _b !== void 0 ? _b : []), true); }, []);
47
- var relayDocuments = relay_compiler_1.Parser.transform(adjustedSchema, documentAsts);
48
- var fragmentCompilerContext = new CompilerContext_1.default(adjustedSchema).addAll(relayDocuments);
49
- var fragmentDocuments = fragmentCompilerContext
50
- .applyTransforms([
51
- ApplyFragmentArgumentTransform_1.transform,
52
- (0, FlattenTransform_1.transformWithOptions)({ flattenAbstractTypes: false }),
53
- SkipRedundantNodesTransform_1.transform,
54
- ])
55
- .documents()
56
- .filter(function (doc) { return doc.kind === 'Fragment'; });
57
- var queryCompilerContext = new CompilerContext_1.default(adjustedSchema)
58
- .addAll(relayDocuments)
59
- .applyTransforms([
60
- ApplyFragmentArgumentTransform_1.transform,
61
- InlineFragmentsTransform_1.transform,
62
- (0, FlattenTransform_1.transformWithOptions)({ flattenAbstractTypes: false }),
63
- SkipRedundantNodesTransform_1.transform,
64
- ]);
65
- var newQueryDocuments = queryCompilerContext.documents().map(function (doc) { return ({
66
- location: 'optimized by relay',
67
- document: (0, graphql_1.parse)((0, IRPrinter_1.print)(adjustedSchema, doc)),
68
- }); });
69
- var newDocuments = [];
70
- if (newQueryDocuments.length === 0) {
71
- return { content: '' };
72
- }
73
- if (newQueryDocuments.length === 1) {
74
- newDocuments = newQueryDocuments;
75
- }
76
- else {
77
- newDocuments = __spreadArray(__spreadArray([], fragmentDocuments.map(function (doc) { return ({
78
- location: 'optimized by relay',
79
- document: (0, graphql_1.parse)((0, IRPrinter_1.print)(adjustedSchema, doc)),
80
- }); }), true), newQueryDocuments, true);
81
- }
82
- documents.splice(0, documents.length);
83
- documents.push.apply(documents, newDocuments);
84
- return {
85
- content: '',
86
- };
87
- };
88
- exports.plugin = plugin;
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";;;;;;AAEA,qCAAkF;AAElF,mDAAsD;AACtD,8FAAqE;AACrE,iEAAuE;AACvE,2DAAsE;AAEtE,iHAA0H;AAC1H,qFAAoH;AACpH,qGAA8G;AAC9G,2GAAoH;AAKpH,SAAS,UAAU,CAAC,YAAgC;IAClD,IAAI,IAAI,GAAG,KAAK,CAAA;IAEhB,IAAA,eAAK,EAAC,YAAY,CAAC,QAAS,EAAE;QAC5B,KAAK,EAAE;YACL,kBAAkB,EAAE,GAAG,EAAE;gBACvB,IAAI,GAAG,IAAI,CAAA;YACb,CAAC;SACF;KACF,CAAC,CAAA;IACF,OAAO,IAAI,CAAA;AACb,CAAC;AAE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xB,IAAA,uCAA2B,EAAC,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC;QAC5D,uCAA2B;KAC5B,CAAC,CAAA;IAEJ,MAAM,iBAAiB,GAAyB,oBAAoB,CAAC,SAAS,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAC7F,QAAQ,EAAE,oBAAoB;QAC9B,QAAQ,EAAE,IAAA,eAAK,EAAC,IAAA,iBAAU,EAAC,cAAc,EAAE,GAAG,CAAC,CAAC;KACjD,CAAC,CAAC,CAAA;IAEH,IAAI,YAAY,GAAyB,EAAE,CAAA;IAC3C,IAAI,iBAAiB,CAAC,MAAM,KAAK,CAAC,EAAE;QAClC,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAA;KACvB;IACD,IAAI,iBAAiB,CAAC,MAAM,KAAK,CAAC,EAAE;QAClC,YAAY,GAAG,iBAAiB,CAAA;KACjC;SAAM;QACL,YAAY,GAAG;YACb,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;gBACjC,QAAQ,EAAE,oBAAoB;gBAC9B,QAAQ,EAAE,IAAA,eAAK,EAAC,IAAA,iBAAU,EAAC,cAAc,EAAE,GAAG,CAAC,CAAC;aACjD,CAAC,CAAC;YACH,GAAG,iBAAiB;SACrB,CAAA;KACF;IAED,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,CAAA;IACrC,SAAS,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,CAAA;IAE/B,OAAO;QACL,OAAO,EAAE,EAAE;KACZ,CAAA;AACH,CAAC,CAAA;AAzEY,QAAA,MAAM,UAyElB"}
@@ -1,85 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.plugin = void 0;
7
- const graphql_1 = require("graphql");
8
- const relay_compiler_1 = require("relay-compiler");
9
- const CompilerContext_1 = __importDefault(require("relay-compiler/lib/core/CompilerContext"));
10
- const IRPrinter_1 = require("relay-compiler/lib/core/IRPrinter");
11
- const Schema_1 = require("relay-compiler/lib/core/Schema");
12
- const ApplyFragmentArgumentTransform_1 = require("relay-compiler/lib/transforms/ApplyFragmentArgumentTransform");
13
- const FlattenTransform_1 = require("relay-compiler/lib/transforms/FlattenTransform");
14
- const InlineFragmentsTransform_1 = require("relay-compiler/lib/transforms/InlineFragmentsTransform");
15
- const SkipRedundantNodesTransform_1 = require("relay-compiler/lib/transforms/SkipRedundantNodesTransform");
16
- function isFragment(documentFile) {
17
- let name = false;
18
- (0, graphql_1.visit)(documentFile.document, {
19
- enter: {
20
- FragmentDefinition: () => {
21
- name = true;
22
- },
23
- },
24
- });
25
- return name;
26
- }
27
- const plugin = (schema, documents, _config) => {
28
- const isFrag = documents.every((d) => isFragment(d));
29
- if (isFrag)
30
- return { content: '' };
31
- // @TODO way for users to define directives they use, otherwise relay will throw an unknown directive error
32
- // Maybe we can scan the queries and add them dynamically without users having to do some extra stuff
33
- // transformASTSchema creates a new schema instance instead of mutating the old one
34
- const adjustedSchema = (0, Schema_1.create)((0, graphql_1.printSchema)(schema)).extend([
35
- /* GraphQL */ `
36
- directive @connection(key: String!, filter: [String!]) on FIELD
37
- directive @client on FIELD
38
- `,
39
- ]);
40
- const documentAsts = documents.reduce((prev, v) => { var _a, _b; return [...prev, ...((_b = (_a = v.document) === null || _a === void 0 ? void 0 : _a.definitions) !== null && _b !== void 0 ? _b : [])]; }, []);
41
- const relayDocuments = relay_compiler_1.Parser.transform(adjustedSchema, documentAsts);
42
- const fragmentCompilerContext = new CompilerContext_1.default(adjustedSchema).addAll(relayDocuments);
43
- const fragmentDocuments = fragmentCompilerContext
44
- .applyTransforms([
45
- ApplyFragmentArgumentTransform_1.transform,
46
- (0, FlattenTransform_1.transformWithOptions)({ flattenAbstractTypes: false }),
47
- SkipRedundantNodesTransform_1.transform,
48
- ])
49
- .documents()
50
- .filter((doc) => doc.kind === 'Fragment');
51
- const queryCompilerContext = new CompilerContext_1.default(adjustedSchema)
52
- .addAll(relayDocuments)
53
- .applyTransforms([
54
- ApplyFragmentArgumentTransform_1.transform,
55
- InlineFragmentsTransform_1.transform,
56
- (0, FlattenTransform_1.transformWithOptions)({ flattenAbstractTypes: false }),
57
- SkipRedundantNodesTransform_1.transform,
58
- ]);
59
- const newQueryDocuments = queryCompilerContext.documents().map((doc) => ({
60
- location: 'optimized by relay',
61
- document: (0, graphql_1.parse)((0, IRPrinter_1.print)(adjustedSchema, doc)),
62
- }));
63
- let newDocuments = [];
64
- if (newQueryDocuments.length === 0) {
65
- return { content: '' };
66
- }
67
- if (newQueryDocuments.length === 1) {
68
- newDocuments = newQueryDocuments;
69
- }
70
- else {
71
- newDocuments = [
72
- ...fragmentDocuments.map((doc) => ({
73
- location: 'optimized by relay',
74
- document: (0, graphql_1.parse)((0, IRPrinter_1.print)(adjustedSchema, doc)),
75
- })),
76
- ...newQueryDocuments,
77
- ];
78
- }
79
- documents.splice(0, documents.length);
80
- documents.push(...newDocuments);
81
- return {
82
- content: '',
83
- };
84
- };
85
- exports.plugin = plugin;