daniel-ac-martin / NotGovUK

An implementation of the GOV.UK Design System in React that provides support for writing internal applications in addition to public ones.
https://not-gov.uk/
MIT License
27 stars 8 forks source link

API subscription support #125

Open daniel-ac-martin opened 4 years ago

daniel-ac-martin commented 4 years ago

Real applications will need to obtain data from the server in order to run.

We should provide a React component and/or hook that allows one to subscribe to a ReSTful API (or GraphQL).

Ideally, this would attempt to set up a webhook with the server so that after the initial payload the server could push any updates to the client. Polling the API according to a set interval could be used as a fall-back.

In order to support pushing updates we would need to build in support to the API endpoints so that is another thing to consider.

This sort of thing would likely benefit from Redux.

daniel-ac-martin commented 4 years ago

The GraphQL client from Apollo Server seems to do most of what we want. I think we should see if we can simply re-use that for now.

daniel-ac-martin commented 4 years ago

See: https://www.apollographql.com/docs/react/

daniel-ac-martin commented 3 years ago

Apollo Client is now available.

I've not tested subscriptions yet though. (We are on an old version of apollo-server in restify so it might not work.)

daniel-ac-martin commented 3 years ago

If nothing else, I'd expect polling to work: https://www.apollographql.com/docs/react/data/queries/#polling

daniel-ac-martin commented 3 years ago

Apollo seems to suggest that subscriptions should be used sparingly: https://www.apollographql.com/docs/react/data/subscriptions/#when-to-use-subscriptions