Getting Started

In this chapter, you will learn about the GraphQL schema:

  1. How it performs as an API contract between the consumer and the provider,
  2. How you can use graphql library as a basic GraphQL execution mechanism
  3. What is a GraphQL operation and how you can use it.

Getting Started with GraphQL

To get a better understanding of how GraphQL works, you can start by reading this tutorial about GraphQL basics.

If you are already familiar with the basics of GraphQL, here’s a quick overview:

  1. The GraphQL schema is where your GraphQL types are defined.

  2. GraphQL types are connected to each other using fields, and they form a graph.

  3. The Query and Mutation types are special, since they act as entry point to the graph.

  4. The GraphQL schema acts as the data provider, and it offers a set of capabilities the consumer can use.

  5. To get data from a GraphQL schema, you need to write a GraphQL operation (a query) that selects the data and fields you need.

In this section of the tutorial, you’ll write a simple GraphQL schema, and you’ll consume it directly, just for the learning process.

Later, you’ll replace the direct execution with a GraphQL server (based on HTTP protocol), and you’ll add developer tools that will make it super simple to query and access.

Creating your first GraphQL schema

There are many ways to create a GraphQL schema - in this tutorial, you are going to use schema-first approach, and build the schema with the @graphql-tools/schema library (take a look at the end of this chapter for more advanced/different solutions for creating your GraphQL schema).

A GraphQL schema can be written with GraphQL SDL (Schema Definition Language), which is the GraphQL language for defining your API/contract. The actual code and business-logic of each field is called a GraphQL resolvers.

So let’s get started by creating your first, very-simple, GraphQL schema.

Unlock the next chapter
What does `makeExecutableSchema` function do?
Convert GraphQL SDL to DocumentNode
Combine multiple SDLs into one
Glue GraphQL SDL with Resolvers into an executable schema we can later use
Run schema with query