Home > Camis S24 > Object Types and Resolvers

Object Types and Resolvers (Backend)

This document is more or less my current understanding of object types and resolvers in the Hot Chocolate GraphQL backend, which can hopefully be used as a reference.

To create an object that can be included in GraphQL responses, there are a few steps involved:

  1. Create a “GraphQL version” of the object (optional but recommended)
  2. Create an Object Type of the object
  3. Include Object Type in 'AddCustomGQL'

While this document might cover most of what's necessary, other sources of the relevant information are:

Once the object is created/defined, it can be used in the backend as desired. (Note that you use the object, not the object type.)

Create a “GraphQL version” of the Object

Technically, this is optional. You can use the “original” object (the one used elsewhere in the backend), but there are some reasons to create a dedicated object:

(Note: Some objects may not have a “GraphQL version,” but will have a Type.)

Create an Object Type

In some cases, there can be several unused fields that don't need to be “resolved.” In fact, some fields cannot be automatically “resolved” and therefore will create errors if they aren't defined. Fields are explicitly bound here, and any resolvers can be added as necessary.

The link at the top about resolvers goes more in depth on how they look/work.

Include Object Type in AddCustomGQL

This one is pretty simple/straightforward. Add the code .AddType<ObjectType>() where all the other such statements are included. This provides Hot Chocolate/GraphQL with any necessary information about the object.