Fork me on GitHub
#graphql
<
2018-01-11
>
Oliver George09:01:40

Hi Guys. I've had some fun trying out lacinia over the last few days. There's a few "first experience" things I wanted to mention in case it is helpful.

Oliver George09:01:39

First one was that it was confusing working out how to add interceptors. The use of a threading macro in the example code is concise but gets in the way based on how the default interceptors get included by pedestal.

hlship17:01:36

Please paste the URL of the page in question, so I'm sure we're looking at the same thing.

Oliver George22:01:46

http://lacinia-pedestal.readthedocs.io/en/latest/overview.html

(def service (-> (hello-schema)
                 (service-map {:graphiql true})
                 http/create-server
                 http/start))
I think the quirk which was confusing was how/when default interceptors get added. Depends on :interceptor not being set from memory.

Oliver George22:01:10

Perhaps threading would have been fine once I gave up on using the :interceptors key

Oliver George09:01:51

My code ended up looking like

(start [this]
    (let [compiled-schema (:schema schema-provider)
          options {:graphiql true}
          service-map (-> (lp/service-map compiled-schema options)
                          (assoc ::http/allowed-origins (fn [x] true))
                          http/default-interceptors
                          http/dev-interceptors)
          server (http/create-server service-map)]
      (assoc this :server (http/start server))))

Oliver George09:01:30

(I should have said first that the pedestal lacinia tutorial is fanastic... keep it going)

Oliver George09:01:17

Also, it seems odd that field-resolvers don't know the key they are associated with. The default field resolver works around this. Just seems like a funny thing to not know since they are passed a map value and don't have enough context to actually know what key they are meant to be working on.

hlship17:01:12

The intent is that application code, as the provider of the field resolver function, will know that detail; there's also the option of using field resolver factories (with the attach-resolvers function).

hlship17:01:45

Default field resolvers are expected to be 'trivial' and adapt to the field in question.

hlship17:01:58

Application field resolvers are expected to be specific to a particular field, within reason.

hlship17:01:56

In theory, we could pass some field data in the application context, passed to the field resolver. In fact, its largely already there ... but not public. We'd need an api to get the data properly, and stably across future releases.

hlship17:01:25

So, not perfectly consistent, but better than passing four parameters to every field resolver function!

Oliver George22:01:00

I see what you mean. Not sure I can comment on a good pattern/solution. Feels like you want a "you are here" which points to a spot in the schema. Just an observation that it feels oddly clumsy when you're poking around.

hlship17:01:50

Side note: once Clojure's new "git" dependencies work their way through the toolchain (including Leiningen and Cursive), these PR releases will likely just be a tag, not built and pushed to Clojars. We'll see.

lilactown20:01:06

i got a really weird one for you all

lilactown20:01:16

I’m trying to use lacinia in AWS lambda

lilactown20:01:37

I’m able to execute queries and whatnot in the REPL just fine

lilactown20:01:45

I’m guessing this is an issue with antlr or clj-antlr and some classpath nonsense with the AOT compiling, but I’m a complete java newb and so I’m at a bit of a loss. hoping ya’ll might have more experience

lilactown20:01:31

I’ve tried unzipping the generated uberjar and poking around, and i do see the mentioned “antlr.stg”, but it appears empty

hlship20:01:10

That is odd; all of our applications are Uberjars (without AOT). Are you using Leiningen? Can we see the project.clj?

hlship20:01:38

I'm not sure what version of Java is supported on lambda, that could be a factor (unlikely, though).

lilactown20:01:27

I am using leiningen

lilactown20:01:41

(defproject cmb-fido-personalization-lambda "0.1.0-SNAPSHOT"
  :description "User personalization data service POC"
  :dependencies [[org.clojure/clojure "1.8.0"]
                 [org.clojure/data.json "0.2.6"]
                 [com.walmartlabs/lacinia "0.23.0"]
                 [com.amazonaws/aws-lambda-java-core "1.1.0"]]
  :source-paths ["src"]
  :resource-paths ["resources"]
  :aot :all)

hlship20:01:09

Should be pretty straight forward, but AWS is not something I use (I can't even use my Walmart corporate card on Amazon's web site).

hlship20:01:56

Can you try, as an experiment, to deploy the Uberjar without AOT? AOT will make your Uberjar much larger, but won't make a huge difference in startup time (maybe 10%).

lilactown20:01:09

I’m not sure I can do that

lilactown20:01:29

it’s not able to find my class. the way that AWS Lambda works, it expects a class that implements com.amazonaws.services.lambda.runtime.RequestStreamHandler. so I’m using gen-class to create it

lilactown20:01:07

i’m not sure how gen-class works without AOT, but when I deployed it without AOT it said it can’t find my class now

lilactown20:01:01

(btw, it’s Java 8 - that’s all AWS says in their docs)

hlship20:01:25

Ok, I can see that. I'm afraid I'm in the middle of things right now and can't give much more help. I'd start by investigating what's in the Uberjar vs. what's in the Antlr Jars, then dig around the Leiningen docs/examples to see why some files are not being packaged. Also, check, what's in aws-lambda-java-core to see if it for some reason has Antlr repackaged inside it (this kind of crazy stuff happens for no good reason!).

lilactown21:01:03

hmm. OK, thanks 🙂