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:Your Supabase API key.
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 rowsupdate<Table>Collection- Update rowsdeleteFrom<Table>Collection- Delete rows
Example Table
Generated Types
Filtering
Filter results using thefilter argument:
Filter Operators
| Operator | Description | Example |
|---|---|---|
eq | Equal | { name: { eq: "Albania" } } |
neq | Not equal | { name: { neq: "Albania" } } |
gt | Greater than | { population: { gt: 1000000 } } |
gte | Greater than or equal | { population: { gte: 1000000 } } |
lt | Less than | { population: { lt: 1000000 } } |
lte | Less than or equal | { population: { lte: 1000000 } } |
in | In list | { code: { in: ["US", "CA"] } } |
is | Is null/not null | { capital: { is: null } } |
like | Pattern match | { name: { like: "%United%" } } |
ilike | Case-insensitive match | { name: { ilike: "%united%" } } |
Combining Filters
Useand, or, and not for complex filters:
Ordering
Sort results using theorderBy argument:
Order Options
AscNullsFirst- Ascending with nulls firstAscNullsLast- Ascending with nulls lastDescNullsFirst- Descending with nulls firstDescNullsLast- Descending with nulls last
Multiple Columns
Pagination
GraphQL uses cursor-based pagination:First N Records
Number of records to return from the beginning.
Return records after this cursor.
Next Page
Last N Records
Number of records to return from the end.
Return records before this cursor.
Relationships
Query related data using foreign keys:Filtering Related Data
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:GraphQL Playground
Access the GraphQL Playground in your project settings to explore your schema and test queries interactively.Limitations
Best Practices
Request only needed fields
Request only needed fields
Only query the fields you need to reduce payload size:
Use pagination
Use pagination
Always paginate large datasets using cursor-based pagination.
Use variables
Use variables
Use GraphQL variables instead of string interpolation to prevent injection attacks.
Enable RLS
Enable RLS
Always enable Row Level Security on your tables to protect your data.
Next Steps
Queries
Learn about advanced querying
Mutations
Modify data with mutations
