A way to exculde Maybe<> type from a generated TS schema
Is your feature request related to a problem? Please describe.
For frontend we set maybeValue: T | undefined in config and in this case it's not clear why we need Maybe type at all, because TypeScript guides usually suggest to prefer optional types over T | undefined.
For example user?: User will work as good as user?: Maybe<User> and of course better than if we specify avoidOptionals: true.
With avoidOptionals and typescript's strictNullChecks turned on it'll throw an error if I don't specify user for user: Maybe<User> (which is right from TS perspective, but not right from actual usage cases – if some value is optional, I prefer to not specify it at all then to write { someValue: undefined }).
Describe the solution you'd like
Add to config a way to exclude Maybe type at all from all the optional value types.
Describe alternatives you've considered
No response
Is your feature request related to a problem? Please describe.
No response
I second that. If I have prop: SomeType in my GQL schema, all I need is prop?: SomeType in TS. the inclusion of Maybe here actually annoys me as now I have to have this in my function interfaces: const myfunc = (prop?: SomeType | null): RetType => {}. How annoying is that?! Please give us option to exclude these horrible Maybes from generated TS types!
I second that. If I have
prop: SomeTypein my GQL schema, all I need isprop?: SomeTypein TS. the inclusion ofMaybehere actually annoys me as now I have to have this in my function interfaces:const myfunc = (prop?: SomeType | null): RetType => {}. How annoying is that?! Please give us option to exclude these horribleMaybesfrom generated TS types!
to get rid of the | null in your function signatures you can use as config maybeValue: 'T' . it will still generate Maybe<T> but it will omit the null. eg :
const config: CodegenConfig = {
overwrite: true,
schema: './graphql/schema.graphql',
documents: ['src/**/*.gql'],
generates: {
'src/api/types.generated.ts': {
plugins: ['typescript'],
config: {
maybeValue: 'T',
}
}
}
Hi @ovy9086 , I also have the same problem. Thanks for your suggestion. However, seems like the maybeValue: 'T' doesn't work with preset: 'client'?
Hi @ovy9086 , I also have the same problem. Thanks for your suggestion. However, seems like the
maybeValue: 'T'doesn't work withpreset: 'client'?
Also having this problem
no updates?
Up vote for giving an option to exclude unnecessary type wrappers.
Hi all, the original issue is asking for maybeValuein typescript plugin, which is already supported.
If you need this for client-preset, please open another issue to help us track 🙏