ocaml-graphql-server icon indicating copy to clipboard operation
ocaml-graphql-server copied to clipboard

Schema.obj allows for fields to be an empty list, which causes a runtime error for clients

Open sgrove opened this issue 7 years ago • 1 comments

If fields for a GraphQL object type is empty, it'll cause an error to be thrown on the reference GraphQL implementation, so that this is effectively not valid:

let gen_TokenPaginationObj =
    Schema.(
      obj("TokenPagination", ~fields=_gen_forRecObjType => [])
    )

Perhaps there should be some validation function we can call at runtime to make sure we've constructed a valid GraphQL schema?

sgrove avatar Jun 18 '18 00:06 sgrove

I've considered having Schema.schema raise an exception in case of validation errors. Presumably creating a schema is something that happens once at "boot time", so it should be easy to catch invalid schemas with even the most primitive test suite. There are definitely more complex solutions (e.g. add a phantom type parameter to Schema.schema which is either unvalidated or validated -- then you can only execute queries on validated schemas), but I'm not sure it's worth it.

Could you be interested in adding one or more validations?

andreas avatar Jun 19 '18 20:06 andreas