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

[typescript-resolvers] avoid input optional as typescript-operations #3815

Open
Tracked by #8296 ...
LucienLee opened this issue Apr 6, 2020 · 7 comments
Open
Tracked by #8296 ...
Labels
core Related to codegen core/cli kind/enhancement New feature or request plugins

Comments

@LucienLee
Copy link

Now, we have dedicated controls of optional types in typescript-operations, including field, inputValue and Object. However, we only can choose on or off in typescript-resolvers.

I suggest that typescript-resolvers can take avoidOptionals as typescript-operations.

@dotansimha
Copy link
Owner

I think it will have to use a different controls, right? What did you have in mind? @LucienLee

@LucienLee
Copy link
Author

I think that it could be the same because we can pass options in the output level (usually, resolvers and operations will be generated in the different files) and plugin level. It' doesn't matter we used the same config signatures.

However, maybe we can have a new one setting, scalar. Now we can control these GQL schema types optional or not: FieldDefinition, InputValueDefinition and ObjectTypeDefinition, but missed ScalarsDefinition.

BTW, I think the documentation of avoidOptionals is not quite completed now. People cannot know what is the setting meaning.

@LucienLee
Copy link
Author

@dotansimha any thoughts?

@dotansimha
Copy link
Owner

@LucienLee I think you are right. PRs are welcome ;)

@stephenh
Copy link

stephenh commented Jun 1, 2020

Fwiw if you're messing with avoidOptionals in typescript-resolvers, you should have a mode that differentiates by mapped types:

  • Resolvers.authors for a mapped Author output type should be required, and every field resolver in AuthorResolvers should be required
  • Resolvers.saveAuthorResult for a non-mapped / DTO `SaveAuthorResult should be optional
  • The non-mapped/DTO-object SaveAuthorResult should have all of its keys non-optional

I.e. if I'm not mapping a type, I don't need a resolver for it, b/c I'll just instantiate it fully each time I want to return it. And when I instantiate it, I should have to specify all of the fields.

If I am mapping a type, then I need a resolver for it, and every field in that resolver should be required (imo/at least as a potential config option).

We ended up implementing our own version of typescript-resolvers to get this more nuanced output.

@dotansimha
Copy link
Owner

@stephenh maybe this is something you can share with us? This use case sounds interesting, maybe it could help others as well :)

@stephenh
Copy link

stephenh commented Jun 1, 2020

@dotansimha sure :-) here's our plugin's repo: https://github.com/homebound-team/graphql-typescript-simple-resolvers (also edited my original suggestion for clarity)

@dotansimha dotansimha added kind/enhancement New feature or request and removed enhancement labels Jun 20, 2021
@charlypoly charlypoly added the core Related to codegen core/cli label Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to codegen core/cli kind/enhancement New feature or request plugins
Projects
None yet
Development

No branches or pull requests

4 participants