graphile / crystal

🔮 Graphile's Crystal Monorepo; home to Grafast, PostGraphile, pg-introspection, pg-sql2 and much more!
https://graphile.org/
Other
12.52k stars 569 forks source link

eval is evil (and undocumented) #1950

Open benjie opened 5 months ago

benjie commented 5 months ago

Ref: https://discord.com/channels/489127045289476126/498852330754801666/1205068909787746304

So apparently the eval methods are completely undocumented... Good to know.

Yes; all the eval methods have a cost, but the more specific you can be the better. .evalHas(key) causes the plan to branch such that .evalHas('foo') will have two versions of the plan - one where foo is present, and one where foo is not present. (Compare to .eval() where each individual different object will result in a new plan.)

$__inputStep.evalHas(key): two plans $__inputStep.eval(): almost infinite plans $__inputStep.evalLength(): one plan for each length of the list $__inputStep.evalIs(val): two plans (one where $__inputStep's value === val; and one where it doesn't)

benjie commented 5 months ago

@jemgillam I think details of this was in one of the sponsors only talks; perhaps you could extract it and add to the docs?

benjie commented 2 months ago

Actually, we're looking to maybe remove eval if we can... So let's put this on ice.