Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion for typescript-resolvers: Use generated resolver type in regular mappers #1631

Closed
jonaskello opened this issue Apr 2, 2019 · 2 comments
Assignees
Labels
plugins waiting-for-release Fixed/resolved, and waiting for the next stable release

Comments

@jonaskello
Copy link
Contributor

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,
}
@kamilkisiela
Copy link
Collaborator

#1677

@dotansimha dotansimha added the waiting-for-release Fixed/resolved, and waiting for the next stable release label Apr 9, 2019
@dotansimha
Copy link
Owner

Available in 1.1.0 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugins waiting-for-release Fixed/resolved, and waiting for the next stable release
Projects
None yet
Development

No branches or pull requests

3 participants