@gqlbase/plugins 0.0.6 → 0.0.7
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/dist/base/InterfaceUtilsPlugin/InterfaceUtilsPlugin.d.ts +55 -0
- package/dist/base/InterfaceUtilsPlugin/InterfaceUtilsPlugin.d.ts.map +1 -0
- package/dist/base/InterfaceUtilsPlugin/InterfaceUtilsPlugin.js +100 -0
- package/dist/base/InterfaceUtilsPlugin/InterfaceUtilsPlugin.js.map +1 -0
- package/dist/base/InterfaceUtilsPlugin/InterfaceUtilsPlugin.utils.d.ts +3 -0
- package/dist/base/InterfaceUtilsPlugin/InterfaceUtilsPlugin.utils.d.ts.map +1 -0
- package/dist/base/InterfaceUtilsPlugin/InterfaceUtilsPlugin.utils.js +4 -0
- package/dist/base/InterfaceUtilsPlugin/InterfaceUtilsPlugin.utils.js.map +1 -0
- package/dist/base/InterfaceUtilsPlugin/index.d.ts +3 -0
- package/dist/base/InterfaceUtilsPlugin/index.d.ts.map +1 -0
- package/dist/base/InterfaceUtilsPlugin/index.js +3 -0
- package/dist/base/InterfaceUtilsPlugin/index.js.map +1 -0
- package/dist/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.d.ts +9 -3
- package/dist/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.d.ts.map +1 -1
- package/dist/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.js +26 -16
- package/dist/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.js.map +1 -1
- package/dist/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.utils.d.ts +19 -9
- package/dist/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.utils.d.ts.map +1 -1
- package/dist/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.utils.js +11 -11
- package/dist/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.utils.js.map +1 -1
- package/dist/base/RelationsPlugin/RelationsPlugin.d.ts +13 -8
- package/dist/base/RelationsPlugin/RelationsPlugin.d.ts.map +1 -1
- package/dist/base/RelationsPlugin/RelationsPlugin.js +30 -46
- package/dist/base/RelationsPlugin/RelationsPlugin.js.map +1 -1
- package/dist/base/RelationsPlugin/RelationsPlugin.utils.d.ts +5 -3
- package/dist/base/RelationsPlugin/RelationsPlugin.utils.d.ts.map +1 -1
- package/dist/base/RelationsPlugin/RelationsPlugin.utils.js +26 -1
- package/dist/base/RelationsPlugin/RelationsPlugin.utils.js.map +1 -1
- package/dist/base/RelationsPlugin/index.d.ts +1 -1
- package/dist/base/RelationsPlugin/index.d.ts.map +1 -1
- package/dist/base/RelationsPlugin/index.js +1 -1
- package/dist/base/RelationsPlugin/index.js.map +1 -1
- package/dist/base/RfcFeaturesPlugin/RfcFeaturesPlugin.d.ts +28 -0
- package/dist/base/RfcFeaturesPlugin/RfcFeaturesPlugin.d.ts.map +1 -0
- package/dist/base/RfcFeaturesPlugin/RfcFeaturesPlugin.js +33 -0
- package/dist/base/RfcFeaturesPlugin/RfcFeaturesPlugin.js.map +1 -0
- package/dist/base/RfcFeaturesPlugin/RfcFeaturesPlugin.utils.d.ts +14 -0
- package/dist/base/RfcFeaturesPlugin/RfcFeaturesPlugin.utils.d.ts.map +1 -0
- package/dist/base/RfcFeaturesPlugin/RfcFeaturesPlugin.utils.js +39 -0
- package/dist/base/RfcFeaturesPlugin/RfcFeaturesPlugin.utils.js.map +1 -0
- package/dist/base/RfcFeaturesPlugin/index.d.ts +3 -0
- package/dist/base/RfcFeaturesPlugin/index.d.ts.map +1 -0
- package/dist/base/RfcFeaturesPlugin/index.js +3 -0
- package/dist/base/RfcFeaturesPlugin/index.js.map +1 -0
- package/dist/base/basePreset.d.ts +2 -0
- package/dist/base/basePreset.d.ts.map +1 -1
- package/dist/base/basePreset.js +6 -0
- package/dist/base/basePreset.js.map +1 -1
- package/dist/base/index.d.ts +2 -0
- package/dist/base/index.d.ts.map +1 -1
- package/dist/base/index.js +2 -0
- package/dist/base/index.js.map +1 -1
- package/dist/relay/ConnectionPlugin/ConnectionPlugin.d.ts +63 -0
- package/dist/relay/ConnectionPlugin/ConnectionPlugin.d.ts.map +1 -0
- package/dist/relay/ConnectionPlugin/ConnectionPlugin.js +156 -0
- package/dist/relay/ConnectionPlugin/ConnectionPlugin.js.map +1 -0
- package/dist/relay/ConnectionPlugin/ConnectionPlugin.utils.d.ts +4 -0
- package/dist/relay/ConnectionPlugin/ConnectionPlugin.utils.d.ts.map +1 -0
- package/dist/relay/ConnectionPlugin/ConnectionPlugin.utils.js +26 -0
- package/dist/relay/ConnectionPlugin/ConnectionPlugin.utils.js.map +1 -0
- package/dist/relay/ConnectionPlugin/index.d.ts +3 -0
- package/dist/relay/ConnectionPlugin/index.d.ts.map +1 -0
- package/dist/relay/ConnectionPlugin/index.js +3 -0
- package/dist/relay/ConnectionPlugin/index.js.map +1 -0
- package/dist/relay/{NodeInterfacePlugin.d.ts → NodeInterfacePlugin/NodeInterfacePlugin.d.ts} +30 -6
- package/dist/relay/NodeInterfacePlugin/NodeInterfacePlugin.d.ts.map +1 -0
- package/dist/relay/{NodeInterfacePlugin.js → NodeInterfacePlugin/NodeInterfacePlugin.js} +37 -27
- package/dist/relay/NodeInterfacePlugin/NodeInterfacePlugin.js.map +1 -0
- package/dist/relay/NodeInterfacePlugin/index.d.ts +2 -0
- package/dist/relay/NodeInterfacePlugin/index.d.ts.map +1 -0
- package/dist/relay/NodeInterfacePlugin/index.js +2 -0
- package/dist/relay/NodeInterfacePlugin/index.js.map +1 -0
- package/dist/relay/index.d.ts +3 -2
- package/dist/relay/index.d.ts.map +1 -1
- package/dist/relay/index.js +3 -2
- package/dist/relay/index.js.map +1 -1
- package/dist/relay/relayPreset.js +2 -2
- package/dist/relay/relayPreset.js.map +1 -1
- package/package.json +3 -3
- package/dist/relay/ConnectionPlugin.d.ts +0 -46
- package/dist/relay/ConnectionPlugin.d.ts.map +0 -1
- package/dist/relay/ConnectionPlugin.js +0 -200
- package/dist/relay/ConnectionPlugin.js.map +0 -1
- package/dist/relay/NodeInterfacePlugin.d.ts.map +0 -1
- package/dist/relay/NodeInterfacePlugin.js.map +0 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ITransformerContext, TransformerPluginBase } from "@gqlbase/core";
|
|
2
|
+
import { DefinitionNode, InterfaceNode, ObjectNode } from "@gqlbase/core/definition";
|
|
3
|
+
/**
|
|
4
|
+
* Normalizes interface implementation by other interfaces and objects, makeing sure that all fields defined in an interface are implemented by its implementors, and that interfaces can implement other interfaces:
|
|
5
|
+
*
|
|
6
|
+
* - When an object or interface implements another interface, it must implement all fields defined in the implemented interface.
|
|
7
|
+
* - "Transitively implemented interfaces (interfaces implemented by the interface that is being implemented) must also be defined on an implementing type or interface."
|
|
8
|
+
*
|
|
9
|
+
* @see https://spec.graphql.org/September2025/#sec-Interfaces
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```graphql
|
|
13
|
+
* # Before
|
|
14
|
+
* interface Node {
|
|
15
|
+
* id: ID!
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* interface Timestamped {
|
|
19
|
+
* createdAt: DateTime!
|
|
20
|
+
* updatedAt: DateTime!
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* interface User implements Node & Timestamped {
|
|
24
|
+
* id: ID!
|
|
25
|
+
* name: String!
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* # After
|
|
29
|
+
* interface Node {
|
|
30
|
+
* id: ID!
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* interface Timestamped {
|
|
34
|
+
* createdAt: DateTime!
|
|
35
|
+
* updatedAt: DateTime!
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* interface User implements Node & Timestamped {
|
|
39
|
+
* id: ID!
|
|
40
|
+
* name: String!
|
|
41
|
+
* createdAt: DateTime! # added by the plugin
|
|
42
|
+
* updatedAt: DateTime! # added by the plugin
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare class InterfaceUtilsPlugin extends TransformerPluginBase {
|
|
47
|
+
constructor(context: ITransformerContext);
|
|
48
|
+
private _getValidInterface;
|
|
49
|
+
private _normalizeTransitiveInterfaces;
|
|
50
|
+
private _normalizeInterfaceFields;
|
|
51
|
+
match(definition: DefinitionNode): definition is InterfaceNode | ObjectNode;
|
|
52
|
+
normalize(node: InterfaceNode | ObjectNode): void;
|
|
53
|
+
}
|
|
54
|
+
export declare const interfaceUtilsPlugin: (options?: unknown) => import("@gqlbase/core").IPluginFactory;
|
|
55
|
+
//# sourceMappingURL=InterfaceUtilsPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InterfaceUtilsPlugin.d.ts","sourceRoot":"","sources":["../../../src/base/InterfaceUtilsPlugin/InterfaceUtilsPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAChG,OAAO,EACL,cAAc,EAEd,aAAa,EAEb,UAAU,EACX,MAAM,0BAA0B,CAAC;AAIlC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH,qBAAa,oBAAqB,SAAQ,qBAAqB;gBACjD,OAAO,EAAE,mBAAmB;IAIxC,OAAO,CAAC,kBAAkB;IAa1B,OAAO,CAAC,8BAA8B;IAgBtC,OAAO,CAAC,yBAAyB;IAwB1B,KAAK,CAAC,UAAU,EAAE,cAAc;IAIhC,SAAS,CAAC,IAAI,EAAE,aAAa,GAAG,UAAU;CAQlD;AAED,eAAO,MAAM,oBAAoB,+DAA4C,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { createPluginFactory, TransformerPluginBase } from "@gqlbase/core";
|
|
2
|
+
import { FieldNode, InterfaceNode, NamedTypeNode, ObjectNode, } from "@gqlbase/core/definition";
|
|
3
|
+
import { hasInterfaces } from "./InterfaceUtilsPlugin.utils.js";
|
|
4
|
+
import { TransformerPluginExecutionError } from "@gqlbase/shared/errors";
|
|
5
|
+
/**
|
|
6
|
+
* Normalizes interface implementation by other interfaces and objects, makeing sure that all fields defined in an interface are implemented by its implementors, and that interfaces can implement other interfaces:
|
|
7
|
+
*
|
|
8
|
+
* - When an object or interface implements another interface, it must implement all fields defined in the implemented interface.
|
|
9
|
+
* - "Transitively implemented interfaces (interfaces implemented by the interface that is being implemented) must also be defined on an implementing type or interface."
|
|
10
|
+
*
|
|
11
|
+
* @see https://spec.graphql.org/September2025/#sec-Interfaces
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```graphql
|
|
15
|
+
* # Before
|
|
16
|
+
* interface Node {
|
|
17
|
+
* id: ID!
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* interface Timestamped {
|
|
21
|
+
* createdAt: DateTime!
|
|
22
|
+
* updatedAt: DateTime!
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* interface User implements Node & Timestamped {
|
|
26
|
+
* id: ID!
|
|
27
|
+
* name: String!
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* # After
|
|
31
|
+
* interface Node {
|
|
32
|
+
* id: ID!
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* interface Timestamped {
|
|
36
|
+
* createdAt: DateTime!
|
|
37
|
+
* updatedAt: DateTime!
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* interface User implements Node & Timestamped {
|
|
41
|
+
* id: ID!
|
|
42
|
+
* name: String!
|
|
43
|
+
* createdAt: DateTime! # added by the plugin
|
|
44
|
+
* updatedAt: DateTime! # added by the plugin
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export class InterfaceUtilsPlugin extends TransformerPluginBase {
|
|
49
|
+
constructor(context) {
|
|
50
|
+
super("InterfaceUtilsPlugin", context);
|
|
51
|
+
}
|
|
52
|
+
_getValidInterface(name) {
|
|
53
|
+
const iface = this.context.document.getNodeOrThrow(name);
|
|
54
|
+
if (!(iface instanceof InterfaceNode)) {
|
|
55
|
+
throw new TransformerPluginExecutionError(this.name, `Node ${name} is not an interface but is implemented by ${name}`);
|
|
56
|
+
}
|
|
57
|
+
return iface;
|
|
58
|
+
}
|
|
59
|
+
_normalizeTransitiveInterfaces(node) {
|
|
60
|
+
for (const ifaceName of node.getInterfaces()) {
|
|
61
|
+
const iface = this._getValidInterface(ifaceName.getTypeName());
|
|
62
|
+
if (!hasInterfaces(iface)) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
for (const transitiveIfaceName of iface.getInterfaces()) {
|
|
66
|
+
if (!node.hasInterface(transitiveIfaceName.getTypeName())) {
|
|
67
|
+
node.addInterface(transitiveIfaceName);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
_normalizeInterfaceFields(node) {
|
|
73
|
+
for (const ifaceName of node.getInterfaces()) {
|
|
74
|
+
const iface = this._getValidInterface(ifaceName.getTypeName());
|
|
75
|
+
for (const field of iface.getFields()) {
|
|
76
|
+
if (node.hasField(field.name)) {
|
|
77
|
+
const nodeField = node.getField(field.name);
|
|
78
|
+
if (nodeField?.type.getTypeName() !== field.type.getTypeName()) {
|
|
79
|
+
this.context.logger.warn(`Field ${field.name} on ${node.name} has type ${nodeField?.type.getTypeName()} but should be ${field.type.getTypeName()} as defined in interface ${iface.name}`);
|
|
80
|
+
nodeField?.setType(NamedTypeNode.create(field.type.getTypeName()));
|
|
81
|
+
}
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
node.addField(FieldNode.fromDefinition(field.serialize()));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
match(definition) {
|
|
89
|
+
return definition instanceof InterfaceNode || definition instanceof ObjectNode;
|
|
90
|
+
}
|
|
91
|
+
normalize(node) {
|
|
92
|
+
if (!hasInterfaces(node)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
this._normalizeTransitiveInterfaces(node);
|
|
96
|
+
this._normalizeInterfaceFields(node);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
export const interfaceUtilsPlugin = createPluginFactory(InterfaceUtilsPlugin);
|
|
100
|
+
//# sourceMappingURL=InterfaceUtilsPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InterfaceUtilsPlugin.js","sourceRoot":"","sources":["../../../src/base/InterfaceUtilsPlugin/InterfaceUtilsPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAuB,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAChG,OAAO,EAEL,SAAS,EACT,aAAa,EACb,aAAa,EACb,UAAU,GACX,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH,MAAM,OAAO,oBAAqB,SAAQ,qBAAqB;IAC7D,YAAY,OAA4B;QACtC,KAAK,CAAC,sBAAsB,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;IAEO,kBAAkB,CAAC,IAAY;QACrC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAEzD,IAAI,CAAC,CAAC,KAAK,YAAY,aAAa,CAAC,EAAE,CAAC;YACtC,MAAM,IAAI,+BAA+B,CACvC,IAAI,CAAC,IAAI,EACT,QAAQ,IAAI,8CAA8C,IAAI,EAAE,CACjE,CAAC;QACJ,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,8BAA8B,CAAC,IAAgC;QACrE,KAAK,MAAM,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AE,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;oBACrE,CAAC;oBAED,SAAS;gBACX,CAAC;gBAED,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,cAAc,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;YAC7D,CAAC;QACH,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,UAA0B;QACrC,OAAO,UAAU,YAAY,aAAa,IAAI,UAAU,YAAY,UAAU,CAAC;IACjF,CAAC;IAEM,SAAS,CAAC,IAAgC;QAC/C,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;YACzB,OAAO;QACT,CAAC;QAED,IAAI,CAAC,8BAA8B,CAAC,IAAI,CAAC,CAAC;QAC1C,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;CACF;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,mBAAmB,CAAC,oBAAoB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InterfaceUtilsPlugin.utils.d.ts","sourceRoot":"","sources":["../../../src/base/InterfaceUtilsPlugin/InterfaceUtilsPlugin.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAErE,eAAO,MAAM,aAAa,GAAI,MAAM,UAAU,GAAG,aAAa,KAAG,OAEhE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InterfaceUtilsPlugin.utils.js","sourceRoot":"","sources":["../../../src/base/InterfaceUtilsPlugin/InterfaceUtilsPlugin.utils.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAgC,EAAW,EAAE;IACzE,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;AACtE,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/base/InterfaceUtilsPlugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/base/InterfaceUtilsPlugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { ITransformerContext, TransformerPluginBase } from "@gqlbase/core";
|
|
2
2
|
import { DefinitionNode } from "@gqlbase/core/definition";
|
|
3
|
+
import { ModelTypesGeneratorPluginOptions } from "./ModelTypesGeneratorPlugin.utils.js";
|
|
3
4
|
/**
|
|
4
5
|
* This plugin generates TypeScript types for all objects defined in the schema.
|
|
5
6
|
*/
|
|
6
7
|
export declare class ModelTypesGeneratorPlugin extends TransformerPluginBase {
|
|
7
8
|
private nodes;
|
|
8
|
-
|
|
9
|
+
private options;
|
|
10
|
+
constructor(context: ITransformerContext, options?: ModelTypesGeneratorPluginOptions);
|
|
9
11
|
private _getContent;
|
|
10
12
|
private _createTypeNameIdentifier;
|
|
11
13
|
private _createValueTypeReference;
|
|
@@ -17,7 +19,11 @@ export declare class ModelTypesGeneratorPlugin extends TransformerPluginBase {
|
|
|
17
19
|
before(): void;
|
|
18
20
|
match(definition: DefinitionNode): boolean;
|
|
19
21
|
generate(definition: DefinitionNode): void;
|
|
20
|
-
output(): {
|
|
22
|
+
output(): {
|
|
23
|
+
modelTypes: string;
|
|
24
|
+
} | {
|
|
25
|
+
modelTypes?: undefined;
|
|
26
|
+
};
|
|
21
27
|
}
|
|
22
|
-
export declare const modelTypesGeneratorPlugin: (options?:
|
|
28
|
+
export declare const modelTypesGeneratorPlugin: (options?: ModelTypesGeneratorPluginOptions | undefined) => import("@gqlbase/core").IPluginFactory;
|
|
23
29
|
//# sourceMappingURL=ModelTypesGeneratorPlugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelTypesGeneratorPlugin.d.ts","sourceRoot":"","sources":["../../../src/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAGhG,OAAO,EACL,cAAc,
|
|
1
|
+
{"version":3,"file":"ModelTypesGeneratorPlugin.d.ts","sourceRoot":"","sources":["../../../src/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAGhG,OAAO,EACL,cAAc,EASf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAIL,gCAAgC,EACjC,MAAM,sCAAsC,CAAC;AAO9C;;GAEG;AAEH,qBAAa,yBAA0B,SAAQ,qBAAqB;IAClE,OAAO,CAAC,KAAK,CAAiB;IAC9B,OAAO,CAAC,OAAO,CAA6C;gBAEhD,OAAO,EAAE,mBAAmB,EAAE,OAAO,GAAE,gCAAqC;IAMxF,OAAO,CAAC,WAAW;IAiBnB,OAAO,CAAC,yBAAyB;IAkCjC,OAAO,CAAC,yBAAyB;IAuBjC,OAAO,CAAC,mBAAmB;IAmC3B,OAAO,CAAC,iBAAiB;IAazB,OAAO,CAAC,oBAAoB;IAc5B,OAAO,CAAC,eAAe;IAsBvB,OAAO,CAAC,gBAAgB;IAsBjB,MAAM;IAkBN,KAAK,CAAC,UAAU,EAAE,cAAc,GAAG,OAAO;IAQ1C,QAAQ,CAAC,UAAU,EAAE,cAAc;IAkBnC,MAAM;;;;;CASd;AAED,eAAO,MAAM,yBAAyB,oGAAiD,CAAC"}
|
|
@@ -3,21 +3,24 @@ import { createPluginFactory, TransformerPluginBase } from "@gqlbase/core";
|
|
|
3
3
|
import { writeOutputFile } from "@gqlbase/shared/files";
|
|
4
4
|
import { createFileHeaders } from "@gqlbase/shared/codegen";
|
|
5
5
|
import { EnumNode, InterfaceNode, ListTypeNode, NonNullTypeNode, ObjectNode, UnionNode, } from "@gqlbase/core/definition";
|
|
6
|
-
import { getBuildinScalarTypeKeyword,
|
|
6
|
+
import { getBuildinScalarTypeKeyword, isOperationNode, mergeOptions, } from "./ModelTypesGeneratorPlugin.utils.js";
|
|
7
7
|
import { isEnum, isObjectLike, isScalar } from "../ModelPlugin/ModelPlugin.utils.js";
|
|
8
8
|
import { isRelationField } from "../RelationsPlugin/RelationsPlugin.utils.js";
|
|
9
9
|
import { isBuildInScalar } from "@gqlbase/shared/definition";
|
|
10
10
|
import { getTypeHint, isInternal } from "@gqlbase/core/plugins";
|
|
11
|
+
import { isSemanticNullable } from "../RfcFeaturesPlugin/RfcFeaturesPlugin.utils.js";
|
|
11
12
|
/**
|
|
12
13
|
* This plugin generates TypeScript types for all objects defined in the schema.
|
|
13
14
|
*/
|
|
14
15
|
export class ModelTypesGeneratorPlugin extends TransformerPluginBase {
|
|
15
16
|
nodes = [];
|
|
16
|
-
|
|
17
|
+
options;
|
|
18
|
+
constructor(context, options = {}) {
|
|
17
19
|
super("ModelTypesGeneratorPlugin", context);
|
|
20
|
+
this.options = mergeOptions(options);
|
|
18
21
|
}
|
|
19
22
|
_getContent() {
|
|
20
|
-
const file = ts.createSourceFile(
|
|
23
|
+
const file = ts.createSourceFile(this.options.fileName,
|
|
21
24
|
/*sourceText*/ "", ts.ScriptTarget.Latest,
|
|
22
25
|
/*setParentNodes*/ false, ts.ScriptKind.TS);
|
|
23
26
|
const printer = ts.createPrinter({
|
|
@@ -53,15 +56,21 @@ export class ModelTypesGeneratorPlugin extends TransformerPluginBase {
|
|
|
53
56
|
}
|
|
54
57
|
return ts.factory.createIdentifier(typeName);
|
|
55
58
|
}
|
|
56
|
-
_createValueTypeReference(fieldType) {
|
|
59
|
+
_createValueTypeReference(field, fieldType, level = 0) {
|
|
57
60
|
if (fieldType instanceof NonNullTypeNode) {
|
|
58
|
-
return this._createValueTypeReference(fieldType.type);
|
|
61
|
+
return this._createValueTypeReference(field, fieldType.type, level);
|
|
59
62
|
}
|
|
60
63
|
if (fieldType instanceof ListTypeNode) {
|
|
61
|
-
const elementType = this._createValueTypeReference(fieldType.type);
|
|
62
|
-
|
|
64
|
+
const elementType = this._createValueTypeReference(field, fieldType.type, level + 1);
|
|
65
|
+
const arrayType = ts.factory.createArrayTypeNode(elementType);
|
|
66
|
+
return isSemanticNullable(field, level)
|
|
67
|
+
? ts.factory.createTypeReferenceNode("Maybe", [arrayType])
|
|
68
|
+
: arrayType;
|
|
63
69
|
}
|
|
64
|
-
|
|
70
|
+
const baseType = ts.factory.createTypeReferenceNode(this._createTypeNameIdentifier(fieldType.name));
|
|
71
|
+
return isSemanticNullable(field, level)
|
|
72
|
+
? ts.factory.createTypeReferenceNode("Maybe", [baseType])
|
|
73
|
+
: baseType;
|
|
65
74
|
}
|
|
66
75
|
_createFieldMembers(definition) {
|
|
67
76
|
const members = [];
|
|
@@ -69,13 +78,12 @@ export class ModelTypesGeneratorPlugin extends TransformerPluginBase {
|
|
|
69
78
|
if (isRelationField(field)) {
|
|
70
79
|
continue;
|
|
71
80
|
}
|
|
72
|
-
const questionToken =
|
|
73
|
-
?
|
|
74
|
-
:
|
|
75
|
-
const typeNode =
|
|
76
|
-
? this._createValueTypeReference(field.type)
|
|
77
|
-
: ts.factory.createTypeReferenceNode("Maybe", [this._createValueTypeReference(field.type)]);
|
|
81
|
+
const questionToken = isSemanticNullable(field)
|
|
82
|
+
? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
|
|
83
|
+
: undefined;
|
|
84
|
+
const typeNode = this._createValueTypeReference(field, field.type);
|
|
78
85
|
const propertySignature = ts.factory.createPropertySignature([ts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)], ts.factory.createIdentifier(field.name), questionToken, typeNode);
|
|
86
|
+
// TODO: consider adding JSDoc comments with field descriptions and deprecation notices
|
|
79
87
|
// ts.addSyntheticLeadingComment(
|
|
80
88
|
// propertySignature,
|
|
81
89
|
// ts.SyntaxKind.MultiLineCommentTrivia,
|
|
@@ -153,8 +161,10 @@ export class ModelTypesGeneratorPlugin extends TransformerPluginBase {
|
|
|
153
161
|
}
|
|
154
162
|
output() {
|
|
155
163
|
const content = this._getContent();
|
|
156
|
-
|
|
157
|
-
|
|
164
|
+
if (this.options.emitFile) {
|
|
165
|
+
writeOutputFile(this.context.outputDirectory, this.options.fileName, content);
|
|
166
|
+
}
|
|
167
|
+
return this.options.emitOutput ? { modelTypes: content } : {};
|
|
158
168
|
}
|
|
159
169
|
}
|
|
160
170
|
export const modelTypesGeneratorPlugin = createPluginFactory(ModelTypesGeneratorPlugin);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelTypesGeneratorPlugin.js","sourceRoot":"","sources":["../../../src/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAuB,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAChG,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAEL,QAAQ,
|
|
1
|
+
{"version":3,"file":"ModelTypesGeneratorPlugin.js","sourceRoot":"","sources":["../../../src/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,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QAAQ,EAAE,CAAC;YAC1B,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAChF,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAChE,CAAC;CACF;AAED,MAAM,CAAC,MAAM,yBAAyB,GAAG,mBAAmB,CAAC,yBAAyB,CAAC,CAAC"}
|
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
import { DefinitionNode
|
|
1
|
+
import { DefinitionNode } from "@gqlbase/core/definition";
|
|
2
|
+
export interface ModelTypesGeneratorPluginOptions {
|
|
3
|
+
/** If true, the plugin will not emit any files.
|
|
4
|
+
* @default true
|
|
5
|
+
*/
|
|
6
|
+
emitFile?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* The output file name for the generated types.
|
|
9
|
+
* @default "models.typegen.ts"
|
|
10
|
+
*/
|
|
11
|
+
fileName?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Whether to include the generated types in the output object.
|
|
14
|
+
* @default false
|
|
15
|
+
*/
|
|
16
|
+
emitOutput?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare const DEFAULT_OPTIONS: Required<ModelTypesGeneratorPluginOptions>;
|
|
19
|
+
export declare const mergeOptions: (options?: ModelTypesGeneratorPluginOptions) => Required<ModelTypesGeneratorPluginOptions>;
|
|
2
20
|
export declare const isOperationNode: (node: DefinitionNode) => boolean;
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* @param field Field node to check for non-nullability
|
|
6
|
-
* @returns True if the field is non-nullable, false otherwise
|
|
7
|
-
*
|
|
8
|
-
* TODO: check for semantic nullability based on directives.
|
|
9
|
-
*/
|
|
10
|
-
export declare const isNonNullableField: (field: FieldNode | InputValueNode) => boolean;
|
|
11
21
|
export declare const getBuildinScalarTypeKeyword: (typeName: string) => string;
|
|
12
22
|
//# sourceMappingURL=ModelTypesGeneratorPlugin.utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelTypesGeneratorPlugin.utils.d.ts","sourceRoot":"","sources":["../../../src/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.utils.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ModelTypesGeneratorPlugin.utils.d.ts","sourceRoot":"","sources":["../../../src/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,MAAM,WAAW,gCAAgC;IAC/C;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,gCAAgC,CAI7D,CAAC;AAEX,eAAO,MAAM,YAAY,GACvB,UAAU,gCAAgC,KACzC,QAAQ,CAAC,gCAAgC,CAK3C,CAAC;AAIF,eAAO,MAAM,eAAe,GAAI,MAAM,cAAc,YAEnD,CAAC;AAEF,eAAO,MAAM,2BAA2B,GAAI,UAAU,MAAM,KAAG,MAa9D,CAAC"}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
export const DEFAULT_OPTIONS = {
|
|
2
|
+
emitFile: true,
|
|
3
|
+
fileName: "models.typegen.ts",
|
|
4
|
+
emitOutput: false,
|
|
5
|
+
};
|
|
6
|
+
export const mergeOptions = (options) => {
|
|
7
|
+
return {
|
|
8
|
+
...DEFAULT_OPTIONS,
|
|
9
|
+
...options,
|
|
10
|
+
};
|
|
11
|
+
};
|
|
2
12
|
const OPERATION_NODE_NAME = ["Query", "Mutation", "Subscription"];
|
|
3
13
|
export const isOperationNode = (node) => {
|
|
4
14
|
return OPERATION_NODE_NAME.includes(node.name);
|
|
5
15
|
};
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
* @param field Field node to check for non-nullability
|
|
9
|
-
* @returns True if the field is non-nullable, false otherwise
|
|
10
|
-
*
|
|
11
|
-
* TODO: check for semantic nullability based on directives.
|
|
12
|
-
*/
|
|
13
|
-
export const isNonNullableField = (field) => {
|
|
14
|
-
return field.type instanceof NonNullTypeNode;
|
|
15
|
-
};
|
|
16
16
|
export const getBuildinScalarTypeKeyword = (typeName) => {
|
|
17
17
|
switch (typeName) {
|
|
18
18
|
case "ID":
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelTypesGeneratorPlugin.utils.js","sourceRoot":"","sources":["../../../src/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ModelTypesGeneratorPlugin.utils.js","sourceRoot":"","sources":["../../../src/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.utils.ts"],"names":[],"mappings":"AAqBA,MAAM,CAAC,MAAM,eAAe,GAA+C;IACzE,QAAQ,EAAE,IAAI;IACd,QAAQ,EAAE,mBAAmB;IAC7B,UAAU,EAAE,KAAK;CACT,CAAC;AAEX,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,OAA0C,EACE,EAAE;IAC9C,OAAO;QACL,GAAG,eAAe;QAClB,GAAG,OAAO;KACX,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,mBAAmB,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,cAAc,CAAU,CAAC;AAE3E,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAoB,EAAE,EAAE;IACtD,OAAO,mBAAmB,CAAC,QAAQ,CAAC,IAAI,CAAC,IAA4C,CAAC,CAAC;AACzF,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,QAAgB,EAAU,EAAE;IACtE,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,IAAI,CAAC;QACV,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,KAAK,CAAC;QACX,KAAK,OAAO;YACV,OAAO,QAAQ,CAAC;QAClB,KAAK,SAAS;YACZ,OAAO,SAAS,CAAC;QACnB;YACE,MAAM,IAAI,KAAK,CAAC,qCAAqC,QAAQ,EAAE,CAAC,CAAC;IACrE,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -2,12 +2,20 @@ import { ITransformerContext, ITransformerPlugin } from "@gqlbase/core";
|
|
|
2
2
|
import { DefinitionNode, InterfaceNode, ObjectNode } from "@gqlbase/core/definition";
|
|
3
3
|
import { RelationPluginOptions } from "./RelationsPlugin.utils.js";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* This plugin is responsible for adding the `@hasOne` and `@hasMany` directives to the schema, which can be used to define relationships between types.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* It also adds the necessary fields and arguments to the schema to support these directives.
|
|
8
8
|
*
|
|
9
|
+
* @definition
|
|
9
10
|
* ```graphql
|
|
11
|
+
* directive `@hasOne(key: String)` on FIELD_DEFINITION
|
|
12
|
+
*
|
|
13
|
+
* directive `@hasMany(key: String)` on FIELD_DEFINITION
|
|
14
|
+
*
|
|
15
|
+
* ```
|
|
10
16
|
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```graphql
|
|
11
19
|
* # Before
|
|
12
20
|
* type User {
|
|
13
21
|
* id: ID!
|
|
@@ -25,24 +33,21 @@ import { RelationPluginOptions } from "./RelationsPlugin.utils.js";
|
|
|
25
33
|
* type User {
|
|
26
34
|
* id: ID!
|
|
27
35
|
* name: String!
|
|
28
|
-
* posts: [Post]
|
|
36
|
+
* posts: [Post] # formatted by the plugin
|
|
29
37
|
* }
|
|
30
38
|
*
|
|
31
39
|
* type Post {
|
|
32
40
|
* id: ID!
|
|
33
41
|
* title: String!
|
|
34
|
-
* authorId: ID
|
|
42
|
+
* authorId: ID # added by the plugin
|
|
35
43
|
* author: User
|
|
36
44
|
* }
|
|
37
45
|
* ```
|
|
38
|
-
*
|
|
39
|
-
* In the above example, the `User` type has a `posts` field that is decorated with the `@hasMany` directive, indicating that a user can have many posts. The plugin will automatically add the necessary fields and arguments to support this relationship in the schema.
|
|
40
|
-
*
|
|
41
46
|
*/
|
|
42
47
|
export declare class RelationsPlugin implements ITransformerPlugin {
|
|
43
48
|
readonly name = "RelationsPlugin";
|
|
44
49
|
readonly context: ITransformerContext;
|
|
45
|
-
private readonly
|
|
50
|
+
private readonly options;
|
|
46
51
|
constructor(context: ITransformerContext, options?: RelationPluginOptions);
|
|
47
52
|
private _getRelationshipTarget;
|
|
48
53
|
private _getFieldRelation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RelationsPlugin.d.ts","sourceRoot":"","sources":["../../../src/base/RelationsPlugin/RelationsPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC7F,OAAO,EACL,cAAc,EAId,aAAa,EAGb,UAAU,EAEX,MAAM,0BAA0B,CAAC;AAGlC,OAAO,
|
|
1
|
+
{"version":3,"file":"RelationsPlugin.d.ts","sourceRoot":"","sources":["../../../src/base/RelationsPlugin/RelationsPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC7F,OAAO,EACL,cAAc,EAId,aAAa,EAGb,UAAU,EAEX,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EASL,qBAAqB,EAEtB,MAAM,4BAA4B,CAAC;AAGpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH,qBAAa,eAAgB,YAAW,kBAAkB;IACxD,QAAQ,CAAC,IAAI,qBAAqB;IAClC,QAAQ,CAAC,OAAO,EAAE,mBAAmB,CAAC;IACtC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkC;gBAE9C,OAAO,EAAE,mBAAmB,EAAE,OAAO,GAAE,qBAA0B;IAO7E,OAAO,CAAC,sBAAsB;IAgB9B,OAAO,CAAC,iBAAiB;IAazB,OAAO,CAAC,eAAe;IAMvB,OAAO,CAAC,uBAAuB;IAU/B,OAAO,CAAC,sBAAsB;IAiBvB,IAAI;IAkBJ,KAAK,CAAC,UAAU,EAAE,cAAc,GAAG,OAAO;IAW1C,SAAS,CAAC,UAAU,EAAE,UAAU,GAAG,aAAa,GAAG,IAAI;IAiC9D,OAAO,CAAC,UAAU,EAAE,UAAU,GAAG,aAAa,GAAG,IAAI;IAoB9C,OAAO,CAAC,UAAU,EAAE,UAAU,GAAG,aAAa,GAAG,IAAI;IAY5D,KAAK,IAAI,IAAI;CAKd;AAED,eAAO,MAAM,cAAc,yFAAuC,CAAC"}
|
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import { createPluginFactory } from "@gqlbase/core";
|
|
2
2
|
import { DirectiveDefinitionNode, FieldNode, InputValueNode, InterfaceNode, ListTypeNode, NamedTypeNode, ObjectNode, UnionNode, } from "@gqlbase/core/definition";
|
|
3
3
|
import { TransformerPluginExecutionError } from "@gqlbase/shared/errors";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { pascalCase } from "@gqlbase/shared/format";
|
|
5
|
+
import { isPaginationConnection, isManyRelationship, isOneRelationship, isRelationField, isValidRelationTarget, parseFieldRelation, RelationDirective, } from "./RelationsPlugin.utils.js";
|
|
6
6
|
import { isListTypeNode } from "../ModelPlugin/ModelPlugin.utils.js";
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* This plugin is responsible for adding the `@hasOne` and `@hasMany` directives to the schema, which can be used to define relationships between types.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* It also adds the necessary fields and arguments to the schema to support these directives.
|
|
11
11
|
*
|
|
12
|
+
* @definition
|
|
12
13
|
* ```graphql
|
|
14
|
+
* directive `@hasOne(key: String)` on FIELD_DEFINITION
|
|
15
|
+
*
|
|
16
|
+
* directive `@hasMany(key: String)` on FIELD_DEFINITION
|
|
17
|
+
*
|
|
18
|
+
* ```
|
|
13
19
|
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```graphql
|
|
14
22
|
* # Before
|
|
15
23
|
* type User {
|
|
16
24
|
* id: ID!
|
|
@@ -28,64 +36,40 @@ import { isListTypeNode } from "../ModelPlugin/ModelPlugin.utils.js";
|
|
|
28
36
|
* type User {
|
|
29
37
|
* id: ID!
|
|
30
38
|
* name: String!
|
|
31
|
-
* posts: [Post]
|
|
39
|
+
* posts: [Post] # formatted by the plugin
|
|
32
40
|
* }
|
|
33
41
|
*
|
|
34
42
|
* type Post {
|
|
35
43
|
* id: ID!
|
|
36
44
|
* title: String!
|
|
37
|
-
* authorId: ID
|
|
45
|
+
* authorId: ID # added by the plugin
|
|
38
46
|
* author: User
|
|
39
47
|
* }
|
|
40
48
|
* ```
|
|
41
|
-
*
|
|
42
|
-
* In the above example, the `User` type has a `posts` field that is decorated with the `@hasMany` directive, indicating that a user can have many posts. The plugin will automatically add the necessary fields and arguments to support this relationship in the schema.
|
|
43
|
-
*
|
|
44
49
|
*/
|
|
45
50
|
export class RelationsPlugin {
|
|
46
51
|
name = "RelationsPlugin";
|
|
47
52
|
context;
|
|
48
|
-
|
|
49
|
-
constructor(context, options = {
|
|
53
|
+
options;
|
|
54
|
+
constructor(context, options = {}) {
|
|
50
55
|
this.context = context;
|
|
51
|
-
this.
|
|
56
|
+
this.options = {
|
|
57
|
+
usePaginationTypes: options.usePaginationTypes ?? false,
|
|
58
|
+
};
|
|
52
59
|
}
|
|
53
|
-
_getRelationshipTarget(field) {
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
56
|
-
|
|
60
|
+
_getRelationshipTarget(object, field) {
|
|
61
|
+
const target = this.context.document.getNode(field.type.getTypeName());
|
|
62
|
+
if (!target || !isValidRelationTarget(target)) {
|
|
63
|
+
throw new TransformerPluginExecutionError(this.name, `Type ${target?.name ?? "unknwon type"} is not a valid relationship target for ${object.name}.${field.name}`);
|
|
57
64
|
}
|
|
58
|
-
return
|
|
65
|
+
return target;
|
|
59
66
|
}
|
|
60
67
|
_getFieldRelation(object, field) {
|
|
61
|
-
|
|
62
|
-
if (!target)
|
|
68
|
+
if (!isRelationField(field)) {
|
|
63
69
|
return null;
|
|
64
|
-
if (!isValidRelationTarget(target)) {
|
|
65
|
-
throw new TransformerPluginExecutionError(this.name, `Type ${target.name} is not a valid relationship target for ${object.name}.${field.name}`);
|
|
66
|
-
}
|
|
67
|
-
let directive = field.getDirective(RelationDirective.HAS_ONE);
|
|
68
|
-
if (directive) {
|
|
69
|
-
if (field.hasDirective(RelationDirective.HAS_MANY)) {
|
|
70
|
-
throw new TransformerPluginExecutionError(this.name, `Multiple relationship directives detected for ${object.name}.${field.name}`);
|
|
71
|
-
}
|
|
72
|
-
const args = directive.getArgumentsJSON();
|
|
73
|
-
return {
|
|
74
|
-
type: "oneToOne",
|
|
75
|
-
target: target,
|
|
76
|
-
key: args.key ?? camelCase(field.name, "id"),
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
directive = field.getDirective(RelationDirective.HAS_MANY);
|
|
80
|
-
if (directive) {
|
|
81
|
-
const args = directive.getArgumentsJSON();
|
|
82
|
-
return {
|
|
83
|
-
type: "oneToMany",
|
|
84
|
-
target: target,
|
|
85
|
-
key: args.key ?? camelCase(object.name, "id"),
|
|
86
|
-
};
|
|
87
70
|
}
|
|
88
|
-
|
|
71
|
+
const target = this._getRelationshipTarget(object, field);
|
|
72
|
+
return parseFieldRelation(object, field, target);
|
|
89
73
|
}
|
|
90
74
|
_setRelationKey(node, key) {
|
|
91
75
|
if (!node.hasField(key)) {
|
|
@@ -102,7 +86,7 @@ export class RelationsPlugin {
|
|
|
102
86
|
}
|
|
103
87
|
_createFieldConnection(field, target) {
|
|
104
88
|
this._setConnectionArguments(field);
|
|
105
|
-
if (
|
|
89
|
+
if (isPaginationConnection(target)) {
|
|
106
90
|
return target;
|
|
107
91
|
}
|
|
108
92
|
const connectionTypeName = pascalCase(target.name, "Connection");
|
|
@@ -119,7 +103,7 @@ export class RelationsPlugin {
|
|
|
119
103
|
if (definition instanceof InterfaceNode || definition instanceof ObjectNode) {
|
|
120
104
|
if (definition.name === "Mutation")
|
|
121
105
|
return false;
|
|
122
|
-
if (
|
|
106
|
+
if (isPaginationConnection(definition))
|
|
123
107
|
return false;
|
|
124
108
|
if (!definition.fields?.length)
|
|
125
109
|
return false;
|
|
@@ -158,7 +142,7 @@ export class RelationsPlugin {
|
|
|
158
142
|
if (!relation || relation.type === "oneToOne") {
|
|
159
143
|
continue;
|
|
160
144
|
}
|
|
161
|
-
if (this.
|
|
145
|
+
if (this.options.usePaginationTypes) {
|
|
162
146
|
const connection = this._createFieldConnection(field, relation.target);
|
|
163
147
|
field.setType(NamedTypeNode.create(connection.name));
|
|
164
148
|
continue;
|