I am looking at the Sangria library for encoding GraphQL server in Scala. However, it seems strange that a system of the same type should be implemented twice: (1) as part of GraphQL type declarations and (2) also on the server side, as Scala class classes, with an accompanying ObjectType, InterfaceType, etc. vals.
Hard coding the type system in Scala is especially tedious, since my goal is to be able to CRUD aggregates of arbitrary shape, where each form is defined as a collection of GraphQL types. For example, say an instance of the Shape type contains a GraphQL document as a field; and an instance of type Entity has a link to its form and also contains a Json object of the form defined in that form.
case class Shape(id: String, name: String, doc: sangria.ast.Document) case class Entity(id: String, name: String, shape: Shape, content: JsValue)
For example, if the form document looks something like this:
type Person { firstName: String! lastName: String! age: Int }
then the content of Json in essence could be something like this:
{ "firstName": "John", "lastName": "Smith", "age": 30 }
(a real example, of course, would also have nested types, etc.)
Thus, I am trying to define instances of type Entity whose form is defined in the appropriate form. I do NOT want to hardcode the corresponding sangria.schema.Schema, but I want to get it directly from the form document.
Is there a ready-made way to generate a GraphQL schema programmatically from a GraphQL document containing type declarations?