Exposing the Entity on GraphQL¶
The Suite Framework favors GraphQL over HTTP/Rest APIs. The framework provides several integration points to facilitate the creation of GraphQL queries and mutations.
Exposing Entity¶
The GraphQL Module provides a way to expose an entity trough a GraphQL query
with a simple configuration on the GraphQL Module Options. In fact, the
microservice template adds this configuration for us to expose the main entity
of our microservice. Lets check the EquipmentsApplicationModule
class.
The method ExposeInPublicApi
allows us to expose the entity as a query on
GraphQL. It takes the entity class and the DTO class as generic parameters, and
the name for the query as string parameter. As mentioned in the comments left by
the template, lets change the name of the query with something appropriate and
lets remove the comments.
Info
Notice that on a previous chapter, when adding the Code
property to our
entity we had to also add it on a DTO and an AutoMapper Profile, that was
necessary because the ExposeInPublicApi
uses AutoMapper to map from the
entity to the DTO configured on the generic types.
Now we can run the Application project and try executing the following query on the GraphQL Playground:
We should get the two equipments we created when doing Data Seeding:
The exposed entity includes also by default a lot of features like paging, filtering, quick search, etc. See the following: