eddeee888 / graphql-code-generator-plugins

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

[BUG] Federation support. #90

Closed patrickdronk closed 10 months ago

patrickdronk commented 1 year ago

I'm unsure if this is a bug, or just not in the preset. But currently, I'm trying to use the preset in combination with federation. But I'm not seeing any types being generated.

To Reproduce Use the following config:

import type { CodegenConfig } from '@graphql-codegen/cli'
import { preset } from '@eddeee888/gcg-typescript-resolver-files'

const config: CodegenConfig = {
  schema: '**/schema.graphql',
  generates: {
    'src/schema': {
      preset,
      config: { federation: true },
    }
  }
}
export default config

generate types

Expected behavior I expect a referenceResolver type to be generated.

eddeee888 commented 1 year ago

Hello 👋

You can pass typescript-resolvers config through presetConfig.typesPluginsConfig option. I'll update the README to make it clearer

In your case, this should work:

import type { CodegenConfig } from "@graphql-codegen/cli";
import { preset } from "@eddeee888/gcg-typescript-resolver-files";

const config: CodegenConfig = {
  schema: "**/schema.graphql",
  generates: {
    "src/schema": {
      preset,
      presetConfig: {
        // Config you'd normally pass into `typescript` and `typescript-resolvers`'s config 
        // can be passed through typesPluginsConfig
        typesPluginsConfig: {
          federation: true,
        },
      },
    },
  },
};
export default config;

Doing this adds a _FieldSet in Scalars:

Screen Shot 2023-02-28 at 8 26 33 pm

I haven't tried federation so please let me know what else's missing. Thanks! 🙏