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:
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.)
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.)
.BindFieldsExplicitly()
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.
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.