Skip to main content

Introduction

Supabase provides a GraphQL API powered by pg_graphql, allowing you to query your PostgreSQL database using GraphQL. The API is automatically generated from your database schema.
GraphQL support in Supabase is currently in beta. The API is production-ready but may receive breaking changes.

Endpoint

Your GraphQL API is available at:

Authentication

Authenticate requests using the same headers as the REST API:
string
required
Your Supabase API key.
string
Bearer token for authenticated requests.

Basic Query

Query your database using GraphQL syntax:

Response

Schema Reflection

The GraphQL schema is automatically generated from your database schema. Each table becomes a collection type with the following structure:
  • <table>Collection - Query multiple rows
  • <table> - Query a single row (if primary key is provided)
  • insert<Table>Collection - Insert rows
  • update<Table>Collection - Update rows
  • deleteFrom<Table>Collection - Delete rows

Example Table

Generated Types

Filtering

Filter results using the filter argument:

Filter Operators

Combining Filters

Use and, or, and not for complex filters:

Ordering

Sort results using the orderBy argument:

Order Options

  • AscNullsFirst - Ascending with nulls first
  • AscNullsLast - Ascending with nulls last
  • DescNullsFirst - Descending with nulls first
  • DescNullsLast - Descending with nulls last

Multiple Columns

Pagination

GraphQL uses cursor-based pagination:

First N Records

Int
Number of records to return from the beginning.
Cursor
Return records after this cursor.

Next Page

Last N Records

Int
Number of records to return from the end.
Cursor
Return records before this cursor.

Relationships

Query related data using foreign keys:

Variables

Use variables to make queries reusable:

Variables JSON

Fragments

Reuse query parts with fragments:

Introspection

Explore your schema using introspection:

Get Type Details

Row Level Security

GraphQL respects your PostgreSQL Row Level Security policies:
The GraphQL API will automatically apply these policies based on the authenticated user.

GraphQL Playground

Access the GraphQL Playground in your project settings to explore your schema and test queries interactively.

Limitations

  • Mutations are in beta and may have limitations
  • Some PostgreSQL features may not be fully supported
  • Complex computed fields require custom functions

Best Practices

Only query the fields you need to reduce payload size:
Always paginate large datasets using cursor-based pagination.
Use GraphQL variables instead of string interpolation to prevent injection attacks.
Always enable Row Level Security on your tables to protect your data.

Next Steps

Queries

Learn about advanced querying

Mutations

Modify data with mutations