This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-14
Channels
- # aleph (1)
- # aws-lambda (10)
- # beginners (161)
- # bitcoin (2)
- # boot (20)
- # cider (3)
- # clara (46)
- # cljs-dev (35)
- # cljsrn (9)
- # clojure (123)
- # clojure-boston (1)
- # clojure-colombia (1)
- # clojure-dusseldorf (3)
- # clojure-gamedev (2)
- # clojure-germany (2)
- # clojure-greece (1)
- # clojure-italy (7)
- # clojure-losangeles (3)
- # clojure-nl (2)
- # clojure-russia (15)
- # clojure-spec (1)
- # clojure-uk (7)
- # clojurescript (75)
- # community-development (5)
- # cursive (5)
- # datomic (25)
- # docs (3)
- # emacs (1)
- # fulcro (11)
- # graphql (131)
- # heroku (1)
- # jobs (1)
- # juxt (55)
- # lein-figwheel (2)
- # luminus (1)
- # off-topic (4)
- # om (8)
- # onyx (32)
- # pedestal (19)
- # re-frame (53)
- # reagent (11)
- # remote-jobs (1)
- # rum (12)
- # shadow-cljs (12)
- # spacemacs (53)
- # testing (2)
- # unrepl (18)
@karlstefan can you explain your problem in a bit more details and/or post your schema (and resolvers)?
Anyone here got experience with lacinia? I'm writing a graphQL proxy for a REST api, and I'm having problems traversing the REST endpoint and building tree data based on the response.
Give me asec
Uhm, what paste tool do you prefer for edn files?
@karlstefan I tend to use gist
It works for the first level
@karlstefan can you paste your resolvers too please?
oh, thanks hehe
The api is constructed with different 'model roots', which correspons to whatever domain the data belongs to. If the client/request-backend is called with nil it returns all of them in a hashmap.
This works, I've tested it.
But building the three from object { children { object { children ... etc does not
When the endpoint answers a call for an rid, and the object has children, it is returned as an array with of objects, and they all have the keys :rid :name :id
Somehow the object does not resolve children objects
Thats the body of an REST call, contains json data that is converted to a hashmap
(get :status) would yeild i.e 200 for OK or 401 for auth fail
as in https://gist.github.com/hmaurer/79c838966dff65b94d9c6a7102c9f7eb#file-response-L1
Oh, sure I'll show what a curl does. (I'm not sure how to pipe output in the REPL)
Thats an object which has children
There is a lot going on in that output, but only the rid, and children are relevant properties
under :Object?
I see, so just to be clear, I put the resolver under :object {:Object and not :queries ?
try this https://gist.github.com/hmaurer/79c838966dff65b94d9c6a7102c9f7eb#gistcomment-2202869
I see, lemme try! 😄
I'm probably being stupid now, but I need a new resolver for this, right?
(1) get rid of :resolve :resolve-read-object-rid
under :object :Object
in your edn schema
(2) add :resolve :my-resolver
(or whatever other name you want) under :object :Object :fields :children
then register a resolver under :my-resolver
mapping to the following function (which I hopefully got right):
(fn [context args _value]
(map (fn [val]
(:body (client/request-backend (:rid val)))) _value)
I think the resolver function is wrong, the repl throws an "Unsupported binding form" error
(fn [context args _value]
(map (fn [val]
(:body (client/request-backend (:rid val)))) _value))
(defn read-objects-rid [context args _value] (map (fn [val (:body (client/request-backend (:rid val))) _value])))
hold on
my bracket matcher at work
"message": "Field resolver returned a single value, expected a collection of values.",
from graph i QL
@karlstefan are you sure you got the resolver right?
counting brackets
😄 are you sure you are using read-objects-rid
and not read-object-rid
too? @karlstefan
Haha, yes
Lets see now
It seems to be working somehow, but its stuck in an infinite loop hitting the API
Thats a tricky one
But I got something to go on now, thanks a lot for your help!
I see the problem now
I'm requesting an enormous tree
@hmaurer Do you know whats passed in _value in the reducer?
@karlstefan the value under children
in the api payload
@karlstefan ah hang on, no, sorry
as in
(fn [context args _value]
(map (fn [val]
(:body (client/request-backend (:rid val)))) (:children _value)))
It works!
I think with the previous (wrong) code your client/request-backend
was being called with nil
as argument
Thanks! 😄
This is my first attempt at clojure, very excited!
So remember: resolves are always placed on fields, and they get passed the value of their containing object
i see, so args in args and their value in _value
Whats the context for then, if you dont mind me asking
@karlstefan passing down some stuff to all resolvers. For example, you might want to pass down a database connection, the authentication status, etc
@hmaurer I see 🙂
Where would I specify what to pass down?
> The two nils are variables to be used executing the query, and an application context.
note that if you printed out the first argument you would see a lot more than :answer
you don’t need to care about that for now, but it does contain some useful stuff for more advanced use-cases
I'll read up in the docs! 🙂 Thanks again for your time!
I watched and enjoyed your talk on YouTube, good stuff 🙂