@graphql-codegen/typescript-urql 3.4.3-alpha-bc33c031d.0 → 3.5.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/index.js +3 -3
- package/index.mjs +3 -3
- package/package.json +3 -4
package/index.js
CHANGED
|
@@ -8,7 +8,6 @@ const pluginHelpers = require('@graphql-codegen/plugin-helpers');
|
|
|
8
8
|
const graphql = require('graphql');
|
|
9
9
|
const visitorPluginCommon = require('@graphql-codegen/visitor-plugin-common');
|
|
10
10
|
const autoBind = _interopDefault(require('auto-bind'));
|
|
11
|
-
const changeCaseAll = require('change-case-all');
|
|
12
11
|
const path = require('path');
|
|
13
12
|
|
|
14
13
|
class UrqlVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
|
|
@@ -69,7 +68,7 @@ export const ${componentName} = (props: Omit<Urql.${operationType}Props<${generi
|
|
|
69
68
|
_buildHooks(node, operationType, documentVariableName, operationResultType, operationVariablesTypes) {
|
|
70
69
|
var _a, _b;
|
|
71
70
|
const operationName = this.convertName((_b = (_a = node.name) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '', {
|
|
72
|
-
suffix: this.
|
|
71
|
+
suffix: this.getOperationSuffix(node, operationType),
|
|
73
72
|
useTypesPrefix: false,
|
|
74
73
|
});
|
|
75
74
|
if (operationType === 'Mutation') {
|
|
@@ -84,8 +83,9 @@ export function use${operationName}<TData = ${operationResultType}>(options: Omi
|
|
|
84
83
|
return Urql.use${operationType}<${operationResultType}, TData, ${operationVariablesTypes}>({ query: ${documentVariableName}, ...options }, handler);
|
|
85
84
|
};`;
|
|
86
85
|
}
|
|
86
|
+
const isVariablesRequired = node.variableDefinitions.some(variableDef => variableDef.type.kind === graphql.Kind.NON_NULL_TYPE && variableDef.defaultValue == null);
|
|
87
87
|
return `
|
|
88
|
-
export function use${operationName}(options: Omit<Urql.Use${operationType}Args<${operationVariablesTypes}>, 'query'>
|
|
88
|
+
export function use${operationName}(options${isVariablesRequired ? '' : '?'}: Omit<Urql.Use${operationType}Args<${operationVariablesTypes}>, 'query'>) {
|
|
89
89
|
return Urql.use${operationType}<${operationResultType}>({ query: ${documentVariableName}, ...options });
|
|
90
90
|
};`;
|
|
91
91
|
}
|
package/index.mjs
CHANGED
|
@@ -2,7 +2,6 @@ import { oldVisit } from '@graphql-codegen/plugin-helpers';
|
|
|
2
2
|
import { Kind, concatAST } from 'graphql';
|
|
3
3
|
import { ClientSideBaseVisitor, getConfigValue, DocumentMode, OMIT_TYPE } from '@graphql-codegen/visitor-plugin-common';
|
|
4
4
|
import autoBind from 'auto-bind';
|
|
5
|
-
import { pascalCase } from 'change-case-all';
|
|
6
5
|
import { extname } from 'path';
|
|
7
6
|
|
|
8
7
|
class UrqlVisitor extends ClientSideBaseVisitor {
|
|
@@ -63,7 +62,7 @@ export const ${componentName} = (props: Omit<Urql.${operationType}Props<${generi
|
|
|
63
62
|
_buildHooks(node, operationType, documentVariableName, operationResultType, operationVariablesTypes) {
|
|
64
63
|
var _a, _b;
|
|
65
64
|
const operationName = this.convertName((_b = (_a = node.name) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '', {
|
|
66
|
-
suffix: this.
|
|
65
|
+
suffix: this.getOperationSuffix(node, operationType),
|
|
67
66
|
useTypesPrefix: false,
|
|
68
67
|
});
|
|
69
68
|
if (operationType === 'Mutation') {
|
|
@@ -78,8 +77,9 @@ export function use${operationName}<TData = ${operationResultType}>(options: Omi
|
|
|
78
77
|
return Urql.use${operationType}<${operationResultType}, TData, ${operationVariablesTypes}>({ query: ${documentVariableName}, ...options }, handler);
|
|
79
78
|
};`;
|
|
80
79
|
}
|
|
80
|
+
const isVariablesRequired = node.variableDefinitions.some(variableDef => variableDef.type.kind === Kind.NON_NULL_TYPE && variableDef.defaultValue == null);
|
|
81
81
|
return `
|
|
82
|
-
export function use${operationName}(options: Omit<Urql.Use${operationType}Args<${operationVariablesTypes}>, 'query'>
|
|
82
|
+
export function use${operationName}(options${isVariablesRequired ? '' : '?'}: Omit<Urql.Use${operationType}Args<${operationVariablesTypes}>, 'query'>) {
|
|
83
83
|
return Urql.use${operationType}<${operationResultType}>({ query: ${documentVariableName}, ...options });
|
|
84
84
|
};`;
|
|
85
85
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/typescript-urql",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "GraphQL Code Generator plugin for generating an introspection file for Urql's Schema Awareness",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
|
|
7
7
|
"graphql-tag": "^2.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@graphql-codegen/plugin-helpers": "2.3.
|
|
11
|
-
"@graphql-codegen/visitor-plugin-common": "2.5.
|
|
10
|
+
"@graphql-codegen/plugin-helpers": "^2.3.2",
|
|
11
|
+
"@graphql-codegen/visitor-plugin-common": "2.5.2",
|
|
12
12
|
"auto-bind": "~4.0.0",
|
|
13
|
-
"change-case-all": "1.0.14",
|
|
14
13
|
"tslib": "~2.3.0"
|
|
15
14
|
},
|
|
16
15
|
"repository": {
|