The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Adds some graphql docs
Copple276a624457cc
diff --git a/README.md b/README.mdindex a8a07c99b33..5cee2492dd8 100644--- a/README.md+++ b/README.md@@ -8,13 +8,17 @@[Supabase](https://supabase.com) is an open source Firebase alternative. We're building the features of Firebase using enterprise-grade open source tools.-- [x] Hosted Postgres Database-- [x] Realtime subscriptions-- [x] Authentication and authorization-- [x] Auto-generated APIs+- [x] Hosted Postgres Database. [Docs](https://supabase.com/docs/guides/database)+- [x] Authentication and Authorization. [Docs](https://supabase.com/docs/guides/auth)+- [x] Auto-generated APIs.+ - [x] REST. [Docs](https://supabase.com/docs/guides/api#restful-api)+ - [x] Realtime subscriptions. [Docs](https://supabase.com/docs/guides/api#realtime-api)+ - [x] GraphQL (Beta). [Docs](https://supabase.com/docs/guides/api#graphql-api)+- [x] Functions.+ - [ ] Database Functions. [Docs](https://supabase.com/docs/guides/database/functions)+ - [ ] Edge Functions (coming soon).+- [x] File Storage. [Docs](https://supabase.com/docs/guides/storage)- [x] Dashboard-- [x] Storage-- [ ] Functions (coming soon)## Documentationdiff --git a/web/docs/guides/api.mdx b/web/docs/guides/api.mdxindex a7fb8dfc992..26ea345b875 100644--- a/web/docs/guides/api.mdx+++ b/web/docs/guides/api.mdx@@ -13,18 +13,18 @@ Supabase generates three types of API directly from your database schema.- REST - interact with your database through a restful interface.- Realtime - listen to database changes.-- GraphQL - [coming soon](https://supabase.com/blog/2021/12/03/pg-graphql).+- GraphQL - [in beta](/blog/2021/12/03/pg-graphql).The APIs are:-- Instant and auto-generated: as you update your database the changes are immediately accessible through your API.-- Self documenting: Supabase generates documentation in the Dashboard which updates as you make database changes.-- Secure: the API is configured to work with PostgreSQL's Row Level Security, provisioned behind an API gateway with key-auth enabled.-- Fast: our benchmarks for basic reads are more than 300% faster than Firebase. The API is a very thin layer on top of Postgres, which does most of the heavy lifting.-- Scalable: the API can serve thousands of simultaneous requests, and works well for Serverless workloads.+- **Instant and auto-generated.** <br />As you update your database the changes are immediately accessible through your API.+- **Self documenting.** <br />Supabase generates documentation in the Dashboard which updates as you make database changes.+- **Secure.** <br />The API is configured to work with PostgreSQL's Row Level Security, provisioned behind an API gateway with key-auth enabled.+- **Fast.** <br />ur benchmarks for basic reads are more than 300% faster than Firebase. The API is a very thin layer on top of Postgres, which does most of the heavy lifting.+- **Scalable.** <br />the API can serve thousands of simultaneous requests, and works well for Serverless workloads.-### RESTful API+### REST APISupabase provides a RESTful API using [PostgREST](https://postgrest.org/). This is a very thin API layer on top of Postgres.It provides everything you need from a CRUD API:@@ -45,20 +45,29 @@ It provides everything you need from a CRUD API:allowFullScreen></iframe>-### Realtime API+### GraphQL API-Supabase provides a Realtime API using [Realtime](https://github.com/supabase/realtime). You can use this to listen to database changes over websockets.-Realtime leverages PostgreSQL's built-in logical replication. You can manage your Realtime API simply by managing Postgres publications.+:::note-### GraphQL API+GraphQL is in Beta, and may have breaking changes. It is only available on self-hosted setups and Supabase projects created after 28th March 2022.++:::++GraphQL in Supabase works through [pg_graphql](/blog/2021/12/03/pg-graphql), an open source PostgreSQL extension for GraphQL.+To get started with GraphQL you must enable the `pg_graphql` extension in your project.-[Coming soon](https://supabase.com/blog/2021/12/03/pg-graphql). We are developing `pg_graphql`, an open source PostgreSQL extension for GraphQL.-`pg_graphql` inspects an existing PostgreSQL schema and reflects a GraphQL schema with resolvers. We will expose `pg_graphql` via the existing REST interface.+<video width="99%" muted playsInline controls="true">+<source src="/docs/videos/api/api-enable-graphql.mp4" type="video/mp4" muted playsInline />+</video>+### Realtime API++Supabase provides a Realtime API using [Realtime](https://github.com/supabase/realtime). You can use this to listen to database changes over websockets.+Realtime leverages PostgreSQL's built-in logical replication. You can manage your Realtime API simply by managing Postgres publications.## Getting started-After you have added tables or functions to your database, you can use the API.+All APIs are auto-created from Database tables. After you have added tables or functions to your database, you can use the APIs provided.### Creating API Routes@@ -105,19 +114,10 @@ create table todos (</TabItem></Tabs>-### API URL and KeysEvery Supabase project has a unique API URL. Your API is secured behind an API gateway which requires an API Key for every request.-You can find the Keys inside the Dashboard.--<Tabs-defaultValue="UI"-values={[- {label: 'UI', value: 'UI'}-]}>-<TabItem value="UI">```sh1. Go to the "Settings" section.@@ -130,16 +130,22 @@ values={[<source src="/docs/videos/api/api-url-and-key.mp4" type="video/mp4" muted playsInline /></video>-</TabItem>-</Tabs>+The REST API and the GraphQL API are both accessible through this URL:++- REST: `https://<project_ref>.supabase.com/rest/v1`+- GraphQL: `https://<project_ref>.supabase.com/rest/v1`+Both of these routes require the `anon` key to be passed through an `apikey` header.-#### Details and links:+#### API Keys-You are provided with two keys initially:++You can find the Keys inside the Dashboard in the same location as the URL above.++You are provided with two keys:- an `anon` key, which is safe to be used in a browser context.-- a `service_role` key, which should only be used on a server. This key can bypass Row Level Security.+- a `service_role` key, which should only be used on a server. This key can bypass Row Level Security. NEVER use this key in a browser.### Accessing the Docs@@ -161,16 +167,23 @@ values={[3. Switch between the Javascript and the cURL docs using the tabs.```+<video width="99%" muted playsInline controls="true">+<source src="/docs/videos/api/api-docs.mp4" type="video/mp4" muted playsInline />+</video>+</TabItem></Tabs>-### Using the API+## Using the API+++### REST APIYou can interact with your API directly via HTTP requests, or you can use the client libraries which we provide.Let's see how to make a request to the `todos` table which we created in the first step,-using the API URL (`[SUPABASE_URL]`) and Key (`[SUPABASE_ANON_KEY]`) we provided:+using the API URL (`SUPABASE_URL`) and Key (`SUPABASE_ANON_KEY`) we provided:<Tabs@@ -184,10 +197,10 @@ values={[```javascript// Initialize the JS clientimport { createClient } from '@supabase/supabase-js'-const supabase = createClient([SUPABASE_URL], [SUPABASE_ANON_KEY])+const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY)// Make a request-let { data: todos, error } = await supabase+const { data: todos, error } = await supabase.from('todos').select('*')```@@ -197,44 +210,73 @@ let { data: todos, error } = await supabase```bash# Append /rest/v1/ to your URL, and then use the table name as the route-curl '[SUPABASE_URL]/rest/v1/todos' \--H "apikey: [SUPABASE_ANON_KEY]" \--H "Authorization: Bearer SUPABASE_ANON_KEY"+curl '<SUPABASE_URL>/rest/v1/todos' \+-H "apikey: <SUPABASE_ANON_KEY>" \+-H "Authorization: Bearer <SUPABASE_ANON_KEY>"```</TabItem></Tabs>-#### Details and links:--- When you create a table in Postgres, Row Level Security is disabled by default. Make sure you secure it by [enabling RLS](/docs/guides/api#securing-your-routes).-- Never expose the `service_role` key in a browser or anywhere where a user can see it.-- JS Reference: [select()](/docs/reference/javascript/select),+JS Reference: [select()](/docs/reference/javascript/select),[insert()](/docs/reference/javascript/insert),[update()](/docs/reference/javascript/update),[upsert()](/docs/reference/javascript/upsert),[delete()](/docs/reference/javascript/delete),[rpc()](/docs/reference/javascript/rpc) (call Postgres functions).-### Safeguards towards accidental deletes and updates-For new projects, by default, the Postgres extension [safeupdate](https://github.com/eradman/pg-safeupdate) is enabled for all queries coming from the API.-This ensures that any `delete()` or `update()` would fail if there are no accompanying filters provided.-This can be disabled by running the following query on the SQL editor on the dashboard:+### GraphQL API-```sql-alter role "authenticator"-set "session_preload_libraries" to default;+You can use any GraphQL client with the Supabase GraphQL API. For our GraphQL example we will use [urlql](https://formidable.com/open-source/urql/docs/).++<Tabs+defaultValue="Javascript"+values={[+ {label: 'Javascript', value: 'Javascript'},+ {label: 'cURL', value: 'cURL'},+]}>+<TabItem value="Javascript">++```javascript+import { createClient, useQuery } from 'urql';++const client = createClient({+ url: '<SUPABASE_URL>/grapqhl/v1',+})++const TodosQuery = `+ query {+ todos {+ id+ title+ }+ }+`++const [result, reexecuteQuery] = useQuery({+ query: TodosQuery,+})++const { data, fetching, error } = result```-To reenable it :-```sql-alter role "authenticator"-set "session_preload_libraries" = 'safeupdate';+</TabItem>+<TabItem value="cURL">++```bash+# Append /grapqhl/v1/ to your URL, and then use the table name as the route+curl --request POST '<SUPABASE_URL>/grapqhl/v1' \+-H 'apikey: <SUPABASE_ANON_KEY>' \+-H 'Authorization: Bearer <SUPABASE_ANON_KEY>' \+-d '{ "query":"{ todos(first: 3) { edges { node { id } } } }" }'```-The above can also be run to enable it for existing projects. Settings are applied immediately and as such no restarts are needed after running any of the two.-### Managing Realtime+</TabItem>+</Tabs>+++### Realtime APIThe Realtime API works through PostgreSQL's replication functionality. Postgres sends database changes to a "publication"@@ -242,6 +284,12 @@ called `supabase_realtime`, and by managing this publication you can control whiBy default Realtime is disabled on your database. Let's turn on Realtime for the `todos` table.+:::note++Realtime only works for tables in the public schema.++:::+<TabsdefaultValue="UI"values={[@@ -271,14 +319,47 @@ alter publication supabase_realtime add table products;</TabItem></Tabs>-#### Details and links:+Now we can listen to any new data that is inserted into the `todo` table:-- Realtime only works for tables in the public schema.-- [JS Reference](/docs/reference/javascript/subscribe): Subscribe to database changes using the realtime client+<Tabs+defaultValue="Javascript"+values={[+ {label: 'Javascript', value: 'Javascript'}+]}>+<TabItem value="Javascript">++```javascript+// Initialize the JS client+import { createClient } from '@supabase/supabase-js'+const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY)++// Create a function to handle inserts+const handleInserts = (payload) => {+ console.log('Change received!', payload)+}++// Listen to unserts+const { data: todos, error } = await supabase+ .from('todos')+ .in('INSERT', handleUpdates)+ .subscribe()+```++</TabItem>+</Tabs>++Use [subscribe()](/docs/reference/javascript/subscribe) to listen to database changes.++## API Security### Securing your Routes++Your API is designed to work with Postgres Row Level Security. If you use Supabase [Auth](/docs/guides/auth), you can restrict data based on the logged-in user.+To control access to your data, you can use [Policies](/docs/guides/auth#policies).+When you create a table in Postgres, Row Level Security is disabled by default. Make sure you secure it by [enabling RLS](/docs/guides/api#securing-your-routes).+<TabsdefaultValue="UI"values={[@@ -303,8 +384,29 @@ alter table todos enable row level security;</TabItem></Tabs>+### The `service_role` key+++Never expose the `service_role` key in a browser or anywhere where a user can see it. This Key can is designed to bypass Row Level Security - so it should only be used on a private server.++We have [partnered with GitHub](/blog/2022/03/28/community-day#supabase-is-now-a-github-secret-scanning-partner) to scan for Supabase `service_role` keys pushed to public repositories.+If they detect any keys with service_role privileges being pushed to GitHub, they will forward the API key to us, so that we can automatically revoke the detected secrets and notify you, protecting your data against malicious actors.++### Safeguards towards accidental deletes and updates++For new projects, by default, the Postgres extension [safeupdate](https://github.com/eradman/pg-safeupdate) is enabled for all queries coming from the API.+This ensures that any `delete()` or `update()` would fail if there are no accompanying filters provided.+This can be disabled by running the following query on the SQL editor on the dashboard:++```sql+alter role "authenticator"+set "session_preload_libraries" to default;+```-#### Details and links:+To reenable it :+```sql+alter role "authenticator"+set "session_preload_libraries" = 'safeupdate';+```+The above can also be run to enable it for existing projects. Settings are applied immediately and as such no restarts are needed after running any of the two.-- Your API is designed to work with Postgres Row Level Security. If you use Supabase [Auth](/docs/guides/auth), you can restrict data based on the logged-in user.-- To control access to your data, you can use [Policies](/docs/guides/auth#policies).diff --git a/web/static/videos/api/api-docs.mp4 b/web/static/videos/api/api-docs.mp4new file mode 100644index 00000000000..7fe41d76a17Binary files /dev/null and b/web/static/videos/api/api-docs.mp4 differdiff --git a/web/static/videos/api/api-enable-graphql.mp4 b/web/static/videos/api/api-enable-graphql.mp4new file mode 100644index 00000000000..f563d278f21Binary files /dev/null and b/web/static/videos/api/api-enable-graphql.mp4 differ