graphql-code-generator: Types not being generated for gql files with imports

Note that this is using 1.4.1-alpha-906f6449.78

Describe the bug

It looks like files that import other fragments aren’t getting types generated.

Config:

overwrite: true
schema: path/to/schema
documents: src/**/*.gql
generates:
    codegen/graphql.d.ts:
        plugins:
            - 'typescript'
            - 'typescript-operations'
        config:
            namingConvention:
                enumValues: keep
                typeNames: change-case#pascalCase
            preResolveTypes: true
            typesPrefix: I
    codegen/graphql.schema.json:
        plugins:
            - 'fragment-matcher'

If I have two files

src/fragments/clickEventInfo.gql:

fragment clickEventInfo on ClickEvent {
  __typename
  .
  .
  .
}

and src/fragments/blah.gql:

#import 'src/fragments/clickEventInfo.gql'

fragment blah on Blah {
  clickEvent {
    ...clickEventInfo
  }
}

A type will only be generated for the IClickEventInfoFragment.

Expected behavior

Types to be generated for all documents

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

@dotansimha, tested our app against 1.4.1-alpha-680e7b39.95 and all React Apollo HOC & Component generations worked even when they contained the graphql-tag webpack loader #import syntax. Thanks for the quick fix!

@dotansimha, works great on this end too 👍thanks! 🙇

On a related note, we’ve been testing out the most recent alpha versions (1.4.1-alpha-ad8ddfd9.92 and a few before it) and we’ve noticed that Typescript React Apollo HOC & Component generation no longer works for any query that imports a fragment. An example query def that no longer works:

#import "./UsersPrefs.gql"

query UserPrefs {
  userPrefs {
    ...UserPrefs
  }
}

This was working fine for us in 1.4.0.

If it helps, I removed the import and HOC/Component generation worked (but of course the query no longer does).

Let me know if you want me to file a separate issue as this is a bit different than the parent as Typescript defs are still working for these, just not the React Apollo stuff.

@dotansimha we’re using graphql-tag. Tried with relative imports and still not generating. It works fine in v1.4.0, so I’ll bisect through the changes between the 1.4.1 prerelease and that version to try to identify the culprit