dotansimha / dotansimha/graphql-code-generator-community
typescript-urql-graphcache: Property '__typename' is missing in type 'DataFields'
- Dominant language
- TypeScript
- Stars
- 137
- Forks
- 195
- Avg merge
- 6h 20m
- Merged PRs (30d)
- 16
Description
### Which packages are impacted by your issue?
_No response_
### Describe the bug
When using `@graphql-codegen/typescript-urql-graphcache` at version `^3.1.0` the resulting types aren't compatible with `urql`'s `cacheExchange` types.
It seems to work with an older version of `@graphql-codegen/typescript-urql-graphcache` though, like `^2.4.0`
### Your Example Website or App
Sorry, can't really provide one
### Steps to Reproduce the Bug or Issue
Generated admin type:
```ts
export type Admin = {
__typename?: 'Admin';
email: Scalars['String']['output'];
...
};
```
Generated `GraphCacheUpdaters`:
```ts
export type GraphCacheUpdaters = {
Query?: {
currentAdmin?: GraphCacheUpdateResolver<
{ currentAdmin: Maybe> },
Record
>;
...
}
}
```
urql cacheExchange:
```ts
import type {
GraphCacheKeysConfig,
GraphCacheOptimisticUpdaters,
GraphCacheResolvers,
GraphCacheUpdaters,
} from 'schema';
const cache = cacheExchange<{
updates?: GraphCacheUpdaters;
keys?: GraphCacheKeysConfig;
optimistic?: GraphCacheOptimisticUpdaters;
resolvers?: GraphCacheResolvers;
schema: IntrospectionQuery;
}>({ ... });
```
Error message:
```
Type '{ updates?: GraphCacheUpdaters | undefined; keys?: GraphCacheKeysConfig | undefined; optimistic?: GraphCacheOptimisticUpdaters | undefined; resolvers?: GraphCacheResolvers | undefined; schema: IntrospectionQuery; }' does not satisfy the constraint 'Partial'.
Types of property 'updates' are incompatible.
Type 'GraphCacheUpdaters | undefined' is not assignable to type 'UpdatesConfig | undefined'.
Type 'GraphCacheUpdaters' is not assignable to type 'UpdatesConfig'.
Property 'Admin' is incompatible with index signature.
Type '{ createdAt?: UpdateResolver>, Record> | undefined; email?: UpdateResolver>, Record<...>> | undefined; ... 6 more ...; verifiedAt?: UpdateResolver<...> | undefined; }' is not assignable to type 'void | { [fieldName: string]: void | ((parent: DataFields, args: Variables, cache: Cache, info: ResolveInfo) => void); }'.
Type '{ createdAt?: UpdateResolver>, Record> | undefined; email?: UpdateResolver>, Record<...>> | undefined; ... 6 more ...; verifiedAt?: UpdateResolver<...> | undefined; }' is not assignable to type '{ [fieldName: string]: void | ((parent: DataFields, args: Variables, cache: Cache, info: ResolveInfo) => void); }'.
Property 'createdAt' is incompatible with index signature.
Type 'UpdateResolver>, Record>' is not assignable to type 'void | ((parent: DataFields, args: Variables, cache: Cache, info: ResolveInfo) => void)'.
Type 'UpdateResolver>, Record>' is not assignable to type '(parent: DataFields, args: Variables, cache: Cache, info: ResolveInfo) => void'.
Types of parameters 'parent' and 'parent' are incompatible.
Type 'DataFields' is not assignable to type 'Maybe>'.
Property '__typename' is missing in type 'DataFields' but required in type '{ __typename: "Admin"; }'.
```
### Expected behavior
No type errors
### Screenshots or Videos
_No response_
### Platform
- OS: macOS
- NodeJS: v20
- `graphql` version: ^16.8.1
- `@graphql-codegen/*` version(s):
```
"@graphql-codegen/cli": "^5.0.0",
"@graphql-codegen/client-preset": "4.1.0",
"@graphql-codegen/typescript-urql-graphcache": "^3.1.0",
"@graphql-codegen/urql-introspection": "^3.0.0",
```
### Codegen Config File
```ts
import type { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
overwrite: true,
schema: 'http://127.0.0.1:8080/graphql',
documents: ['packages/common/data/**/*.ts'],
generates: {
'packages/common/data/schema.introspection.ts': {
plugins: ['urql-introspection'],
config: {
useTypeImports: true,
includeScalars: true,
includeEnums: true,
includeInputs: true,
includeDirectives: true,
},
},
'packages/common/data/schema.ts': {
plugins: ['typescript', 'typescript-urql-graphcache'],
},
'packages/common/data/gql/': {
preset: 'client',
presetConfig: {
fragmentMasking: { unmaskFunctionName: 'getFragmentData' },
},
},
},
hooks: { afterAllFileWrite: ['prettier --write', 'eslint --fix'] },
};
export default config;
```
### Additional context
_No response_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.