opencrvs / opencrvs-core

A global solution to civil registration
https://www.opencrvs.org
Other
85 stars 67 forks source link

Create a "GraphQL to REST" utility function for exposing functionality as REST #4590

Open rikukissa opened 1 year ago

rikukissa commented 1 year ago

Currently, exposing functionality from the gateway as REST requires a completely new endpoint to be created with duplicated logic from our GraphQL API. Exposing functionality for health integrations is thus slow and hugely increases our total cost of ownership.

Let's refactor our approach so that we'd have a utility for converting existing GraphQL functionality to REST. My suggestion is that the end result looks something like this:

    {
      method: 'GET',
      path: '/location',
      handler: graphQLToREST('fetchLocations')

So for instance to expose the "fetchLocations" query from GraphQL you'd

  1. Create a new HAPI endpoint
  2. Define the REST path
  3. Use graphQLToREST (created by us) utility to define to which GraphQL query the rest endpoint should point to

The end result should be the same as making a graphql request and defining it to return all fields

Discussion: https://opencrvsworkspace.slack.com/archives/C02LU432JGK/p1674021482747219

rikukissa commented 11 months ago

There is a query-generator in our code base that could be used here to always query everything in from the GraphQL endpoint in question