Fork me on GitHub
#graphql
<
2019-05-05
>
bartuka01:05:41

Hi people, I would like to split the definitions of my schema into several files. Is it possible to do that on lacinia?

lilactown03:05:20

I think the schema is just EDN, so you can read the files and merge them before you pass it into lacinia

bartuka04:05:43

Yeah, I just did that. Thanks!

rakowa19:05:40

Hello there. I'm looking for a pattern that handles UI submission of mutations, and receipt of response data, particularly in reagent.

rakowa19:05:09

What I have so far are input and submit button components, where input is parsed into the mutation arguments, and the submit button increments a "submissions" ratom. The ratom is dereferenced by the component that issues the mutation. Problem is, when submissions gets swap/inc'ed, entire tree is re-rendered up to where the ratom was instantiated (not, as hoped, only where it gets deref'ed).

lilactown19:05:21

this sounds like a #reagent question, not a #graphql question

lilactown19:05:00

it could depend on how you are instantiating / passing around the ratom

rakowa19:05:11

I think you're right - the ratom question is more for #reagent, but I still wonder if there is a good pattern for UI-driven mutations and result handling.

lilactown19:05:46

at work, we’ve built a framework using apollo and reagent so that we can push/pull data and represent them as ratoms or promises

Lennart Buit19:05:13

Oh apollo? I thought that was hard to incorporate in a cljs codebase

lilactown19:05:04

nope, wasn’t too hard at all

lilactown19:05:24

we don’t use apollo-react, the base apollo-client library is much more amenable to integration with Reagent

Lennart Buit19:05:50

ahh that explains. What makes apollo-react hard to intergrate?

Lennart Buit19:05:36

(oh, sorry I am hijacking a conversation, I just got interested ^^)

lilactown19:05:39

using regular react components in Reagent is quite a pain. the patterns that apollo-react uses (HoC and children-as-fn) require lots of converting to- and from- Reagent to React

lilactown19:05:48

hehe it’s OK 😄

lilactown19:05:54

with a thinner wrapper around React, apollo-react can be used seamlessly

Lennart Buit19:05:08

didn’t you write hx? Would it be easier to integrate with that?

lilactown19:05:35

I did 🙂 yes, I have an internal app at work I wrote using hx + react-apollo and it was quite seamless

Lennart Buit19:05:02

cool! I really like your approach with hx

Lennart Buit19:05:55

it feels counterproductive to put layers on top of such a moving target like React 🙂!

lilactown20:05:28

yeah I think there’s some seriously cutting edge things coming out of React this year that we will want to build on top of

lilactown20:05:43

and unfortunately, libraries like Reagent are not directly compatible with them

lilactown21:05:55

just for giggles, I made an example with react-apollo: https://gist.github.com/Lokeh/bee8fd2010a801354dcbfe7bda371d85

👍 8
stefan05:05:44

I followed the example in the gist, but I’m getting an error that the query prop is undefined for some reason

stefan05:05:18

(defnc concept-select [_]
  [apollo/Query {:query (gql "{ concepts { id } }")} 
   (fn [result]
     (let [{:keys [data error loading]} (j/lookup result)]
       (cond
         loading [:div "loading..."]
         error   [:p   "uh oh..."]
         :else   [:p   "it works"])))])

lilactown05:05:46

are you using the latest version of hx? I had a bug that I pushed a fix for that I discovered in implementing that gist :P

lilactown05:05:58

it should be 0.5.1

stefan05:05:24

that did it! thanks 🙏

lilactown19:05:56

typically, a mutation is fired via some action (e.g. a button click). We swap an atom to indicate that the action has fired and notify the user via some UI update. apollo automatically detects that some data in a particular query that components has pulled changed via the mutation, and will then re-query in those components

rakowa20:05:56

Ah, so mutation issuance depends on a ratom driven re-render?

lilactown20:05:03

I don’t think so. I’m not sure I understand the question

lilactown20:05:09

“issuance”?

lilactown20:05:27

the mutation is fired when the button is clicked. we swap a ratom to indicate that an action is in progress

lilactown20:05:53

re-querying for the data is done elsewhere

rakowa22:05:08

thanks, that helps!