Introduction
Want to take your GraphQL API to the next level? Then you're in the right place!
If you've built products and experiences powered by a GraphQL API, then you know how powerful GraphQL can be when it comes to app development! You've felt that satisfaction of querying for exactly what you need and getting that data back in the shape you asked for. You understand the value of the schema acting as the contract between front-end and back-end. You recognize the efficiency of bringing together multiple data sources and services to be accessible under one endpoint.
Note: If this doesn't sound like you, you can start learning how to build a full-stack app with GraphQL through our introductory tutorial series, Lift-off.
So what's next? There comes the need to grow and evolve the graph. We want to deliver a richer experience, which involves adding more data sources, more features, more services. How do we protect our graph and facilitate its growth in a way that sets us up for success?
Enter Apollo GraphOS.
Apollo GraphOS is a complete cloud platform for building, managing, and scaling your GraphQL API. GraphOS provides a set of tools and services so that developers can focus on building better apps, faster.
We'll start with an existing GraphQL API and transform it into a supergraph (and we'll cover exactly what that means in this course).
Learner pre-requisites
We assume that you have a basic level of understanding of GraphQL and how to write a GraphQL query. Check out our Lift-off series if you need a refresher. You don't need to know any particular programming language for this tutorial.
Series overview
We're here to help you navigate the world of Apollo GraphOS! In this introductory series all about GraphOS, we'll learn:
- Basics: how to get started with GraphOS using an existing GraphQL API. That's the course you're in now!
- Shipping your supergraph: how to ship supergraph changes using safe schema delivery
- Growing your supergraph: how to add new capabilities and data to your supergraph
- Securing your supergraph (coming soon): how to implement authentication and authorization in a supergraph
- Improving your supergraph performance (coming soon): how to use caching and queries to make your supergraph faster
There's a lot to unpack! In this course, let's focus on that first important step: getting our GraphQL API on GraphOS.
Along the way, we'll learn about the components of a supergraph architecture. We have lots of hands-on opportunities ahead: we'll build queries for the supergraph with the Apollo Explorer IDE, analyze our supergraph metrics, and configure the cloud router.
Let's dive in!
In this lesson, we will:
- Examine our API so far and our future plans 🍲🥘
- Learn what GraphOS offers to help make app development easier and faster
Our API so far...
Introducing Poetic Plates 🍽️, the GraphQL API for adventurous cooks and foodies! Try your hand at AI-generated recipes with poetic instructions and delicious (or disastrous) results. With extremely detailed and sometimes helpful instructions, cooking has never been more fun!
The API architecture
The Poetic Plates API is written in JavaScript and uses Apollo Server. Here's what the codebase directory looks like:
📦 poetic-plates-api┣ 📂 src┃ ┣ 📂 datasources┃ ┣ 📂 resolvers┃ ┣ 📄 index.js┣ 📄 package.json┣ 📄 schema.graphql┗ 📄 README.md
If you've built GraphQL APIs before, this should look familiar! It's a GraphQL server with a schema, resolvers and data sources. Here's the quick rundown for the important files:
schema.graphql
: A schema that defines the types and fields that describe our recipes content.resolvers
: Defines resolver functions for the fields in the schema.datasources
: In a real-world application, this data source would probably connect to a REST API or a database, but we're in tutorial-land so we're using hard-coded data in a JSON file in the same directory.index.js
: Creates anApolloServer
instance that uses the three components above.
You don't need to clone the repository, but feel free to browse the codebase if you're curious.
Poetic Plates is hosted at https://poetic-plates-recipes-api.herokuapp.com/, ready to receive queries and return data! To try it out, open up a new terminal and paste the curl command below.
curl --request POST \--header 'content-type: application/json' \--url 'https://poetic-plates-recipes-api.herokuapp.com/' \--data '{"query":"query GetRandomRecipe {\n randomRecipe {\n name\n readyTime\n servings\n ingredients {\n text\n }\n }\n}"}'
You should get back an object: a random recipe with data about how long it takes to cook and the ingredients it needs!
How we're using Poetic Plates
Right now, the API is simply a small collection of recipes. We can do things like:
- ask it for a random recipe
- ask it a for the full list of recipes in its database
- ask it for the most recently added recipes
- see a recipe's ingredients, cooking time, instructions, and more
But we've got big plans for Poetic Plates! We can see a future where we add new features like enabling users to add their own recipes, creating collections, sharing their thoughts about specific recipes. Maybe we can provide folks with more details about their ingredients, or we can recommend specific recipes based on what's already in their pantry. The possibilities are endless!
While we're working on these new features and growing our schema, we also want to keep our current functionality up and running smoothly. We want to track the health of our API, and monitor things like which fields aren't being used, what are the most requested operations, or which parts of a query are way too slow. What's causing problems for the clients using it? Where can we improve?
GraphOS helps us solve these problems and more!
Introducing GraphOS
Apollo GraphOS is a complete cloud platform for building, managing, and scaling a supergraph.
We'll learn about and make use of awesome GraphOS features throughout this course and series, like:
The schema registry: A version control system for our schema, enabling us to see how our supergraph has evolved over time.
Tracking our supergraph's health and analytics: We'll examine how our fields are being used, what queries clients are sending and what errors are occurring in our supergraph.
Safe schema delivery: GraphOS checks every schema change to make sure it won't break our supergraph.
Cloud routing: GraphOS takes care of provisioning and hosting the router, a key part of our supergraph architecture. We'll learn more about what this means and see it in action over the next few lessons!
There are three ways to interface with GraphOS:
- Apollo Studio - the web interface located at https://studio.apollographql.com/.
- The Rover CLI - a command-line interface that can run helpful commands in your local terminal or your CI/CD pipeline.
- The Platform API - a GraphQL API that enables you to perform GraphOS actions from your own custom application.
In this course, we'll primarily be working with Apollo Studio, so you'll need an account to follow along!
Creating an Apollo Studio account
In case you haven't created your Apollo account yet, visit http://studio.apollographql.com and click Create an account. You can sign up either with an email and password, or with an existing GitHub account. You'll also create your own organization.
After that, you're all set to use GraphOS.
Key takeaways
- Apollo GraphOS helps you build, manage and scale your GraphQL API.
- There are three ways to interface with GraphOS: Studio, Rover and the Platform API.
- In this tutorial, we'll be working with an existing API called Poetic Plates 🍽️, the GraphQL API for adventurous cooks and foodies!
Up next
Setting up our Poetic Plates API with GraphOS is a pretty quick and easy process, as we'll see in lesson 3. But if you're still not really sure how it all works, what GraphOS is going to do with the API, and how a supergraph fits into all this, then let's take a moment to answer those questions! In the next lesson, we'll identify the key pieces of a supergraph architecture and how GraphOS helps to make it easier to maintain.
Share your questions and comments about this lesson
This course is currently in
You'll need a GitHub account to post below. Don't have one? Post in our Odyssey forum instead.