dotansimha / dotansimha/graphql-code-generator-community

hasura-allow-list: wrong fragment order in document mode

Open
#821 0 comments 2 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/hasura-allow-list

### Describe the bug

Following up on the great work by @shoma-mano. There seems to be an issue with the fragment order in the generated allow lists when using `fragmentOrder` set to `document` and there are nested fragments spread across several files, compared to the order generated by `typed-document-node`.

### Your Example Website or App

https://github.com/voldern/hasura-allowlist-reproduction

### Steps to Reproduce the Bug or Issue

1. Clone repo and run `pnpm install``
2. Run `pnpm codegen` / graphql-codegen
3. Allow lists and document are generated in folder named `generated`
4. Confirm that BookData comes before AuthorData in GetBook query in allow list

```yaml
- name: allowed-queries
definition:
queries:
- name: GetBook
query: |-
query GetBook {
book {
...BookData
}
}
fragment BookData on Book {
name
author {
...AuthorData
}
}
fragment AuthorData on Author {
name
}
```

5. Confirm that AuthorData appear before BookData in GetBookDocument generated by typed-document-node (`generated/graphql.ts`)

```
export const AuthorDataFragmentDoc = {...} as unknown as DocumentNode;
export const BookDataFragmentDoc = {...} as unknown as DocumentNode;
export const GetBookDocument = {...} as unknown as DocumentNode;
```

6. Run `pnpm test` and confirm that the query generated by `print` from the `graphql` package generates the following query:

```
query GetBook {
book {
...BookData
}
}

fragment AuthorData on Author {
name
}

fragment BookData on Book {
name
author {
...AuthorData
}
}
```

### Expected behavior

Compatible with other plugins.

### Screenshots or Videos

_No response_

### Platform

- OS: [macOS]
- NodeJS: [22.5.1]
- `graphql` version: [16.9.0]
- `@graphql-codegen/` version(s):
"@graphql-codegen/typed-document-node": "^5.0.9",
"@graphql-codegen/typescript": "^4.0.9",
"@graphql-codegen/typescript-graphql-request": "^6.2.0",
"@graphql-codegen/typescript-operations": "^4.2.3",

### Codegen Config File

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

const config: CodegenConfig = {
schema: [
{
"./schema.graphql": {
assumeValid: true,
},
},
],
documents: ["./queries/*.ts"],
generates: {
"./generated/query_collections.yaml": {
plugins: ["hasura-allow-list"],
config: {
globalFragments: true,
fragmentsOrder: "document",
},
},
"./generated/": {
preset: "client",
presetConfig: {
gqlTagName: "gql",
},
},
},
};
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.