@graphql-codegen/typescript-urql-graphcache 2.4.3 → 2.4.5-alpha-20230501084624-199d88962
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 +19 -9
- package/esm/index.js +20 -10
- package/package.json +6 -6
- package/typings/config.d.cts +1 -1
- package/typings/config.d.ts +1 -1
package/cjs/index.js
CHANGED
|
@@ -49,7 +49,10 @@ function constructType(typeNode, schema, convertName, config, nullable = true, a
|
|
|
49
49
|
? `Maybe<Scalars['${type.name}']${allowString ? ' | string' : ''}>`
|
|
50
50
|
: `Scalars['${type.name}']${allowString ? ' | string' : ''}`;
|
|
51
51
|
}
|
|
52
|
-
const tsTypeName = convertName(typeNode.name, {
|
|
52
|
+
const tsTypeName = convertName(typeNode.name, {
|
|
53
|
+
prefix: config.typesPrefix,
|
|
54
|
+
suffix: config.typesSuffix,
|
|
55
|
+
});
|
|
53
56
|
if ((0, graphql_1.isUnionType)(type) || (0, graphql_1.isInputObjectType)(type) || (0, graphql_1.isObjectType)(type)) {
|
|
54
57
|
const finalType = `WithTypename<${tsTypeName}>${allowString ? ' | string' : ''}`;
|
|
55
58
|
return nullable ? `Maybe<${finalType}>` : finalType;
|
|
@@ -66,7 +69,9 @@ function constructType(typeNode, schema, convertName, config, nullable = true, a
|
|
|
66
69
|
});
|
|
67
70
|
return `WithTypename<${tsPossibleTypeName}>`;
|
|
68
71
|
});
|
|
69
|
-
const finalType = allowString
|
|
72
|
+
const finalType = allowString
|
|
73
|
+
? possibleTypes.join(' | ') + ' | string'
|
|
74
|
+
: possibleTypes.join(' | ');
|
|
70
75
|
return nullable ? `Maybe<${finalType}>` : finalType;
|
|
71
76
|
}
|
|
72
77
|
throw new Error(`Unhandled type ${type}`);
|
|
@@ -107,7 +112,10 @@ function getResolversConfig(schema, convertName, config) {
|
|
|
107
112
|
return resolvers;
|
|
108
113
|
}
|
|
109
114
|
function getRootUpdatersConfig(schema, convertName, config) {
|
|
110
|
-
const [mutationUpdaters, subscriptionUpdaters] = [
|
|
115
|
+
const [mutationUpdaters, subscriptionUpdaters] = [
|
|
116
|
+
schema.getMutationType(),
|
|
117
|
+
schema.getSubscriptionType(),
|
|
118
|
+
].map(rootType => {
|
|
111
119
|
if (rootType) {
|
|
112
120
|
const updaters = [];
|
|
113
121
|
Object.values(rootType.getFields()).forEach(field => {
|
|
@@ -140,15 +148,19 @@ function getOptimisticUpdatersConfig(schema, convertName, config) {
|
|
|
140
148
|
})
|
|
141
149
|
: 'Record<string, never>';
|
|
142
150
|
const outputType = constructType(field.type, schema, convertName, config);
|
|
143
|
-
optimistic.push(`${field.name}?: GraphCacheOptimisticMutationResolver<` +
|
|
151
|
+
optimistic.push(`${field.name}?: GraphCacheOptimisticMutationResolver<` +
|
|
152
|
+
`${argsName}, ` +
|
|
153
|
+
`${outputType}>`);
|
|
144
154
|
});
|
|
145
155
|
return optimistic;
|
|
146
156
|
}
|
|
147
157
|
return null;
|
|
148
158
|
}
|
|
149
159
|
function getImports(config) {
|
|
150
|
-
return
|
|
151
|
-
|
|
160
|
+
return [
|
|
161
|
+
'import { offlineExchange } from "@urql/exchange-graphcache";',
|
|
162
|
+
`${config.useTypeImports ? 'import type' : 'import'} { Resolver as GraphCacheResolver, UpdateResolver as GraphCacheUpdateResolver, OptimisticMutationResolver as GraphCacheOptimisticMutationResolver, StorageAdapter as GraphCacheStorageAdapter, CacheExchangeOpts } from '@urql/exchange-graphcache';\n`,
|
|
163
|
+
].join('\n');
|
|
152
164
|
}
|
|
153
165
|
const plugin = (schema, _documents, config) => {
|
|
154
166
|
const convertName = (0, visitor_plugin_common_1.convertFactory)(config);
|
|
@@ -172,13 +184,11 @@ const plugin = (schema, _documents, config) => {
|
|
|
172
184
|
' Subscription?: ' +
|
|
173
185
|
(subscriptionUpdaters ? `{\n ${subscriptionUpdaters.join(',\n ')}\n }` : '{}') +
|
|
174
186
|
',\n};',
|
|
175
|
-
'export type GraphCacheConfig = {\n' +
|
|
176
|
-
' schema?: IntrospectionData,\n' +
|
|
187
|
+
'export type GraphCacheConfig = Parameters<typeof offlineExchange>[0] & {\n' +
|
|
177
188
|
' updates?: GraphCacheUpdaters,\n' +
|
|
178
189
|
' keys?: GraphCacheKeysConfig,\n' +
|
|
179
190
|
' optimistic?: GraphCacheOptimisticUpdaters,\n' +
|
|
180
191
|
' resolvers?: GraphCacheResolvers,\n' +
|
|
181
|
-
' storage?: GraphCacheStorageAdapter\n' +
|
|
182
192
|
'};',
|
|
183
193
|
]
|
|
184
194
|
.filter(Boolean)
|
package/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GraphQLObjectType, isEnumType, isInputObjectType, isInterfaceType, isListType, isNonNullType, isObjectType, isScalarType, isUnionType, isWrappingType, } from 'graphql';
|
|
2
2
|
import { convertFactory } from '@graphql-codegen/visitor-plugin-common';
|
|
3
3
|
const unwrapType = (type) => isWrappingType(type) ? unwrapType(type.ofType) : type || null;
|
|
4
4
|
const getObjectTypes = (schema) => {
|
|
@@ -46,7 +46,10 @@ function constructType(typeNode, schema, convertName, config, nullable = true, a
|
|
|
46
46
|
? `Maybe<Scalars['${type.name}']${allowString ? ' | string' : ''}>`
|
|
47
47
|
: `Scalars['${type.name}']${allowString ? ' | string' : ''}`;
|
|
48
48
|
}
|
|
49
|
-
const tsTypeName = convertName(typeNode.name, {
|
|
49
|
+
const tsTypeName = convertName(typeNode.name, {
|
|
50
|
+
prefix: config.typesPrefix,
|
|
51
|
+
suffix: config.typesSuffix,
|
|
52
|
+
});
|
|
50
53
|
if (isUnionType(type) || isInputObjectType(type) || isObjectType(type)) {
|
|
51
54
|
const finalType = `WithTypename<${tsTypeName}>${allowString ? ' | string' : ''}`;
|
|
52
55
|
return nullable ? `Maybe<${finalType}>` : finalType;
|
|
@@ -63,7 +66,9 @@ function constructType(typeNode, schema, convertName, config, nullable = true, a
|
|
|
63
66
|
});
|
|
64
67
|
return `WithTypename<${tsPossibleTypeName}>`;
|
|
65
68
|
});
|
|
66
|
-
const finalType = allowString
|
|
69
|
+
const finalType = allowString
|
|
70
|
+
? possibleTypes.join(' | ') + ' | string'
|
|
71
|
+
: possibleTypes.join(' | ');
|
|
67
72
|
return nullable ? `Maybe<${finalType}>` : finalType;
|
|
68
73
|
}
|
|
69
74
|
throw new Error(`Unhandled type ${type}`);
|
|
@@ -104,7 +109,10 @@ function getResolversConfig(schema, convertName, config) {
|
|
|
104
109
|
return resolvers;
|
|
105
110
|
}
|
|
106
111
|
function getRootUpdatersConfig(schema, convertName, config) {
|
|
107
|
-
const [mutationUpdaters, subscriptionUpdaters] = [
|
|
112
|
+
const [mutationUpdaters, subscriptionUpdaters] = [
|
|
113
|
+
schema.getMutationType(),
|
|
114
|
+
schema.getSubscriptionType(),
|
|
115
|
+
].map(rootType => {
|
|
108
116
|
if (rootType) {
|
|
109
117
|
const updaters = [];
|
|
110
118
|
Object.values(rootType.getFields()).forEach(field => {
|
|
@@ -137,15 +145,19 @@ function getOptimisticUpdatersConfig(schema, convertName, config) {
|
|
|
137
145
|
})
|
|
138
146
|
: 'Record<string, never>';
|
|
139
147
|
const outputType = constructType(field.type, schema, convertName, config);
|
|
140
|
-
optimistic.push(`${field.name}?: GraphCacheOptimisticMutationResolver<` +
|
|
148
|
+
optimistic.push(`${field.name}?: GraphCacheOptimisticMutationResolver<` +
|
|
149
|
+
`${argsName}, ` +
|
|
150
|
+
`${outputType}>`);
|
|
141
151
|
});
|
|
142
152
|
return optimistic;
|
|
143
153
|
}
|
|
144
154
|
return null;
|
|
145
155
|
}
|
|
146
156
|
function getImports(config) {
|
|
147
|
-
return
|
|
148
|
-
|
|
157
|
+
return [
|
|
158
|
+
'import { offlineExchange } from "@urql/exchange-graphcache";',
|
|
159
|
+
`${config.useTypeImports ? 'import type' : 'import'} { Resolver as GraphCacheResolver, UpdateResolver as GraphCacheUpdateResolver, OptimisticMutationResolver as GraphCacheOptimisticMutationResolver, StorageAdapter as GraphCacheStorageAdapter, CacheExchangeOpts } from '@urql/exchange-graphcache';\n`,
|
|
160
|
+
].join('\n');
|
|
149
161
|
}
|
|
150
162
|
export const plugin = (schema, _documents, config) => {
|
|
151
163
|
const convertName = convertFactory(config);
|
|
@@ -169,13 +181,11 @@ export const plugin = (schema, _documents, config) => {
|
|
|
169
181
|
' Subscription?: ' +
|
|
170
182
|
(subscriptionUpdaters ? `{\n ${subscriptionUpdaters.join(',\n ')}\n }` : '{}') +
|
|
171
183
|
',\n};',
|
|
172
|
-
'export type GraphCacheConfig = {\n' +
|
|
173
|
-
' schema?: IntrospectionData,\n' +
|
|
184
|
+
'export type GraphCacheConfig = Parameters<typeof offlineExchange>[0] & {\n' +
|
|
174
185
|
' updates?: GraphCacheUpdaters,\n' +
|
|
175
186
|
' keys?: GraphCacheKeysConfig,\n' +
|
|
176
187
|
' optimistic?: GraphCacheOptimisticUpdaters,\n' +
|
|
177
188
|
' resolvers?: GraphCacheResolvers,\n' +
|
|
178
|
-
' storage?: GraphCacheStorageAdapter\n' +
|
|
179
189
|
'};',
|
|
180
190
|
]
|
|
181
191
|
.filter(Boolean)
|
package/package.json
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/typescript-urql-graphcache",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.5-alpha-20230501084624-199d88962",
|
|
4
4
|
"description": "GraphQL Code Generator plugin for generating a generic to be used in graphcache cache config",
|
|
5
5
|
"peerDependencies": {
|
|
6
|
+
"@urql/exchange-graphcache": "^4.1.1 || ^5.0.0",
|
|
6
7
|
"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
|
-
"graphql-tag": "^2.0.0"
|
|
8
|
-
"@urql/exchange-graphcache": "^4.1.1 || ^5.0.0"
|
|
8
|
+
"graphql-tag": "^2.0.0"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@graphql-codegen/plugin-helpers": "^
|
|
11
|
+
"@graphql-codegen/plugin-helpers": "^3.0.0",
|
|
12
12
|
"@graphql-codegen/visitor-plugin-common": "2.13.1",
|
|
13
13
|
"auto-bind": "~4.0.0",
|
|
14
|
-
"change-case-all": "1.0.
|
|
14
|
+
"change-case-all": "1.0.15",
|
|
15
15
|
"tslib": "~2.4.0"
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
|
-
"url": "https://github.com/dotansimha/graphql-code-generator.git",
|
|
19
|
+
"url": "https://github.com/dotansimha/graphql-code-generator-community.git",
|
|
20
20
|
"directory": "packages/plugins/typescript/urql-graphcache"
|
|
21
21
|
},
|
|
22
22
|
"license": "MIT",
|
package/typings/config.d.cts
CHANGED
|
@@ -2,4 +2,4 @@ import { RawClientSideBasePluginConfig } from '@graphql-codegen/visitor-plugin-c
|
|
|
2
2
|
/**
|
|
3
3
|
* @description This plugin generates a generic for the `@urql/exchange-graphcache` (https://github.com/FormidableLabs/urql/exchanges/graphcache) config.
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export type UrqlGraphCacheConfig = RawClientSideBasePluginConfig & {};
|
package/typings/config.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ import { RawClientSideBasePluginConfig } from '@graphql-codegen/visitor-plugin-c
|
|
|
2
2
|
/**
|
|
3
3
|
* @description This plugin generates a generic for the `@urql/exchange-graphcache` (https://github.com/FormidableLabs/urql/exchanges/graphcache) config.
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export type UrqlGraphCacheConfig = RawClientSideBasePluginConfig & {};
|