Exposing types¶
When working with a traditional REST API, the shape of the data we can query is defined by the different endpoints' responses, often defined through DTOs that aim to expose only what is relevant for that specific endpoint and hide any domain details that should not be leaked.
Object types¶
While it is possible to define our GraphQL by using DTOs and certain mapping libraries, we highly encourage using the type system to customize our objects instead. What in the REST world would be done as follows:
| C# | |
|---|---|
Can be achieved by defining a GraphQL user type
| C# | |
|---|---|
Object types can then be registered with the module options
| C# | |
|---|---|
Interface types¶
The GraphQL module also allows to declare types as interface types. In this case you do not need to define a custom type and can reference the domain type directly.
Note
The AddType<TEntity>() overload registers a default
ObjectType<TEntity> type. This is usually not required unless you are defining
an interface type with derived types.