This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-08
Channels
- # aws (3)
- # beginners (126)
- # boot (19)
- # cider (31)
- # cljs-dev (324)
- # clojure (96)
- # clojure-boston (2)
- # clojure-denver (9)
- # clojure-dusseldorf (2)
- # clojure-greece (4)
- # clojure-italy (5)
- # clojure-losangeles (1)
- # clojure-spec (18)
- # clojure-uk (59)
- # clojurebridge (1)
- # clojurescript (184)
- # community-development (29)
- # cursive (2)
- # datascript (2)
- # datomic (5)
- # emacs (1)
- # figwheel (6)
- # fulcro (270)
- # hoplon (2)
- # jobs (1)
- # jobs-discuss (1)
- # keyboards (2)
- # leiningen (2)
- # london-clojurians (2)
- # luminus (10)
- # mount (1)
- # off-topic (26)
- # onyx (8)
- # other-languages (1)
- # parinfer (1)
- # protorepl (6)
- # re-frame (23)
- # reagent (61)
- # reitit (5)
- # shadow-cljs (100)
- # spacemacs (3)
- # sql (19)
- # unrepl (90)
- # vim (25)
i hacked my services.clj as follows
(defn dynamic-schema
"docstring"
[]
;(pp/pprint "IN dyn")
;(pp/pprint (resolver-map))
(-> "resources/graphql/schema.edn"
slurp
edn/read-string
(attach-resolvers (resolver-map))
(merge-custom-scalars)
schema/compile))
(defonce compiled-schema
(dynamic-schema))
(defn execute-request [rawbody]
(let [parsed (format-params rawbody)
query (:query parsed)
vars (:variables parsed)
context nil
schema (if (:dev env) (dynamic-schema) compiled-schema)]
(-> (lacinia/execute schema query vars context)
;(json/write-str)
)))
This allows for reloading the schema per request when you’re in dev mode, pulls out the query, vars, etc from the request, and ensures the response goes back as json as opposed to a string. There are some additional functions like merge-custom-scalars
that I added for my needs
I also had to change the default graphiql page as it wasn’t sending the variables, etc
function graphQLFetcher(graphQLParams) {
console.log(graphQLParams);
return fetch(window.location.origin + '/api' , {
method: 'post',
headers: {
'Content-Type': 'application/json'
// 'apikey': 'graphiql'
},
body: JSON.stringify(graphQLParams)
THe above got things working for meHmm. I think something's a bit funky about the changes on one side or the other. format-params
is throwing an error (`ERROR compojure.api.exception - JSON error (unexpected character): q`).
The query it's receiving is "query IntrospectionQuery { __schema { queryType { name } mutationType { name } subscriptionType { name } types { ...FullType } directives { name description locations args { ...InputValue } } } } fragment FullType on __Type { kind name description fields(includeDeprecated: true) { name description args { ...InputValue } type { ...TypeRef } isDeprecated deprecationReason } inputFields { ...InputValue } interfaces { ...TypeRef } enumValues(includeDeprecated: true) { name description isDeprecated deprecationReason } possibleTypes { ...TypeRef } } fragment InputValue on __InputValue { name description type { ...TypeRef } defaultValue } fragment TypeRef on __Type { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name }}}}}}}} "
.
That's on initial load of the graphiql page; I haven't entered an actual query yet.
Is it immediately obvious to you what's going on there?
BTW I didn't add dynamic-schema
yet, since I don't have any custom scalars (and I assume that merge-custom-scalars
is a fn in your code; I didn't find it in lacinia). Otherwise I'm following your suggestion word-for-word.
I should add that the same error is thrown before and after I make the suggested changes to the graphiql page.
Certainly doesn't seem like valid JSON, but it's not quite clear to me that it needs to be; it seems like we're just using JSON to do the string wrapping.
@eoliphant that’s a big help! Looking forward to incorporating it later this morning. Thanks tons for the extensive answer!