eddeee888 / graphql-code-generator-plugins

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

Spreads resolvers of object types other than root object type. #172

Closed YutaUra closed 10 months ago

YutaUra commented 1 year ago

see: https://github.com/eddeee888/graphql-code-generator-plugins/pull/168

:memo:

Fix to spread and place Main Type resolvers to apply individual resolvers other than RootObjectType in the future.


It's hard to touch the AST 😓 :)

I feel that the processing, especially around isScalar, is not beautiful. If you have any good ideas, I would be glad to hear them.

changeset-bot[bot] commented 1 year ago

🦋 Changeset detected

Latest commit: c1d9e7387cb08632e6a3f7dc49d8f0ef8dadd8a9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ---------------------------------------- | ----- | | @eddeee888/gcg-typescript-resolver-files | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

eddeee888 commented 1 year ago

Thanks @YutaUra ! It's looking pretty good already!

I feel that the processing, especially around isScalar, is not beautiful. If you have any good ideas, I would be glad to hear them.

This could be an issue with the current setup. Let me take a closer look. I'll get back to you soon.

(Also, sorry for the conflicts 🙇‍♂️ However, most of them are in e2e so they can be merged and regenned )

eddeee888 commented 1 year ago

I feel that the processing, especially around isScalar, is not beautiful. If you have any good ideas, I would be glad to hear them.

Currently, when we prepare "virtual" files, we are marking each type with __filetype which could one one of the following values:

If we want to treat GraphQL Scalars in a different way (like this situation), we would have to do the following:

  1. Separate a new type for Scalar here. It may look like this:

    export interface ScalarTypeFile extends BaseVirtualFile {
    __filetype: 'scalarType';
    meta: {
    moduleName: string;
    variableStatement: string;
    normalizedResolverName: string;
    };
    }
  2. Add scalarTypes to this FileDetails

  3. Create an if block here that checks file.__filetype === 'sclarType' and add import line and push scalar to the type

  4. Handle scalar around here, like what you are already doing 🙂

eddeee888 commented 10 months ago

This is available in v0.7.0: https://github.com/eddeee888/graphql-code-generator-plugins/releases/tag/%40eddeee888%2Fgcg-typescript-resolver-files%400.7.0