In this tutorial, you’ll learn how to build a CRUD app with  FastAPI,  GraphQL, and  Orator ORM.

Objectives

By the end of this tutorial, you will be able to:

  1. Explain why you may want to use GraphQL over REST
  2. Use Orator ORM to interact with a Postgres database
  3. Describe what Schemas, Mutations, and Queries are in GraphQL
  4. Integrate GraphQL into a FastAPI app with Graphene
  5. Test a GraphQL API with Graphene and pytest

Why GraphQL?

(And why GraphQL over traditional REST?)

REST is the de-facto standard for building web APIs. With REST, you have multiple endpoints for each CRUD operation: GET, POST, PUT, DELETE. Data is gathered by accessing a number of endpoints.

For example, if you wanted to get a particular user’s profile info along with their posts and relevant comments, you would need to call four different endpoints:

  1. /users/<id> returns the initial user data
  2. /users/<id>/posts returns all posts for a given user
  3. /users/<post_id>/comments returns a list of comments per post
  4. /users/<id>/comments returns a list of comments per user

#fastapi #graphql #api

Developing an API with FastAPI and GraphQL
16.35 GEEK