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

Implement a strictly typed service client for comms between services #7358

Closed
wants to merge 11 commits into from

Conversation

rikukissa
Copy link
Member

@rikukissa rikukissa commented Jul 7, 2024

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
image

Compiler errors if you are submitting an invalid or missing body
image

Typed path parameters
image

Typed return values
image

Changed the factory call signature a bit
Service URL now has to be passed from outside
image

What's missing

  • Typed query parameters
  • Quite a lot of Joi definitions from many of our endpoints 😄

@rikukissa rikukissa marked this pull request as ready for review July 7, 2024 21:56
Comment on lines +75 to +87
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 }
: {})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment what this does

@rikukissa
Copy link
Member Author

rikukissa commented Aug 21, 2024

@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

@Zangetsu101
Copy link
Collaborator

@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 😄

@naftis
Copy link
Collaborator

naftis commented Sep 2, 2024

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.

@rikukissa
Copy link
Member Author

I'm closing this for now. I think tRPC is a better option

@rikukissa rikukissa closed this Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants