Graphql-code-generator: AggregateError when query param name same with the directive param

Created on 27 Aug 2020  ยท  5Comments  ยท  Source: dotansimha/graphql-code-generator

Describe the bug

AggregateError when query param name same with the directive

To Reproduce
Steps to reproduce the behavior:
write client schema like and generate

query registrations($filter: RegistrationFilterInput, $page: PageInfo) {
  registrations(filter: $filter, page: $page) @connection(key: "registrations", filter: ["filter"]) {
    items {
      # ...
    }
    pageIndex
  }
}

  1. My GraphQL schema:
type RegistrationPage implements Pageable {
  items: [Registration!]
  pageSize: Int!
  pageIndex: Int!
  total: Int!
}

type Query {
  registrations(filter: RegistrationFilterInput, pageInfo: PageInfo): RegistrationPage
}

  1. My GraphQL operations:
registrations(filter: $filter, pageInfo: $pageInfo) @connection(key: "registrations", filter: ["filter"]){
        items {
            ...RegistrationFields
        }
        pageIndex
        pageSize
        total
    }
  1. My codegen.yml config file:
overwrite: true
schema: "server.graphql"
documents: ["src/**/*.ts", "src/**/*.graphql"]
generates:
  src/graphql.ts:
    plugins:
      - "typescript"
      - "typescript-operations"
      - "typescript-document-nodes"
    config:
      avoidOptionals: false
      exportFragmentSpreadSubTypes: true
      enumsAsTypes: false

Expected behavior

export the documents with the directive

Environment:

  • OS: MacOS 10.15.6
  • @graphql-codegen/...:
  • NodeJS: 12.13.1

Additional context

> graphql-codegen --config codegen.yml --clientSchema clientDirective.graphql

  โœ” Parse configuration
  โฏ Generate outputs
    โฏ Generate src/graphql.ts
      โœ” Load GraphQL schemas
      โœ” Load GraphQL documents
      โœ– Generate
        โ†’         at /Users/xiaoliu/workspace/frontend-main/src/components/registration/RegistrationHooks/registration.query.graphql:7:137


 Found 1 error

  โœ– src/graphql.ts
    AggregateError: 
        GraphQLDocumentError: Expected type RegistrationFilterInput, found ["filter"].
            at /Users/xiaoliu/workspace/frontend-main/src/components/registration/RegistrationHooks/registration.query.graphql:7:137
        at Object.checkValidationErrors (/Users/xiaoliu/workspace/frontend-main/node_modules/@graphql-toolkit/common/index.cjs.js:431:15)
        at Object.codegen (/Users/xiaoliu/workspace/frontend-main/node_modules/@graphql-codegen/core/index.cjs.js:89:16)
        at async process (/Users/xiaoliu/workspace/frontend-main/node_modules/@graphql-codegen/cli/bin.js:764:56)
        at async Promise.all (index 0)
        at async /Users/xiaoliu/workspace/frontend-main/node_modules/@graphql-codegen/cli/bin.js:771:37
        at async Task.task (/Users/xiaoliu/workspace/frontend-main/node_modules/@graphql-codegen/cli/bin.js:567:17)
    AggregateError: 
        GraphQLDocumentError: Expected type RegistrationFilterInput, found ["filter"].
            at /Users/xiaoliu/workspace/frontend-main/src/components/registration/RegistrationHooks/registration.query.graphql:7:137
        at Object.checkValidationErrors (/Users/xiaoliu/workspace/frontend-main/node_modules/@graphql-toolkit/common/index.cjs.js:431:15)
        at Object.codegen (/Users/xiaoliu/workspace/frontend-main/node_modules/@graphql-codegen/core/index.cjs.js:89:16)
        at async process (/Users/xiaoliu/workspace/frontend-main/node_modules/@graphql-codegen/cli/bin.js:764:56)
        at async Promise.all (index 0)
        at async /Users/xiaoliu/workspace/frontend-main/node_modules/@graphql-codegen/cli/bin.js:771:37
        at async Task.task (/Users/xiaoliu/workspace/frontend-main/node_modules/@graphql-codegen/cli/bin.js:567:17)


needs reproduction

Most helpful comment

To solve this problem just add the following line to your schema.graphql file:

directive @connection(key: String!, filter: [String!]) on FIELD

@dotansimha I didn't find where graphql-codegen adds the wrong @connection directive definition for making a PR.

BTW It will be nice if this directive will be added to the react-apollo plugin.

All 5 comments

Hi @xiaoliu-heng ,
Can you please share a live reproduction? We need to have a real, working environment with this issue, please make sure to use latest versions, since it seems like some deps are outdated in the callstack you shared.
I'm not sure it's something related to codegen, because the error seems like a graphql error, coming from graphql-js itself.

Hi, I'm experiencing a similar issue, @xiaoliu-heng do you have any updates on reproducing it?

To solve this problem just add the following line to your schema.graphql file:

directive @connection(key: String!, filter: [String!]) on FIELD

@dotansimha I didn't find where graphql-codegen adds the wrong @connection directive definition for making a PR.

BTW It will be nice if this directive will be added to the react-apollo plugin.

@dotansimha @osalama7 sorry I'm late. Codesandbox
to reproduce, just remove the directive.graphql

@nodkz It works. thanks!

To solve this problem just add the following line to your schema.graphql file:

directive @connection(key: String!, filter: [String!]) on FIELD

@dotansimha I didn't find where graphql-codegen adds the wrong @connection directive definition for making a PR.

BTW It will be nice if this directive will be added to the react-apollo plugin.

Actually, we are not adding that at all. Codegen doesn't do any schema/operations manipulations, so I can only assume this directive comes from somewhere within @xiaoliu-heng 's code.

As I said, this error is coming directly from graphql-js, and I'm not sure there is something we can do about it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dotansimha picture dotansimha  ยท  3Comments

quolpr picture quolpr  ยท  3Comments

edorivai picture edorivai  ยท  3Comments

SimenB picture SimenB  ยท  3Comments

zenVentzi picture zenVentzi  ยท  3Comments