captbaritone / grats

Implementation-First GraphQL for TypeScript
https://grats.capt.dev
MIT License
308 stars 16 forks source link

Arrow functions #148

Closed kansson closed 2 months ago

kansson commented 2 months ago

Hi, great project! Is it possible to use arrow functions for field definitions like this?

export const hello = (_: Query): string => 'Hello World!';
captbaritone commented 2 months ago

Yeah, should be possible. Happy to work on adding that. Quick question though, what's your motivation for preferring arrow functions? Just style?

kansson commented 2 months ago

Yeah, should be possible. Happy to work on adding that. Quick question though, what's your motivation for preferring arrow functions? Just style?

Thanks, looking forward to it. Mainly for coding style and avoiding explicit returns in simple database queries.

captbaritone commented 2 months ago

Got it. That should be possible. I'll use this issue to track.

One common reason to want arrow functions is to apply wrappers, and that won't work (which is why I was asking).

captbaritone commented 2 months ago

Should work now: https://grats.capt.dev/playground/#N4IgJg9gxiBcIHoBUSAEABA5gRwDYBUBPABwFNUkEAdAOwBcTyBFAV1ICdDUBeVFmgNY0IAdxoBuWrWRoseAGIBLUrjAVqNUgA9iEdnVRQINAM4GAFitwQeqABQB9WKlYdCASmdn2imph4AfKgA5AASVjYA6nqqAITB4iAANCBGNABmiphwoDQsuLgAhgBGuKQAQoQAIqTphfl0cHTsbCnspLr6RGQAylA+xHTdpACi7Ox6Jk0tpAC+KQBuyiI5IBAsdMQbAPKDisZwICZguMlH5qIA4uyFdCZViu1QdIoLpFOwdbgmcykAaiMAEo9ACS2wAcnAAIyzIA

You can install grats@main to try it out before the next release.

kansson commented 2 months ago

Awesome thanks! 🚀