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:not compatible with other plugins #441

Closed
shoma-mano opened this issue Oct 5, 2023 · 1 comment
Closed

hasura-allow-list:not compatible with other plugins #441

shoma-mano opened this issue Oct 5, 2023 · 1 comment

Comments

@shoma-mano
Copy link
Contributor

shoma-mano commented Oct 5, 2023

Which packages are impacted by your issue?

@graphql-codegen/hasura-allow-list

Describe the bug

Thanks for creating amazing plugin!This plugin is so useful!

With global fragments turned on, I am using this plugin with query containing multiple fragments. However, sometimes query is not allowed because fragments definition order is not the same with documents other codegen plugins generate.(I confirmed typescript-graphql-request and typed-document-node does not generate code that works with allow lists this plugin generate)

This happened by difference of how to treat global fragments, so I think this can be solved by changing

return fragmentDefinitions.filter(definition => requiredFragmentNames.has(definition.name.value));

to

return Array.from(requiredFragmentNames).map(name => fragmentDefinitions.find(definition => definition.name.value === name));

Order of requiredFragmentNames should be kept.

Your Example Website or App

https://github.com/shoma-mano/hasura-allowlist-reproduction

Steps to Reproduce the Bug or Issue

  1. clone repo
  2. pnpm install
  3. graphql-codegen
  4. allow lists and document are generated in folder name generated.
  5. confirm GetBook query in allow list.(AuthorData appears before BookData)
- name: allowed-queries
  definition:
    queries:
      - name: GetBook
        query: |-
          query GetBook {
            book {
              ...BookData
              author {
                ...AuthorData
              }
            }
          }
          fragment AuthorData on Author {
            name
            books {
              ...BookData
            }
          }
          fragment BookData on Book {
            name
          }

6.confirm GetBookDocument generated by typed-document-node(AuthorData does not appear before BookData)

// omitted
{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BookData"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Book"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}}]}},{"kind":"**FragmentDefinition**","name":{"kind":"Name","value":"AuthorData"}
// omitted

7.confirm GetBookDocument generated by typescript-graphql-request(AuthorData does not appear before BookData)
export const GetBookDocument = gql query GetBook { book { ...BookData author { ...AuthorData } } } ${BookDataFragmentDoc} ${AuthorDataFragmentDoc};

Expected behavior

compatible with other plugins.

Screenshots or Videos

No response

Platform

  • OS: [macOS]
  • NodeJS: [19.9.0]
  • hasura version: [2.34.0]
  • @graphql-codegen/cli version: [5.0.0]
  • @graphql-codegen/hasura-allow-list version: [3.0.0]

Codegen Config File

No response

Additional context

No response

@shoma-mano shoma-mano changed the title hasura-allow-list:requiredFragmentNames order should be kept hasura-allow-list:not compatible with other plugins Oct 5, 2023
@saihaj
Copy link
Collaborator

saihaj commented Oct 25, 2023

@graphql-codegen/hasura-allow-list@3.1.0

@saihaj saihaj closed this as completed Oct 25, 2023
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

2 participants