graphql

Jakub Holý 2020-01-29T11:35:58.016400Z

Hello folks, what library do people use as a GraphQL client? Lacinia is only the server-side, no?

gklijs 2020-01-30T09:31:48.017700Z

For testing subscription I created my 'own' client, it's practically just taken from re-graph, but clojure only and different api https://github.com/openweb-nl/kafka-graphql-examples/blob/master/test/src/nl/openweb/test/graphql_client.clj.

Jakub Holý 2020-01-30T15:00:52.018100Z

thanks!

lispers-anonymous 2020-01-31T15:50:46.018300Z

I've been working on a cljs graphql client that draws a lot of ideas from apollo. The caching from apollo is really nice and it's mainly what I'm trying to replicate using reagent atoms and cursors. Is that something you think you'd be interested in using?

orestis 2020-01-31T16:04:32.020300Z

Yes, mostly caching and normalizing of data. Though caching scares me - they didn’t have a way to evict items from cache until the (unreleased) version 3

☝️ 1
orestis 2020-01-31T16:22:48.021600Z

I’m not using reagent but exploring the idea (in my head) to model something using an agent-like abstraction

lispers-anonymous 2020-01-31T17:30:21.021800Z

The advantage of using reagent atoms for the cache is it can still be updated outside the normal query/mutation APIs. So it looks something like

(let [my-favorite-atom] (query gql-client data-for-query)
  (fn []
     [:div (-> @my-favorite-atom :data)
       [:input {:type button
                :value "evict stuff from cache"
                :on-click #(reset! my-favorite-atom nil)}]]))
That would evict that particular query from the cache in the way I currently have things set up. Any other components that use the same query would also be cleared because they share an atom. A similar approach could be used to clear the entire cache if you wanted to do that. Just reset the atom and it's all taken care of.

orestis 2020-01-31T17:39:12.023200Z

Is the caching per-query or per-entity? That’s the normalizing that I was referring to. Keechma’s entity DB is what I’d like to look into.

lispers-anonymous 2020-01-31T17:51:36.023400Z

I just started working on this last weekend and implemented a cache entry per query. But the entire cache is just a giant clojure map. and cursors can be used to create a "window" into the cache at any point, including individual entities in say a list of users. So if you had a query that returned a list of users, the query would provide the component with a single r/atom with all those users. Then if you wanted to create a component for each user entity, a cursor could be created for each of them and passed into those component functions. As something like a subscription or mutation updates each user entity individually in the cache (I've not implemented that), then those user components would be updated. Apollo provides support for this as well with readFragment I believe https://www.apollographql.com/docs/react/api/apollo-client/#ApolloClient.readFragment So the client I'm working on could do something similar to provide what looks like a cache per-entity.

lispers-anonymous 2020-01-31T17:53:27.023600Z

An thanks for asking that. This have given me a lot of ideas and things to think about

souenzzo 2020-02-03T19:35:03.024800Z

#fulcro with #pathom remote can do "graphql client"

👍 1
gklijs 2020-01-29T14:05:20.016500Z

Yes, lacinia is server only. You can use re-graph it should support even Clojure now. Another common client for the JVM is the android one https://github.com/apollographql/apollo-android?files=1.

👍 1
isak 2020-01-29T15:52:26.016900Z

I don't see the need for a client, just using normal http calls

orestis 2020-01-29T16:47:42.017100Z

We’re doing plain http calls — but I have it on my roadmap to see what Apollo offers, mostly to get a “global store” of sorts. If that seems too big, I have a rough plan to see if I can use Keechma’s EntityDB for the global store, and leverage Transit to get CLJS objects.

orestis 2020-01-29T16:48:19.017300Z

We’re also currently writing a macro of sorts to validate queries (at CLJS compile time) against our Lacinia schema. Still tinkering with it though.

2020-01-29T18:42:03.017500Z

People familiar with Fulcro web framework can use Pathom to translate (Clojure-native) EQL to graphql and have the data fetch at the same time. See Pathom documentation Graphql section for details