walmartlabs / lacinia

GraphQL implementation in pure Clojure
http://lacinia.readthedocs.io/en/latest/
Other
1.82k stars 160 forks source link

Tracing "validation" fields are always null #448

Open favila opened 1 year ago

favila commented 1 year ago

When using the "tracing" extension (e.g. the lacinia-timing header in pedestal), the "validation" field always looks like {:startOffset nil, :duration nil} instead of having an offset and duration.

I believe this is because lacinia execute-query pulls the ::timing/validation entry off the context map instead of the parsed-query map.

Both com.walmartlabs.lacinia.pedestal.internal/on-enter-prepare-query and com.walmartlabs.lacina/execute-parsed-query-async seem to add this to the parsed-query map, not its parent map.

As a workaround in lacinia-pedestal, I insert the following interceptor somewhere in-between l.pedestal2/prepare-query-interceptor and l.pedestal2/query-executor-handler to copy the validation data to the place execute-query expects, although I think execute-query is probably the code that should change here.

(interceptor
     {:enter (fn [pctx]
               (update-in pctx [:request :lacinia-app-context] conj
                          (find (-> pctx :request :parsed-lacinia-query)
                                :com.walmartlabs.lacinia.tracing/validation)))})