GraphQL is basically a query language for - API´s and it also provides a server-side runtime for executing the queries you have created.
Type system:
- You can create a GraphQL service by defining types and fields that we can call Schema, and create functions for each field to provide the required data. This functions are called resolvers.
Creating our first Schema
- As you can see, we have a type Query, if we query our field called hello, it will return an object User then we will have access to this data.
Creating the resolver for the field hello on Query type
- The resolver is a function with the same name as the field we want to retrieve data.
- Notice that the return will be an object with the same type of User.
How to query?
- The default entry point is called Query .
- So we can query like this:
- If we change the entry point called Query to MyQuery we cannot use only curly braces to query, we must do this way:
Executing Query
When executing the query on GraphQL Playground, we should have something like:
What have ou learned?
1º What is GraphQL
2º Creating Schemas
3º What are types, fields and resolvers
4º How to query and retrieve data
Top comments (0)