paren-com / serene

Generate clojure.spec with GraphQL and extend GraphQL with clojure.spec
135 stars 3 forks source link

Spec cannot be satisfied #8

Closed se-neaxplore closed 10 months ago

se-neaxplore commented 10 months ago

Using a custom scalar scalar Timestamp generates a spec clojure.core/any?. Extending this scalar with clojure.core/inst? results in (clojure.spec.alpha/and clojure.core/any? clojure.core/inst?) Which is still not satisfiable by clojure spec.

Swapping the clauses (clojure.spec.alpha/and clojure.core/inst? clojure.core/any?) solves this problem.

Proposal: Change the generated spec to put the extended spec first.

I think the change should be introduced here defmethod compiler/transducer :extend

Let me know what you think and if you would like to move forward with this, I will make a PR.

domkm commented 10 months ago

Sure, PR welcome. It's been a long time since I've looked at this code, so I don't recall if this is feasible, but perhaps we could drop the default any? when extending instead of always anding.

Aside, do you know why (clojure.spec.alpha/and clojure.core/any? clojure.core/inst?) is not satisfiable? That is surprising to me.

se-neaxplore commented 10 months ago

Removing (clojure.core/any?) would solve it directly.

The (s/and) generator uses the first generator to generate a value which is than passed to the next spec. any? generates a lot of different values but never an Inst.

(gen/sample (s/gen (s/and clojure.core/any? string?))) this expression works sometimes, because any? generates String.