This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-13
Channels
- # adventofcode (77)
- # beginners (132)
- # boot (11)
- # cider (40)
- # clara (10)
- # cljsjs (1)
- # cljsrn (4)
- # clojure (148)
- # clojure-android (1)
- # clojure-greece (5)
- # clojure-italy (5)
- # clojure-nl (7)
- # clojure-spec (57)
- # clojure-uk (9)
- # clojurescript (115)
- # core-matrix (1)
- # cursive (3)
- # data-science (1)
- # datomic (1)
- # duct (7)
- # emacs (20)
- # fulcro (29)
- # funcool (4)
- # graphql (31)
- # instaparse (15)
- # java (1)
- # jobs (6)
- # jobs-discuss (95)
- # leiningen (2)
- # off-topic (30)
- # om (4)
- # onyx (7)
- # pedestal (6)
- # quil (4)
- # re-frame (52)
- # reagent (59)
- # rum (1)
- # spacemacs (3)
- # specter (61)
- # test-check (3)
Hey all... I'm an idiot. I've been toying around with https://github.com/walmartlabs/clojure-game-geek I've been trying to use curl to do the queries but I'm tripping over the simplest ones. I can't figure out what I'm doing wrong:
curl --request POST \
--url \
--header 'content-type: application/graphql' \
--data '{"query":"query { game_by_id(id: \"1237\") { name designers { name }}}"}'
{"errors":[{"message":"Failed to parse GraphQL query.","errors":[{"location":{"line":1,"column":null},"parse-error":"mismatched input '\"query\"' expecting {'query', 'mutation', 'subscription', '...', NameId}"}]}]}%
@petr give this a go, curl -XPOST localhost:8888/graphql -H 'Content-Type:application/graphql' -d '{game_by_id(id: "1237") {name designers {name}}}'
@admay THanks for the reply! I seem to have gotten it working with this:
curl --request POST \
--url \
--header 'content-type: application/json' \
--data '{"query":"query { game_by_id(id: \"1237\") { name designers { name }}}"}'
So the difference is that the graphql content type automagically adds the "query" part of the request?To be honest, I only test using the q
function from the user ns that the Lacinia team so graciously provided for us, https://github.com/walmartlabs/clojure-game-geek/blob/master/dev-resources/user.clj#L29
Nope, just kind of lucked out. I tried it without any headers to see what would happen and I got an error telling me in so many words, “You have to have a content type of json or graphql”. So I tried graphql and it worked!
I'm a little confused, looking at this project, how I would write logic for handling requests
I’m not sure I understand your question. Are you wondering how to write mutations? Or are you wondering how Lacinia handles the request?
SO mutations is another question, but not this one I.e. Say I wanted to do more than just pull data out of a DB. Say I wanted an endpoint that rather than made mutations, or got data, it instead called a function that kicked off an asynchronous process
Ah, okay, so you want to work with the resolvers a bit then, correct? What I mean by that is, you’re looking for a resolver that instead of just reading something from a data store would send an HTTP request or something like that
So I see there are some examples: https://github.com/walmartlabs/clojure-game-geek/blob/master/src/clojure_game_geek/schema.clj#L31 That's an example?
Yeah, if you look in that file, you’ll see something like this,
(defn resolver-map
[component]
(let [db (:db component)]
{:query/game-by-id (game-by-id db)
:query/member-by-id (member-by-id db)
:BoardGame/designers (board-game-designers db)
:BoardGame/rating-summary (rating-summary db)
:GameRating/game (game-rating->game db)
:Designer/games (designer-games db)
:Member/ratings (member-ratings db)}))
That’s your resolver map.So if you want another query to send an http request and return a success or fail status, you’ll need a few things. In the context of the clojure-game-geek code, you will need: 1. A status object in the schema 2. A query object in the schema with a resolver 3. A resolver function in the schema.clj namespace 4. A mapping in the resolver-map to connect the query object from the schema to the code in the schema namespace
I have to hop off for a bit for a meet up, keep posting questions and I’ll answer them when I’m back online as soon as I can!
(defn resolver-map
[component]
(let [db (:db component)]
{:query/game-by-id (game-by-id db)
:query/member-by-id (member-by-id db)
:BoardGame/designers (board-game-designers db)
:BoardGame/rating-summary (rating-summary db)
:GameRating/game (game-rating->game db)
:Designer/games (designer-games db)
:Member/ratings (member-ratings db)
:Request/make-request (my-request-function ... )}))
Once you’ve created all your schema objects and add the mapping, Lacinia knows what to do