-
-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Duplication in generated types #60
Comments
@piglovesyou Yes, exactly. I've been using This results in separate files for the general types and the specific operation types. I'm not sure if it has any performance effects, but it's cleaner and makes sure that I import the types from the right file 🙂 |
Thank you. Ah, what a beautiful behavior the @graphql-codegen/near-operation-file-preset does. I didn't track the code but I'm guessing the near-operation-file-preset:
The reasons it'll take long to work on this issue are:
I'll take more time to see near-operation-file-preset when I have time |
Yeah no worries, I see this isn't a high priority thing - just wanted to let you know 😁 The main thing is using the Maybe check https://github.com/dotansimha/graphql-code-generator/blob/master/packages/presets/near-operation-file/src/resolve-document-imports.ts#L1 for how this works (possibly you could import the same helper functions to achieve similar results?) |
Another thing if you have one file with all definitions you can use 'find usages'. Now each file has it is own definitions and you can't find everywhere in the project where i.e. |
This should help, no? https://github.com/dotansimha/graphql-code-generator/blob/master/packages/plugins/typescript/graphql-files-modules/src/index.ts#L6-L25 @piglovesyou It allow you to set the prefix to be used, and have a more strict matching of the path. If you'll set this to the relative path of the file and the cwd, it should work and have no conflicts. |
I am using hasura as the graphql server and the introspection result (schema) is about 20K LOC for each *.graphql file. So it would be beneficial for me, if there where a generated schema file, which could be imported by the different operation files. I am just trying out this library, so maybe there is a solution to my problem already? |
@dotansimha Thank you for everything!! I caught up here finally. We need both presets graphql-modules and import-types, do I get it right? Still studying, but I think we can fix this issue by doing something like this internally. schema: '**/*.graphqls'
documents: '**/*.graphql'
generates:
./server:
preset: graphql-modules
presetConfig:
baseTypesPath: schema.ts # We always generate this
plugins:
- typescript
- typescript-resolvers
out.tsx: # This will be managed by graphql-let. All generated .tsx will import the above schema.ts.
plugins:
- typescript-operations
- typescript-react-apollo
preset: import-types
presetConfig:
typesPath: ./server/schema
importTypesNamespace: SchemaTypes |
Hey folks! So, we've been looking at improving our codegen set up, and are evaluating graphql-let. It looks great (thanks for this truly awesome piece of work <3 ), but this is potentially blocking us from gradual migration. Is there anything we can do to help with this? I couldn't find any WIP, has anything been started yet? |
Hi @StevenLangbroek, thanks for trying graphql-let. I had an idea and stopped, but I'm starting it again partially because of your sponsoring me😄 I can't promise, but maybe it'll publish with a couple of weeks. Folking is also welcomed. My idea is as simple as to make the presets mentioned above be built-in. If you already know how to achieve it by GraphQL code generator's |
I'll leave my thought. I think graphql-let can halt to support preset and manage what they do by itself. Their preset is not a usual preset like Babel Presets but some additional generation logic affecting the plugin implementations. For example, the |
@piglovesyou oh appreciate that, but that's not why I'm sponsoring :). @acao do you think we can help with this? |
It seems what @piglovesyou is saying is that in order for |
I know, @StevenLangbroek👍 @acao Thanks for investigating this and sharing your idea. Shortly, I think graphql-let can solve the problem by calling @graphql-codegen/import-types-preset internally, cofigured as (in codegen.yml format): schema: '**/*.graphqls'
documents: '**/*.graphql'
generates:
__generates__/__SHARED_SCHEMA__.ts:
plugins:
- typescript
__generates__/a.graphql.tsx:
plugins:
- typescript-operations
- typescript-react-apollo:
importOperationTypesFrom: ''
preset: import-types
presetConfig:
typesPath: ./server/schema My previous thought the above is just a little concern/memo about config compatibility as you said; graphql-let is going to control presets. I'm working on it on split-schema-and-document branch. Some passes, the rest still fails. I'll continue to work anyway but appreciate any of your comments. Rest of tasks:
|
@acao let's give this a go 🥳 |
This worked except for one bug where GraphQLErrors were being shown with trying to parse a commonjs file. I will come back to this later this week hopefully! Either way, we feel confident this will be a good alternative to near operation file for our teams! |
Thanks for taking the time for this, sounds great. Did you get that error by |
Ah my bad should’ve clarified, it was only 0.18.0-beta.1! I’ll give the latest beta release a try soon and report back! Thanks for such an awesome project! |
I published v0.18.0, fixing this issue. Thank you, guys. I'd love to hear what you think about the behavior. I wrote a migration guide for it. Please check it. |
Thank you! Will take a look soon! |
When using multiple operations it seems like all operation types are generated for each of them (the only difference between the generated files is the
declare module '*/DocumentName.graphql'
part). I think each file should only contain the matching types.The text was updated successfully, but these errors were encountered: