Graphql-code-generator: Suggestion for typescript-resolvers: Use generated resolver type in regular mappers

Created on 2 Apr 2019  路  2Comments  路  Source: dotansimha/graphql-code-generator

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

Use generated resolver type in regular mappers.

Describe the solution you'd like

This suggestion builds on the features introduced in #1593.

The changes means that there are now special resolver return/parent types generated for all schema types, and these types are returned by default by resolvers. Also these resolver types are defined in each other by default, so one resolver type has fields of the other resolver types rather than the raw schema types.

However if we introduce a mapper it will break the chain of resolver types referencing each other as noted in this comment and this comment.

To solve the above, perhaps we can introduce a parameter to the regular mappers the same way that the default mapper now have a parameter {T}. In the case or regular mappers the parameter would be the default generated type.

Let's say by default we have this:

type MyType {
    foo: String!
    otherType: MyOtherType
  }
type MyOtherType {
    bar: String!
}
type Query {
    something: MyType!
}
type ResolversTypes = {
    Query: Omit<Query, 'something'> & { something: ResolversTypes['MyType'] },
    MyType: Omit<MyType, 'otherType'> & { otherType: Maybe<ResolversTypes['MyOtherType']> },
    String: Scalars['String'],
    MyOtherType: MyOtherType,
}

Now we want to make MyType partial without breaking the chain of referencing resolver types. If mappers had a parameter which gave the default generated resolver type we could have this config:

plugins
  config:
    mappers:
      MyType: Partial<{T}>

In this example the {T} would be Omit<MyType, 'otherType'> & { otherType: Maybe<ResolversTypes['MyOtherType']> } since that is the generated resolver-type. The output from this would be:

type ResolversTypes = {
    Query: Omit<Query, 'something'> & { something: ResolversTypes['MyType'] },
    MyType: Partial<Omit<MyType, 'otherType'> & { otherType: Maybe<ResolversTypes['MyOtherType']> }>,
    String: Scalars['String'],
    MyOtherType: MyOtherType,
}
enhancement plugins waiting-for-release

Most helpful comment

Available in 1.1.0 馃殌

All 2 comments

1677

Available in 1.1.0 馃殌

Was this page helpful?
0 / 5 - 0 ratings