Getting Started
Installation
Install and configure the package using the following command :
Getting Started
To explore the different capabilities of GraphQL we will create a sample GraphQL API for cooking recipes.
Let's start tih the Recipe type, which is the foundation of our API.
Create our Recipe type
The Recipe
We will start with a basic Recipe model.
The ObjectType
We now need to create an object type from our model. It will then be used in our GraphQL schema.
For simplicity here we use directly our model in our schema, but you can create a type from any class.
Create the CRUD operations
After that we want to create typical crud operations. Also called queries and mutations. For this we have to create a Resolver (similar to a controller).
The Resolver
The Inputs and Arguments
We are missing two important pieces, the inputs for the recipes query and the arguments for the addRecipe mutation.
Let's create them:
The @Length, @Min and @ArrayMaxSize are decorators coming from
class-validator a well-known validation library
that rely on decorators.
Register the Resolver
We must now register our Resolver with the GraphQL server:
Access the Playground
Everything is now ready!
You can access the GraphQL playground at http://localhost:3000/graphql and start playing with your queries and mutations.
