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

Better notation for building servers #136

Closed
serras opened this issue Mar 12, 2020 · 4 comments · Fixed by #173
Closed

Better notation for building servers #136

serras opened this issue Mar 12, 2020 · 4 comments · Fixed by #173
Assignees
Labels
enhancement New feature or request rpc
Milestone

Comments

@serras
Copy link
Collaborator

serras commented Mar 12, 2020

Right now, building a server requires matching the exact order in which methods and services are defined in the correspoding type. When this type comes from importing a .proto, .avdl, or in the future GraphQL schema, keeping this order is quite difficult. Furthermore, @kutyel has noticed that the error message you get is quite un-informative.

So we need to find a better notation. Right now we are thinking of a blaze-builder-like notation using do, like:

service @"Book" $ do
  method @"id" ...
  method @"author" ...

@arianvp you might be interested in this

@serras serras self-assigned this Mar 12, 2020
@serras serras added the rpc label Mar 12, 2020
@serras serras added this to the 0.3 milestone Mar 12, 2020
@kutyel kutyel added the enhancement New feature or request label Mar 12, 2020
@arianvp
Copy link

arianvp commented Mar 12, 2020

How will you make sure that you get a type error when you 'miss' a certain rpc call?

Could perhaps fixed by using OverloadedSyntax and use IxMonad, but then you enforce implicit ordering again...

@serras
Copy link
Collaborator Author

serras commented Mar 12, 2020

Sure, the goal is to get a compile-time error if you miss something. I was also thinking along the lines of RebindableSyntax, but I'm not so happy with the idea, because that makes inference in the rest of the file terrible :(

@serras
Copy link
Collaborator Author

serras commented Mar 13, 2020

Here's my first attempt: https://github.com/higherkindness/mu-haskell/blob/better-server-api/core/rpc/src/Mu/Rpc/Examples.hs#L75

@kutyel @arianvp what do you think?

Unfortunately, I could not get a good error message for the case in which you are missing a method. The reason is that for the inference to work I need to have a functional dependency on ToHandlers. But that dependency precludes me from having this instance.

@serras
Copy link
Collaborator Author

serras commented Apr 6, 2020

@arianvp after some discussion with @kutyel, we came with a better API using tuples instead of weird heterogeneous lists. So you can now declare servers in this way:

singleService ( method @"SayHello" sayHello
              , method @"SayManyHellos" sayManyHellos
              , method @"SayHi" sayHi )

and GraphQL resolvers as follows:

resolver
  ( object @"Author" ( field @"name"   authorName
                     , field @"books"  authorBooks )
  , object @"Book"   ( field @"author" (pure . snd)
                     , field @"title"  (pure . fst) ) )

What do you think? I find it quite nice :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request rpc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants