Overview
Let's meet the project we'll be working with in this series. 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!
Ever find yourself at a loss for what to cook for dinner, endlessly scrolling through videos and websites, and getting hangrier by the minute?
Poetic Plates lets you try your hand at AI-generated recipes with poetic instructions and delicious (or potentially 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 might 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 won'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!
Wanna try it out? Open up a new terminal and paste this curl command from the homepage. We can tweak the query to ask for a random recipe's name.
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}"}'
And we get data back: a random recipe with information 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 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 imagine a future where users can add their own recipes, create collections, and share their thoughts. We could provide more details about each ingredient, or 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?
Working with GraphOS
GraphOS helps us solve these problems.
To get started with GraphOS, we're going to use its web interface, Studio. There are two other ways to connect with GraphOS: Rover, a command-line interface used locally or in a CI/CD pipeline; and the Platform API, which is a GraphQL API to perform GraphOS actions in your own application.
In this course, we'll primarily be working with Studio, so you'll need an account to follow along!
Creating an Apollo account
In case you haven't created your Apollo account yet, visit https://studio.apollographql.com/signup. 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.
Practice
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
All right, we're ready to take Poetic Plates to the next level. GraphOS is going to transform our API into a federated graph. If you're not familiar with this federated architecture, don't worry! We'll cover it all in the next lesson.
Share your questions and comments about this lesson
Your feedback helps us improve! If you're stuck or confused, let us know and we'll help you out. All comments are public and must follow the Apollo Code of Conduct. Note that comments that have been resolved or addressed may be removed.
You'll need a GitHub account to post below. Don't have one? Post in our Odyssey forum instead.