haskell-graphql / graphql-api

Write type-safe GraphQL services in Haskell
BSD 3-Clause "New" or "Revised" License
406 stars 35 forks source link

Validate schema before using it for resolution #62

Open jml opened 7 years ago

jml commented 7 years ago

In #42, @teh and I both agreed that we should ideally not be checking for schema validity while we are resolving values.

The difficulty is that we need to construct values from the type-level schema in order to do the work of resolution.

The solution, as I see it, is to construct a value-level representation of the schema before resolving and to pass that as a parameter to buildResolver. As we traverse down the selection set that represents the user query, we would also traverse down the value-level schema, shucking off the top-most layer.

jml commented 7 years ago

Related, there's a TODO to switch from using the stand-in NonEmptyList to using the base library's NonEmpty, which actually enforces non-emptiness. I started on this, but am oh so tired and really need to get to work.

Probably the right way to do it is:

jml commented 7 years ago

Related, there are two TODOs for trying to enforce non-empty lists of fields etc. at the type level.

I'm pretty sure this is possible and even straightforward (although it will likely require more typeclasses).[*] However, I wouldn't want to begin to attempt it until the value-level stuff correctly enforced non-emptiness.

[*] If you can have a list of types, and you can have a product of types, then you can have a non-empty type. Fields Field [Field] would guarantee Fields is non-empty.