Fork me on GitHub
#graphql
<
2017-06-01
>
lilactown19:06:51

I'm using lacinia, and running into problems with a simple example:

(schema/compile {:queries    {
              :hello  {:type    String
                       :resolve "hello"}}})

lilactown19:06:03

and i'm getting ExceptionInfo Could not process type. clojure.core/ex-info (core.clj:4617)

hlship19:06:28

:resolve has to be a function; this will attempt to invoke ("hello" context args nil).

hlship19:06:16

Use io.aviso/pretty and you'll more easily see the details of the exception.

hlship19:06:57

Chances are it's complaining about type QueryRoot and field hello, and there's an error because "hello" is not a function.

hlship19:06:10

Try (constantly "hello") to get the effect you are looking for.

lilactown19:06:43

graphql-demo.server>  (schema/compile {:queries    {
              :hello  {:type    String
                       :resolve (constantly "world")}}})
ExceptionInfo Could not process type.  clojure.core/ex-info (core.clj:4617)

hlship19:06:29

That should work. I'd need to see the full stack trace / exception info.

hlship19:06:20

clojure.lang.ExceptionInfo: Could not process type.
clojure.lang.ExceptionInfo: Could not identify type of field.
                                          clojure.core/eval            core.clj: 3105
                                                        ...                          
                                             user/eval48926           REPL Input     
                     com.walmartlabs.lacinia.schema/compile          schema.clj:  812
                     com.walmartlabs.lacinia.schema/compile          schema.clj:  818
   com.walmartlabs.lacinia.schema/construct-compiled-schema          schema.clj:  765
            com.walmartlabs.lacinia.internal-utils/map-vals  internal_utils.clj:   39
                                     clojure.core/reduce-kv            core.clj: 6573
                                clojure.core.protocols/fn/G       protocols.clj:  174
                                            clojure.core/fn            core.clj: 6547
                                        clojure.core/reduce            core.clj: 6545
                                clojure.core.protocols/fn/G       protocols.clj:   13
                                  clojure.core.protocols/fn       protocols.clj:   75
                         clojure.core.protocols/iter-reduce       protocols.clj:   49
                                         clojure.core/fn/fn            core.clj: 6557
         com.walmartlabs.lacinia.internal-utils/map-vals/fn  internal_utils.clj:   40
com.walmartlabs.lacinia.schema/construct-compiled-schema/fn          schema.clj:  765
                                                        ...                          
                com.walmartlabs.lacinia.schema/eval19878/fn          schema.clj:  609
              com.walmartlabs.lacinia.schema/compile-fields          schema.clj:  529
                                        clojure.core/update            core.clj: 5960
           com.walmartlabs.lacinia.schema/compile-fields/fn          schema.clj:  529
             com.walmartlabs.lacinia.internal-utils/map-kvs  internal_utils.clj:   51
                                     clojure.core/reduce-kv            core.clj: 6573
                                clojure.core.protocols/fn/G       protocols.clj:  174
                                            clojure.core/fn            core.clj: 6547
                                        clojure.core/reduce            core.clj: 6545
                                clojure.core.protocols/fn/G       protocols.clj:   13
                                  clojure.core.protocols/fn       protocols.clj:   75
                         clojure.core.protocols/iter-reduce       protocols.clj:   49
                                         clojure.core/fn/fn            core.clj: 6557
          com.walmartlabs.lacinia.internal-utils/map-kvs/fn  internal_utils.clj:   52
        com.walmartlabs.lacinia.schema/compile-fields/fn/fn          schema.clj:  530
               com.walmartlabs.lacinia.schema/compile-field          schema.clj:  335
                com.walmartlabs.lacinia.schema/rewrite-type          schema.clj:  317
                                        clojure.core/update            core.clj: 5960
                 com.walmartlabs.lacinia.schema/expand-type          schema.clj:  291
                                       clojure.core/ex-info            core.clj: 4617
clojure.lang.ExceptionInfo: Could not process type.
    type: java.lang.String
clojure.lang.ExceptionInfo: Could not identify type of field.
    field: {:type java.lang.String,
            :resolve
            #object[clojure.core$constantly$fn__4614 0x19890edf "clojure.core$constantly$fn__4614@19890edf"]}

lilactown19:06:25

working on getting aviso/pretty setup

hlship19:06:40

Ah, there's the problem. You need to quote 'String when doing this from REPL. That way String is a symbol, not a class. Easy to miss. Always best to put as much of your schema into EDN as possible, so that things don't get eval'ed.

lilactown19:06:30

I'm trying to come up with a very minimal example to add to the lacinia-pedestal docs. do you think it would be confusing to people coming to the library if it had the quoted 'String in the example, but best practice is to store the schema in an .edn file?

hlship20:06:45

Best practice is absolutely to store the schema as an EDN file. Schema at the REPL should be considered the exception, not the rule. Use the attach-resolvers utility function.

lilactown20:06:20

sure; that's what I'm using for my own projects

lilactown20:06:02

I'm trying to improve the documentation in the lacinia and lacinia-pedestal project, as I found it quite difficult to get to a working project by following them

lilactown20:06:58

I thought providing a simple ~30 line example would help a lot

lilactown20:06:34

especially as someone who is new to lacinia and pedestal (and clojure!), barebones examples help a lot

hlship20:06:05

We've put a lot (a lot) of effort into the Lacinia docs, but it's a never-ending struggle to keep them readible, upto date, and accurate.

hlship20:06:51

But I do like your example, and I'll gladly accept it as a PR.

hlship20:06:25

Include an example of running curl against the running server, too.

lilactown20:06:17

totally! docs are often the hardest part of a project like this 😅 especially with where the project is at

lilactown20:06:22

I'd like to help out where I can