Fork me on GitHub
#luminus
<
2018-03-08
>
eoliphant01:03:33

hi, i’m using it

eoliphant01:03:52

had to make a few hacks to get it to where it did what i needed

eoliphant01:03:45

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)
        )))

eoliphant01:03:03

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

eoliphant01:03:19

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 me

eggsyntax17:03:15

Hmm. 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.

eggsyntax17:03:23

I should add that the same error is thrown before and after I make the suggested changes to the graphiql page.

eggsyntax17:03:09

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.

eggsyntax13:03:54

@eoliphant that’s a big help! Looking forward to incorporating it later this morning. Thanks tons for the extensive answer!

eoliphant13:03:27

no prob, i was planning to make a PR for these changes at some point