graphql-code-generator-community icon indicating copy to clipboard operation
graphql-code-generator-community copied to clipboard

Typed-Document-Node with Apollo-Angular

Open erikwrede opened this issue 9 months ago • 1 comments

We are currently using typescript-apollo-angular to generate our type hints. We now want to make use of typed-document-node in conjunction with ts-apollo-angular to benefit from the additional ergonomics of typed-document-node during cache interactions.

We have tried the following configuration, but the typed document node lacks all of the generic type annotations:

  documents: [
    "apps/**/src/app/**/*.graphql",
    "libs/**/*.graphql"
  ],
  generates: {
    ["./"]: {
      preset: "near-operation-file",
      presetConfig: {
        baseTypesPath: "our-base-types-module",
        importTypesNamespace: "GraphQlTypes"
      },
      config: {
        documentNodeImport: "@graphql-typed-document-node/core#TypedDocumentNode",
        documentMode: "documentNode"
      },
      plugins: [
        "typescript-operations",
        "typescript-apollo-angular"
      ]
    }
  },

Describe the solution you'd like

Have either an additional option for the apollo angular plugin to use the typed document node directly, or make it compatible in a better way

Describe alternatives you've considered

The alternative is duplicating the type definitions. (One for apollo-angular, one for typed-document-node). This is not an option as it unnecessarily increases bundle size and creates type redundancies, decreasing code ergonomics.

Typed-Document-Node just by itself as a replacement for the apollo-angular plugin is also not an alternative due to the handy inject syntax that goes well with apollo-angular.

Is your feature request related to a problem? Please describe.

See above, it currently does not work.

This issue continues the discussion from https://github.com/dotansimha/graphql-code-generator/issues/9500#issuecomment-2645772300

erikwrede avatar Feb 08 '25 19:02 erikwrede

Looking at this discussion this won't get implemented. The reason I wanted to try this was so I could do MockProvider(GroepsoverzichtRegistratiesGQL, queryData(...), 'useValue') in the unit tests, but that's probably not worth the extra bundle size. Maybe I'm better of just creating a fake apollo client and using that.

JesseZomer avatar Feb 11 '25 08:02 JesseZomer