haskell-graphql / graphql-api

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

What is the difference between HasObjectDefinition and HasAnnotatedType? #196

Closed EdmundsEcho closed 6 years ago

EdmundsEcho commented 6 years ago

My apologies for the question. I've worked with the library for a couple of months now and have missed the point of the two class definitions: HasObjectDefinition and HasAnnotatedType.

Do we only use HasAnnotatedType when we want to specify that our object can be null? And if so, required when our type is wrapped by Maybe?

(in non-Haskell implementations, it is a definition to specify non-null)

Thank you in advance for clarifying.

theobat commented 6 years ago

An annotation is not part of anyone's schema, and can only be used with another type (builtin or part of the user's schema). example: [Boolean]! On the other hand an object definition is simply a Type definition.

EdmundsEcho commented 6 years ago

Thank you for your response. I'm confused by how [Boolean]!, a gql schema specification, is "not part of anyone's schema". Can you tell me more about what you mean? Are you saying the ! indicating non-null, is an example "Annotated"?... and "can only be used with another type".

theobat commented 6 years ago

Yes, ! is an example of an annotation, same as the brackets for a List ([]). This means that [Boolean]!is of type AnnotatedType awhere a can be either an InputType or a GType. Besides, there are two different kind of graphQL types here, the Builtin types which are part of graphQL itself, (e.g. Boolean, Stringetc), and there are custom types (e.g. for non input types: DefinedType TypeDefinitionversus BuiltinType Builtin). "not part of anyone's schema" only means that the definition of Boolean, String, Int etc is baked in with graphQL itself, if by schema I meant the set of all type definitions of a given graphQL user, then it's not part of anyone's schema, it's part of the library itself.

Hope this helps.

theobat commented 6 years ago

An then to precise the answer of your original question: