FastAPI + SQLAlchemy Tutorial

The code for this article can be found on my GitHub: https://github.com/jmgraff/fastapi-sqlalchemy-sqlite-example FastAPI has made creating an API for your app incredibly simple. SQLAlchemy has also done the same for interacting with databases. Using both of them together makes it very simple to have your API store and retrieve data from a number of different … Read more

Strawberry: Type Query must define one or more fields

This error occurs when you pass a Strawberry type to strawberry.Schema as the query parameter, but that type doesn’t define any fields. To fix this, define at least one field on the type you passed as the query argument. I came across this error when working on the real-time chat app GraphQL example. Since I … Read more

GraphQL Example: Real-time Chat App Using Subscriptions

The code for this example can be found on GitHub here: https://github.com/jmgraff/strawberry-graphql-chat-app. This project builds off our previous full-stack GraphQL example. If you’re new to GraphQL and haven’t read it yet, you should check it out. What we’re making We’re going to make a real-time chat application using GraphQL subscriptions. GraphQL subscriptions are implemented with … Read more

FastAPI: Access to fetch blocked by CORS policy

When using FastAPI, this error can occur when your frontend content is being served from a different server (or port) than your backend server. To fix this, import CorsMiddleware from starlette.middleware.cors and add it to your app. What is CORS? CORS stands for “Cross-Origin Request Sharing”. It’s what allows scripts in your browser to safely … Read more

Full Stack GraphQL Example: FastAPI, Strawberry, and URQL

The source code for this article is available on GitHub: https://github.com/jmgraff/fastapi-strawberry-urql This example will walk you through creating a docker compose based full-stack GraphQL API using FastAPI+Strawberry on the backend, and React+URQL on the frontend. The associated GitHub repo is a template and is designed to be used as a starting point for new GraphQL … Read more