Skip to main content

Overview

GraphQL queries allow you to fetch exactly the data you need from your Supabase database. This guide covers advanced query patterns and techniques.

Basic Queries

Select All Rows

Fetch all rows from a table:

Select Specific Fields

Only request the fields you need:

Select Single Row

Query a single row by its primary key:

Filtering

Equality Filters

Comparison Filters

Pattern Matching

List Filters

NULL Filters

Complex Filters

AND Conditions

OR Conditions

NOT Conditions

Nested Conditions

Sorting

Single Column

Multiple Columns

NULL Handling

Pagination

Forward Pagination

Next Page

Use the endCursor from the previous query:
Variables:

Backward Pagination

Relationships

One-to-Many

Fetch a country with its cities:

Many-to-One

Fetch a city with its country:

Many-to-Many

Fetch students with their courses:

Nested Filtering

Filter parent based on child properties:

Aggregations

Count

Get the total count of records:

Count with Filter

Variables

Using Variables

Variables:

Multiple Variables

Variables:

Optional Variables

Aliases

Rename fields in the response:

Fragments

Defining Fragments

Inline Fragments

Use inline fragments for union types:

Directives

@include

Conditionally include fields:

@skip

Conditionally exclude fields:

Best Practices

Define fragments for commonly used field sets:
Always use cursor-based pagination for large datasets.
Only query the fields you actually need to minimize payload size.
Never interpolate values directly into query strings - use variables.

Next Steps

Mutations

Learn how to modify data

Client Libraries

Use GraphQL with client SDKs