Fork me on GitHub

thanks a bunch hlship!


Hey all... I'm an idiot. I've been toying around with 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?


I have no idea lol


To be honest, I only test using the q function from the user ns that the Lacinia team so graciously provided for us,


Fair enough. Did you get the query string using that q fn?


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.e. if I wanted to transform data


Where does that go? This project seems to magically pass through to the db layer


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


Yeah, if you look in that file, you’ll see something like this,

(defn resolver-map
  (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.


That map is the go-between for the schema and the actual code.


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!


Ok that makes sense. So then how do I call one of the non-queries?


I.e. (board-game-designers db)


(defn resolver-map
  (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


So... like this?`BoardGame { board-game-designers }`?


Also it doesn't allow me to change these fns without restarting the server whcih is a little frustrating


Is it common with graphql to throw exceptions such as 400s, 404s etc?


It also appears that status codes aren't a thing?