-
Notifications
You must be signed in to change notification settings - Fork 69
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
Implement a strictly typed service client for comms between services #7358
Conversation
type RequestOptions< | ||
RequestMethod extends keyof Service, | ||
Path extends keyof Service[RequestMethod] | ||
> = (Service[RequestMethod][Path] extends { request: infer R } | ||
? IsNever<R> extends true | ||
? {} | ||
: { body: R } | ||
: {}) & | ||
(Service[RequestMethod][Path] extends { params: infer P } | ||
? IsNever<P> extends true | ||
? {} | ||
: { params: P } | ||
: {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment what this does
@naftis @Zangetsu101 I've also started thinking if writing our internal APIs in https://trpc.io/ would actually be better in the grand scheme of things. Thoughts? It would take us a step further from "easily approachable tech" but would yield other benefits for our team |
tRPC is ideal for communicating between frontend and backend so kinda at the place where our GraphQL layer sits. Of course it has this requirement that both of them must be using typescript (which we already do). But not sure if anyone's using it for backend services tho. TBH this PR did look to me like a tRPC implementation but for backend microservices 😄 |
Idea: the country-config routes could be typed like this as well. Then we could go as far as create a Swagger / OpenAPI docs of what routes the country-config should implement. |
I'm closing this for now. I think tRPC is a better option |
This is not used anywhere yet, but the more we start using it the better. This will effectively provide a much nicer dev experience, less room for human errors and better type safety for refactoring.
Features
Autocomplete for request paths
Compiler errors if you are submitting an invalid or missing body
Typed path parameters
Typed return values
Changed the factory call signature a bit
Service URL now has to be passed from outside
What's missing