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

[typescript-apollo-client-helpers] generated FieldPolicy type definitions

Open martdavidson opened this issue 3 years ago • 2 comments

I added typescript-apollo-client-helpers to generate a typesafe StrictTypedTypePolicies. Looking at the generated FieldPolicy declarations for each entity type, I see they're all FieldPolicy, so when doing something like:

typePolicies: {
  User: {
    fields: {
      displayName(existing) {
        return existing;
      },
    },
  },
}

The existing prop is of course any because of the generated FieldPolicy:

export type UserFieldPolicy = {
	displayName?: FieldPolicy<any> | FieldReadFunction<any>,
};

I'm wondering if it's possible to - when used in tandem with the Typescript plugin - have these anys replaced with the fields actual type definitions, which in my case looks like:

export type User = {
  displayName: Maybe<Scalars['String']>;
};

Thanks!

martdavidson avatar May 19 '22 14:05 martdavidson

Oh I see this discussion from last year: https://github.com/dotansimha/graphql-code-generator/discussions/6047

I'll take a look at maybe doing up a PR if I feel like I understand.

Feel free to close, or leave open as a feature request.

martdavidson avatar May 19 '22 19:05 martdavidson

Yes, please!

maaft avatar Aug 31 '22 16:08 maaft