@vladimirdev635/gql-codegen 0.0.48 → 0.0.49
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.
|
@@ -52,8 +52,11 @@ function generateArrowFunction(operationName, variablesName, resultName, type) {
|
|
|
52
52
|
}
|
|
53
53
|
export function generateNodes(config, context) {
|
|
54
54
|
const graphqlImports = [];
|
|
55
|
+
let hasSubscriptions = false;
|
|
55
56
|
const nodes = Object.values(context.schema.client.operations)
|
|
56
57
|
.map(operation => {
|
|
58
|
+
if (operation.type === 'SUBSCRIPTION')
|
|
59
|
+
hasSubscriptions = true;
|
|
57
60
|
const operationName = operation.name + 'Operation';
|
|
58
61
|
const variablesName = operation.name + 'Variables';
|
|
59
62
|
const resultName = operation.name + 'Result';
|
|
@@ -68,15 +71,19 @@ export function generateNodes(config, context) {
|
|
|
68
71
|
ts.factory.createPropertyAssignment('useLazy' + operationName, generateArrowFunction(operationName, variablesName, resultName, 'LAZY'))
|
|
69
72
|
];
|
|
70
73
|
}).flat();
|
|
74
|
+
const gqlClientReactImports = [
|
|
75
|
+
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('useOperation')),
|
|
76
|
+
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('useLazyOperation')),
|
|
77
|
+
ts.factory.createImportSpecifier(true, undefined, ts.factory.createIdentifier('OperationState')),
|
|
78
|
+
ts.factory.createImportSpecifier(true, undefined, ts.factory.createIdentifier('UseLazyOperationReturnType'))
|
|
79
|
+
];
|
|
80
|
+
if (hasSubscriptions) {
|
|
81
|
+
gqlClientReactImports.push(ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('useSubscription')), ts.factory.createImportSpecifier(true, undefined, ts.factory.createIdentifier('SubOpAsyncIterable')));
|
|
82
|
+
}
|
|
71
83
|
return [
|
|
72
84
|
ts.factory.createIdentifier('// @ts-nocheck'),
|
|
73
85
|
...config.importDeclarations,
|
|
74
|
-
ts.factory.createImportDeclaration([], ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports(
|
|
75
|
-
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('useOperation')),
|
|
76
|
-
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('useLazyOperation')),
|
|
77
|
-
ts.factory.createImportSpecifier(true, undefined, ts.factory.createIdentifier('OperationState')),
|
|
78
|
-
ts.factory.createImportSpecifier(true, undefined, ts.factory.createIdentifier('UseLazyOperationReturnType'))
|
|
79
|
-
])), ts.factory.createStringLiteral('@vladimirdev635/gql-client-react')),
|
|
86
|
+
ts.factory.createImportDeclaration([], ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports(gqlClientReactImports)), ts.factory.createStringLiteral('@vladimirdev635/gql-client-react')),
|
|
80
87
|
ts.factory.createImportDeclaration([], ts.factory.createImportClause(true, undefined, ts.factory.createNamedImports([
|
|
81
88
|
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('Executor')),
|
|
82
89
|
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('RequestContext'))
|