shadow-cljs

conao3 2025-12-06T04:56:51.153349Z

:node-script target exists, and this cljs is intended to be executed on the server side. It depends on resources/schema.graphql and is being loaded via shadow.resource/inline. When schema.graphql changes, watch will automatically recompile, but in cases where the schema.graphql is being edited and may be corrupted, I want to interrupt the build rather than replacing the new output with it. I considered using :build-hooks, but throwing an exception here would cause shadow-cljs to endlessly retry. Is there any way to tell shadow-cljs to interrupt the build in such cases?

thheller 2025-12-07T15:24:41.372429Z

there is not no and I would recommend solving this outside shadow-cljs. for example save to a different file, validate it and only when validated copy it to the included location. or just do not include it in the build at all. doesn't seem like something that needs to be inlined. just load if the (fs/readFileSync ...) into node at runtime?

conao3 2025-12-08T00:15:02.740429Z

Since loading a broken schema.graphql at runtime causes the server to crash, we must maintain a backup of a previous, valid schema.graphql. Running this at runtime would be cumbersome, so we want to handle this during the build phase instead. Is there a configuration method for specifying prerequisites required for the build process?

thheller 2025-12-08T07:04:03.410909Z

well, you can just write your own macro. inline is just a very small wrapper around the slurp-resource helper function. https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/resource.clj#L73

thheller 2025-12-08T07:05:35.743789Z

so something like

(defmacro inline-gql [path]
  (let [text (slurp-resource &env path)]
    (when (invalid-graphql? text)
      (throw (ana/error &env "graphql is invalid!")))
    text))

thheller 2025-12-08T07:06:02.464649Z

that'll throw and exception and thus cause a build error

thheller 2025-12-08T07:07:13.350779Z

see https://code.thheller.com/blog/shadow-cljs/2019/10/12/clojurescript-macros.html on how to write a macro. ana/error is cljs.analyzer/error, make sure to only require that in the .clj part of the macro. otherwise it'll make your build huge if part of the .cljs compile

thheller 2025-12-08T07:14:12.923929Z

you can just throw any exception, but using ana/error the error will at least point to the correct location.

conao3 2025-12-08T07:17:36.434739Z

thanks! I'll try it after get home.