dotansimha / dotansimha/graphql-code-generator-community

The `typescript-urql-graphcache` plugin does not respect the `import-types` preset configuration

Open
#185 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
137
Forks
195
Avg merge
6h 20m
Merged PRs (30d)
16

Description

### Issue workflow progress

_Progress of the issue based on the [Contributor Workflow](https://github.com/the-guild-org/Stack/blob/master/CONTRIBUTING.md#a-typical-contributor-workflow)_

- [ ] 1. The issue provides a reproduction available on [Github](https://github.com/dotansimha/graphql-code-generator-issue-sandbox-template), [Stackblitz](https://stackblitz.com/github/dotansimha/graphql-code-generator-issue-sandbox-template) or [CodeSandbox](https://codesandbox.io/s/github/dotansimha/graphql-code-generator-issue-sandbox-template)
_Make sure to fork this template and run `yarn generate` in the terminal._
_Please make sure the Codegen and plugins version under `package.json` matches yours._
- [ ] 2. A failing test has been provided
- [ ] 3. A local solution has been provided
- [ ] 4. A pull request is pending review

---
**Describe the bug**

**To Reproduce**
Steps to reproduce the behavior:

1. My GraphQL schema:
N/A

2. My GraphQL operations:
N/A

3. My `codegen.yml` config file:

```yaml
schema: http://192.168.0.11:8080/graphql
documents: 'src/**/*.graphql'

generates:
./src/schema.ts:
hooks:
afterOneFileWrite:
- eslint --fix
plugins:
- typescript

config:
maybeValue: T | undefined
useTypeImports: true

./src/index.ts:
preset: import-types

presetConfig:
typesPath: ./schema
importTypesNamespace: Schema

hooks:
afterOneFileWrite:
- eslint --fix

plugins:
- typescript-operations
- typescript-resolvers
- typed-document-node
- urql-svelte-operations-store
- typescript-urql-graphcache

config:
maybeValue: T | undefined
useTypeImports: true

./src/schema.graphql:
plugins:
- schema-ast
```

**Expected behavior**
Generating `typescript-urql-graphcache` should generate types with the respected namespace (in this case schema) but instead it ignores it.
For example, here is the output generated by another plugin. The namespace is respected (ie. `Schema.Address`)
```ts
export type ResolversTypes = {
Address: ResolverTypeWrapper;
}
```

Here is the output of `typescript-urql-graphcache`:
```ts
export type GraphCacheKeysConfig = {
Address?: (data: WithTypename

) => null | string,
}
```
In this case the namespace is not respected.

**Environment:**

- OS: macOS 12.3
- `@graphql-codegen/...`:
```json
{
"@graphql-codegen/cli": "^1.21.8",
"@graphql-codegen/import-types-preset": "^2.1.15",
"@graphql-codegen/near-operation-file-preset": "^2.2.9",
"@graphql-codegen/schema-ast": "^1.18.3",
"@graphql-codegen/typed-document-node": "^2.2.8",
"@graphql-codegen/typescript": "^1.23.0",
"@graphql-codegen/typescript-operations": "^1.18.4",
"@graphql-codegen/typescript-resolvers": "^2.6.1",
"@graphql-codegen/typescript-urql-graphcache": "^2.2.10",
"@graphql-codegen/urql-svelte-operations-store": "^1.1.15"
}
```
- NodeJS: 16.5.0

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the typescript-urql-graphcache plugin entry point and reproduce the configuration shown in the issue, using the import-types preset with importTypesNamespace: Schema. Compare its generated GraphCacheKeysConfig types with the namespace-qualified output from the other plugin; done means generated references respect Schema and a regression test covers this configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.