eddeee888 / graphql-code-generator-plugins

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

[FEAT] Config option to allow for nested modules #243

Closed jb-1980 closed 5 months ago

jb-1980 commented 6 months ago

Is your feature request related to a problem? Please describe. I have to keep a very flat file structure to use this. I would like to be able to organize modules together in subdomains to facilitate domain driven design, i.e.:

src/schema
├── school
│   └── demographics
│   │   ├── resolvers
│   │   ├── schema.graphql
├── students
│   ├── profile
│   ├── avatar
│   │   ├── resolvers
│   │   ├── schema.graphql
│   └── guardians
├── teachers
│   ├── profile
│   ├── avatar
│   │   ├── resolvers
│   │   └── schema.graphql

If I have a codegen.ts like

// codegen.ts
import type { CodegenConfig } from '@graphql-codegen/cli';
import { defineConfig } from '@eddeee888/gcg-typescript-resolver-files';

const config: CodegenConfig = {
  schema: '**/schema.graphql',
  generates: {
    'src/schema': defineConfig(),
  },
};

export default config;

Then it will generate a file structure like

src/schema
├── demographics
│   └── resolvers
├── profile
│   └── resolvers
├── avatar
│   └── resolvers
...

The issue with that is that the resolvers are ambiguous. They may go with the students or with the teachers. Like, It seems like it is some race condition as to which resolvers are going to get into avatar/resolvers. Moreover, the code is no longer collocated within its subdomain.

Describe the solution you'd like I would like an option similar to that offered by the near-operation-file-preset plugin. Namely, that setting the option to true would place all resolver files inside the directory where schema.graphql is located instead of <baseOutputDir>/<moduleName>/<resolverRelativeTargetDir>.

Output should be <baseOutputDir>/**/<moduleInSubdomain>/<resolverRelativeTargetDir>

Describe alternatives you've considered

eddeee888 commented 5 months ago

This is now available in v0.7.4. Thank you!