Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

add in generated files

Inian822f26c9828f
diff --git a/apps/reference/_supabase_js/generated/invoke.mdx b/apps/reference/_supabase_js/generated/invoke.mdx
index 06f9f02f14a..bc2eb51a724 100644
--- a/apps/reference/_supabase_js/generated/invoke.mdx
+++ b/apps/reference/_supabase_js/generated/invoke.mdx
@@ -12,7 +12,7 @@ Invokes a Supabase Function.
```js
const { data: user, error } = await supabase.functions.invoke('hello', {
- body: JSON.stringify({ foo: 'bar' }),
+ body: { foo: 'bar' },
})
```
@@ -115,26 +115,46 @@ object representing the headers to send with the request
- Requires an Authorization header.
- Invoke params generally match the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) spec.
+- When you pass in a body to your function, we automatically attach the Content-Type header for `Blob`, `ArrayBuffer`, `File`, `FormData` and `String`. If it doesn't match any of these types we assume the payload is `json`, serialise it and attach the `Content-Type` header as application/json. You can override this behaviour by passing in a Content-Type header of your own.
+- Responses are automatically parsed as `json`, `blob` and `form-data` depending on the `Content-Type` header sent by your function. Responses are parsed as `text` by default.
## Examples
### Basic invocation.
+null
+
```js
const { data: user, error } = await supabase.functions.invoke('hello', {
- body: JSON.stringify({ foo: 'bar' }),
+ body: { foo: 'bar' },
})
```
-### Specifying response type.
+### Error handling.
-By default, `invoke()` will parse the response as JSON. You can parse the response in the following formats: `json`, `blob`, `text`, and `arrayBuffer`.
+A `FunctionsHttpError` error is returned if your function throws an error, `FunctionsRelayError` if the Supabase Relay has an error processing your function and `FunctionsFetchError` if there is a network error in calling your function.
```js
+import {
+ FunctionsHttpError,
+ FunctionsRelayError,
+ FunctionsFetchError,
+} from '@supabase/supabase-js'
+
const { data: user, error } = await supabase.functions.invoke('hello', {
- responseType: 'text',
- body: JSON.stringify({ foo: 'bar' }),
+ headers: {
+ 'my-custom-header': 'my-custom-header-value',
+ },
+ body: { foo: 'bar' },
})
+
+if (error instanceof FunctionsHttpError) {
+ console.log('Function returned an error', error.message)
+} else if (error instanceof FunctionsRelayError) {
+ console.log('Relay error:', error.message)
+} else if (error instanceof FunctionsFetchError) {
+ console.log('Fetch error:', error.message)
+}
```
### Passing custom headers.
@@ -146,6 +166,6 @@ const { data: user, error } = await supabase.functions.invoke('hello', {
headers: {
'my-custom-header': 'my-custom-header-value',
},
- body: JSON.stringify({ foo: 'bar' }),
+ body: { foo: 'bar' },
})
```
diff --git a/apps/reference/_supabase_js/generated/update.mdx b/apps/reference/_supabase_js/generated/update.mdx
index 1a9810af163..a62c1f87774 100644
--- a/apps/reference/_supabase_js/generated/update.mdx
+++ b/apps/reference/_supabase_js/generated/update.mdx
@@ -139,7 +139,7 @@ const { data, error } = await supabase
.from('users')
.update(
`
- address: {
+ address: {
street: 'Melrose Place',
postcode: 90210
}
diff --git a/spec/supabase_js_v2_legacy.yml b/spec/supabase_js_v2_legacy.yml
index d760eef2893..284a35b1e4e 100644
--- a/spec/supabase_js_v2_legacy.yml
+++ b/spec/supabase_js_v2_legacy.yml
@@ -760,7 +760,7 @@ pages:
notes: |
- Requires an Authorization header.
- Invoke params generally match the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) spec.
- - When you pass in a body to your function, we automatically attach the Content-Type header for `Blob`, `ArrayBuffer`, `File`, `FormData` and `String`. If it doesn't match any of these types we assume the payload is `json`, serialise it and attach the `Content-Type` header as application/json. You can override this behaviour by passing in a Content-Type header of your own.
+ - When you pass in a body to your function, we automatically attach the Content-Type header for `Blob`, `ArrayBuffer`, `File`, `FormData` and `String`. If it doesn't match any of these types we assume the payload is `json`, serialise it and attach the `Content-Type` header as `application/json`. You can override this behaviour by passing in a `Content-Type` header of your own.
- Responses are automatically parsed as `json`, `blob` and `form-data` depending on the `Content-Type` header sent by your function. Responses are parsed as `text` by default.
examples:
- name: Basic invocation.
@@ -982,25 +982,6 @@ pages:
{ name: 'Rohan', country_id: 555 },
])
```
- - name: Upsert
- description: |
- For upsert, if set to true, primary key columns would need to be included
- in the data parameter in order for an update to properly happen. Also, primary keys
- used must be natural, not surrogate. There are however,
- [workarounds](https://github.com/PostgREST/postgrest/issues/1118)
- for surrogate primary keys.
- js: |
- ```js
- const { data, error } = await supabase
- .from('cities')
- .insert(
- [
- { name: 'The Shire', country_id: 554 },
- { name: 'Rohan', country_id: 555 },
- { name: 'City by the Bay', country_id:840}
- ],
- { upsert: true })
- ```
update():
title: 'Modify data: update()'