dotansimha / dotansimha/graphql-code-generator-community

[typescript-react-query] malformed files created 4.0.6 and later

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

Description

### Which packages are impacted by your issue?

@graphql-codegen/typescript-react-query

### Describe the bug

After updating my version of typescript-react-query as an attempt to deal with a different type issue I noted this output:

```ts
import * as Types from './types'

import { GraphQLClient } from 'graphql-request';
import { useMutation, UseMutationOptions } from '@tanstack/react-query';

import fetcher from '../../fetchers/fetcher';
>(client: GraphQLClient, query: string, variables?: TVariables, requestHeaders?: RequestInit['headers']) {
return async (): Promise => client.request({
document: query,
variables,
requestHeaders
});
}
export type AuthenticateUserMutationVariables = Types.Exact<{
input: Types.UserAuthenticationInput;
}>;
```

You can see that after `import fetcher` code appears to be generated in the wrong place.

I narrowed this down to version 4.0.6 after rolling back to a previously working version.

### Your Example Website or App

N/A

### Steps to Reproduce the Bug or Issue

Using the given codegen file plugins I'd attempt to see if the same result can be reproduced. Sorry, I haven't been able to reproduce in a shareable example.

### Expected behavior

I mostly expected similar output but it would be great if this type issue was also solved:

```bash
Argument of type 'HeadersInit | undefined' is not assignable to parameter of type 'HeadersInit | undefined'.
Type 'string[][]' is not assignable to type 'HeadersInit | undefined'.
Type 'string[][]' is not assignable to type '[string, string][]'.
Type 'string[]' is not assignable to type '[string, string]'.
Target requires 2 element(s) but source may have fewer.ts(2345)
```

### Screenshots or Videos

_No response_

### Platform

- OS: MacOs
- NodeJS: 16.19.1
- `graphql` version: 16.6.0
- `@graphql-codegen/cli`: "3.2.2",
- `@graphql-codegen/introspection`: "3.0.1"
- `@graphql-codegen/near-operation-file-preset`: "2.5.0"
- `@graphql-codegen/typescript`: "3.0.2"
- `@graphql-codegen/typescript-operations`: "3.0.2"
- `@graphql-codegen/typescript-react-query`: "4.0.6"

### Codegen Config File

```yaml
overwrite: true
schema: ''
documents: ['libs/api/src/lib/queries/**/*.graphql', 'libs/api/src/lib/mutations/**/*.graphql']
generates:
libs/api/src/lib/generated/graphql/types.ts:
plugins:
- 'typescript'
- add:
placement: 'prepend'
content: >
/* eslint-disable */
config:
# typescript: https://www.the-guild.dev/graphql/codegen/plugins/typescript/typescript
constEnums: true
useImplementingTypes: true
useTypeImports: true
libs/api:
preset: near-operation-file
presetConfig:
baseTypesPath: ./types.ts # Tell it where to import these from
extension: .graphql.ts
plugins:
- 'typescript-operations'
- 'typescript-react-query'
- add:
placement: 'prepend'
content: >
/* eslint-disable */

/**
* WARNING: THIS FILE IS AUTO-GENERATED, DO NOT EDIT IT DIRECTLY!
*/
config:
# react-query: https://www.the-guild.dev/graphql/codegen/plugins/typescript/typescript-react-query
fetcher: graphql-request
pureMagicComment: true
exposeFetcher: false
dedupeFragments: true
```

### Additional context

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.