DEV Community

Joao Colussi
Joao Colussi

Posted on

2

What is GraphQL and creating your first Schema

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. GraphQL Schema

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.

Creating resolver

How to query?

  • The default entry point is called Query .
  • So we can query like this:

GraphQL Query

  • If we change the entry point called Query to MyQuery we cannot use only curly braces to query, we must do this way:

GraphQL changing entrypoint name

Executing Query
When executing the query on GraphQL Playground, we should have something like:

GraphQL executed Query

What have ou learned?
What is GraphQL
Creating Schemas
What are types, fields and resolvers
How to query and retrieve data

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more