dotansimha / dotansimha/graphql-code-generator

Nested fragments do not work with client-preset and documentMode="string"

Open
#9,356 0 comments 4 reactions 1 assignee Claimed by @beerose View on GitHub
kind/bug stage/1-reproduction
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

### Which packages are impacted by your issue?

@graphql-codegen/client-preset

### Describe the bug

When using `documentMode: "string"` with @graphql-codegen/client-preset, in case of nested fragments, only the first level of fragments are included in the final query.

The Github repo reproduces the issue clearly.

### Your Example Website or App

https://github.com/stefanoverna/codegen-string-bug

### Steps to Reproduce the Bug or Issue

```
yarn
yarn start
```

Notice that the output on the page is just:

```
query Video($id: ID!) {
video(id: $id) {
...DetailsFragment
__typename
}
}

fragment DetailsFragment on Video {
title
__typename
...MovieFragment
...EpisodeFragment
}
```

So, MovieFragment and EpisodeFragment are missing.

### Expected behavior

`MovieFragment` and `EpisodeFragment` should be part of the query.

### Screenshots or Videos

_No response_

### Platform

- OS: macOs
- NodeJS: 16.20.0
- `graphql` version: 16.6.0
- `@graphql-codegen/client-preset` version: 3.0.1

### Codegen Config File

```
import { CodegenConfig } from "@graphql-codegen/cli";

const config: CodegenConfig = {
schema: "schema.graphql",
documents: ["src/**/*.tsx", "!src/gql/**/*"],
generates: {
"./src/gql/": {
preset: "client",
plugins: [],
config: { documentMode: "string" },
presetConfig: {
fragmentMasking: { unmaskFunctionName: "getFragmentData" },
},
},
},
};
```

export default config;

### 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.