eddeee888 / graphql-code-generator-plugins

List of GraphQL Code Generator plugins that complements the official plugins.
MIT License
44 stars 10 forks source link

[BUG] Not all `*.mappers.ts` files are detected #217

Closed lensbart closed 6 months ago

lensbart commented 7 months ago

Hello,

First of all, thanks for developing the server preset. It allowed me to remove large chunks of boilerplate code.

Not entirely sure how to narrow down this bug, but I have the following setup:

// codegen config file
'apps/api/src/schema/': {
  ...defineConfig({
    emitLegacyCommonJSImports: false,
    resolverMainFile: './__generated__/resolvers.ts',
    resolverTypesPath: './__generated__/types.ts',
    tsConfigFilePath: './apps/api/tsconfig.json',
    typeDefsFilePath: './__generated__/typeDefs.ts',
    typesPluginsConfig: {
      contextType: 'src/index.js#Context',
    },
  }),
},

and a couple of modules: annotation, base, block and inline. If I have the following mapper files (all paths below are inside src/schema):

then only annotation.mappers.ts and block.mappers.ts get detected and imported into the generated types.ts file.

If I rename these files to:

then all except for inline.mappers.ts are imported into types.ts

If I rename these files to:

then only the second file gets imported into the generated types.ts file.

The only thing I changed to achieve these different results is the filename. Each of these files contain a single statement, in the form of

// see https://the-guild.dev/graphql/codegen/docs/guides/graphql-server-apollo-yoga-with-server-preset#adding-mappers
export type {
  Something as SomethingMapper,
  SomethingElse as SomethingElseMapper
} from 'src/__generated__/prisma/index.js'

None of these exports have overlapping names.

Hope this helps!

eddeee888 commented 7 months ago

Hello @lensbart !

Thanks for using the preset, and apologies for the delayed response.

I've tried to re-create your setup using this example Codesandbox:

The generated type file is correctly importing the mapper interfaces:

Screenshot 2023-12-06 at 9 14 03 pm

The only thing I haven't tried is setting up your config in a monorepo (which seems to be your real setup). However, I have an app that uses codegen in an Nx monorepo and it is working fine too.

Do you have an example where I could check out to debug? 🙂

lensbart commented 6 months ago

Sorry for the late response — I can’t easily provide an example, because the project I’m working on is closed source. Feel free to close this issue, I have resolved it on my end by putting all mappers in a single schema.mappers.ts file.

eddeee888 commented 6 months ago

Thanks @lensbart !