Graphql-code-generator: External document mode in near-operations-file no longer works in 1.12.2

Created on 9 Feb 2020  路  14Comments  路  Source: dotansimha/graphql-code-generator

With the changes made in #3436, the following configuration no longer works as expected in 1.12.2:

documentMode: external
importDocumentNodeExternallyFrom: near-operation-file

All generated fragment files are expected to have a <FragmentName>Doc export, which they don't have with this config.

It works as expected in 1.12.1

bug presets waiting-for-release

Most helpful comment

@dotansimha That did the trick 馃憤

All 14 comments

@mvestergaard can you please try the latest alpha (1.12.3-alpha-c0f7e16f.24)? we introduced some fixed related to presets and imports.

@dotansimha Still happens in 1.12.3-alpha-c0f7e16f.24

I answered your question btw. Just so the tag doesn't make you forgot about this issue.

Oh, seems to be fixed with the latest canary version 1.12.3-alpha-ff4bca66.86+ff4bca66
Nevermind, still not fixed

@mvestergaard any luck with 1.12.3-alpha-b89e11fd.107? If not, can you please share a reproduction in a repo/sandbox?

Just tried 1.13.0, and it's still not working there.

I haven't really had time to create a reproduction, but it should be fairly easy to replicate,
Use preset: near-operation-file and documentMode: external, then create a file containing a fragment, and another containing a query, that references the fragment.
The query file will try to import <FragmentName>Doc from the generated fragment file, which doesn't exist.

I see, thanks @mvestergaard !
This might have been fixed in https://github.com/dotansimha/graphql-code-generator/pull/3628 by @wassim-k , but I'll try to reproduce it anyway.

Btw, I think documentMode: documentNodeImportFragments might solve those issues for you?

I quickly gave documentMode: documentNodeImportFragments a shot, and that just leads to other problems.

It puts the query document into the generated file containing code that doesn't work, for example here:

export const UserSelectorSearchUsersDocument = gql`
    query UserSelectorSearchUsers($query: String!) {
  users(name: $query) {
    items {
      id
      ...UserSelectorUser
    }
  }
}
    ${UserSelectorUserFragmentDoc}`;

No import of gql is put into the file, so that causes an error.
And the UserSelectorUserFragmentDoc is not imported into the file either, so that also causes an error

I haven't encountered the gql tag not being imported issue but my fix should handle the fragment imports correctly.

I tried upgrading to the latest canary build and using documentNodeImportFragments, which works.

I honestly like the original approach with documentMode: external better though.

The reason I like "external" better is that it actually references the original file, which these other approaches don't.

It's not a huge issue, but allows for tooling that detects unused files for example.

@mvestergaard I added some fixes and tests for the combination of near-operation-file and documentMode. Not sure if it covers your use case, as I was trying to fix https://github.com/dotansimha/graphql-code-generator/issues/3525 which seems a bit related.

Alpha is available: 1.13.1-alpha-a7a3c762.19, can you give it a try?

@dotansimha That did the trick 馃憤

Fixed in v1.13.1 馃帀

Was this page helpful?
0 / 5 - 0 ratings