OxfordAbstracts / purescript-graphql-client

Typesafe graphql client for purescript
43 stars 6 forks source link

Add urql live query #117

Closed jmatsushita closed 1 year ago

jmatsushita commented 1 year ago

Adding @live queries in the style of https://github.com/n1ru4l/graphql-live-query

 - Testing end to end with a graphql-yoga server with live queries enabled.
 - Also refactored  the default `query_` client to be in the `Affjax.Node` module to avoid depending on `urql` across tests.

Example (from the end to end test):
```purescript
main :: Effect Unit
main = do

  client :: Client UrqlLiveQueryClient Directives Query _ _ <-
    createLiveQueryClient
      { url: "http://localhost:4000/graphql"
      , headers: [ ]
      }

  let
    event = liveQuery client "" $ live {} { greetings }

  handle <-
    HS.subscribe event \e -> do
      log "Live Query update received"
      logShow e

  launchAff_ do
    delay $ Milliseconds (3.0 * 1000.0)
    liftEffect $ HS.unsubscribe handle
roryc89 commented 1 year ago

I think this is a useful idea, but as I don't want to expand the scope this lib much more, I'm afraid I wont be merging.