Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
voldern opened this issue Aug 15, 2024 · 0 comments
Open

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

voldern opened this issue Aug 15, 2024 · 0 comments

Comments

@voldern
Copy link

voldern commented Aug 15, 2024

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
- name: allowed-queries
  definition:
    queries:
      - name: GetBook
        query: |-
          query GetBook {
            book {
              ...BookData
            }
          }
          fragment BookData on Book {
            name
            author {
              ...AuthorData
            }
          }
          fragment AuthorData on Author {
            name
          }
  1. Confirm that AuthorData appear before BookData in GetBookDocument generated by typed-document-node (generated/graphql.ts)
export const AuthorDataFragmentDoc = {...} as unknown as DocumentNode<AuthorDataFragment, unknown>;
export const BookDataFragmentDoc = {...} as unknown as DocumentNode<BookDataFragment, unknown>;
export const GetBookDocument = {...} as unknown as DocumentNode<GetBookQuery, GetBookQueryVariables>;
  1. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant