forked from nhost/nhost
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sync Fork
committed
Jan 27, 2024
1 parent
fb25e06
commit b50a6e9
Showing
21 changed files
with
181 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
--- | ||
title: Resources | ||
description: description | ||
description: Learn about compute resources | ||
icon: gauge-max | ||
--- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
title: call() | ||
sidebarTitle: call() | ||
--- | ||
|
||
Use `nhost.functions.call` to call (sending a POST request to) a serverless function. Use generic | ||
types to specify the expected response data, request body and error message. | ||
|
||
```ts | ||
await nhost.functions.call('send-welcome-email', { | ||
email: '[email protected]', | ||
name: 'Joe Doe' | ||
}) | ||
``` | ||
|
||
## Parameters | ||
|
||
--- | ||
|
||
**<span className="parameter-name">url</span>** <span className="optional-status">required</span> <code>string</code> | ||
|
||
--- | ||
|
||
**<span className="parameter-name">body</span>** <span className="optional-status">optional</span> <code>null | TBody</code> | ||
|
||
--- | ||
|
||
**<span className="parameter-name">config</span>** <span className="optional-status">optional</span> <code>NhostFunctionCallConfig</code> | ||
|
||
--- | ||
|
||
## Examples | ||
|
||
### Without generic types | ||
|
||
```ts | ||
await nhost.functions.call('send-welcome-email', { | ||
email: '[email protected]', | ||
name: 'Joe Doe' | ||
}) | ||
``` | ||
|
||
### Using generic types | ||
|
||
```ts | ||
type Data = { | ||
message: string | ||
} | ||
|
||
type Body = { | ||
email: string | ||
name: string | ||
} | ||
|
||
type ErrorMessage = { | ||
details: string | ||
} | ||
|
||
// The function will only accept a body of type `Body` | ||
const { res, error } = await nhost.functions.call<Data, Body, ErrorMessage>( | ||
'send-welcome-email', | ||
{ email: '[email protected]', name: 'Joe Doe' } | ||
) | ||
|
||
// Now the response data is typed as `Data` | ||
console.log(res?.data.message) | ||
|
||
// Now the error message is typed as `ErrorMessage` | ||
console.log(error?.message.details) | ||
``` |
31 changes: 31 additions & 0 deletions
31
docs/reference/javascript/functions/create-functions-client.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
title: createFunctionsClient() | ||
sidebarTitle: createFunctionsClient() | ||
--- | ||
|
||
Creates a client for Functions from either a subdomain or a URL | ||
|
||
## Parameters | ||
|
||
--- | ||
|
||
**<span className="parameter-name">params</span>** <span className="optional-status">required</span> [`NhostClientConstructorParams`](/reference/javascript/nhost-js/types/nhost-client-constructor-params) | ||
|
||
| Property | Type | Required | Notes | | ||
| :----------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------ | :------: | :--------------------------------------------------------------------------------------------------------------------------------------- | | ||
| <span className="parameter-name"><span className="light-grey">params.</span>adminSecret</span> | <code>string</code> | | When set, the admin secret is sent as a header, `x-hasura-admin-secret`, for all requests to GraphQL, Storage, and Serverless Functions. | | ||
| <span className="parameter-name"><span className="light-grey">params.</span>functionsUrl</span> | <code>string</code> | | | | ||
| <span className="parameter-name"><span className="light-grey">params.</span>storageUrl</span> | <code>string</code> | | | | ||
| <span className="parameter-name"><span className="light-grey">params.</span>graphqlUrl</span> | <code>string</code> | | | | ||
| <span className="parameter-name"><span className="light-grey">params.</span>authUrl</span> | <code>string</code> | | | | ||
| <span className="parameter-name"><span className="light-grey">params.</span>region</span> | <code>string</code> | | Project region (e.g. `eu-central-1`) Project region is not required during local development (when `subdomain` is `localhost`) | | ||
| <span className="parameter-name"><span className="light-grey">params.</span>subdomain</span> | <code>string</code> | | Project subdomain (e.g. `ieingiwnginwnfnegqwvdqwdwq`) Use `localhost` during local development | | ||
| <span className="parameter-name"><span className="light-grey">params.</span>devTools</span> | <code>boolean</code> | | Activate devTools e.g. the ability to connect to the xstate inspector | | ||
| <span className="parameter-name"><span className="light-grey">params.</span>autoSignIn</span> | <code>boolean</code> | | When set to true, will parse the url on startup to check if it contains a refresh token to start the session with | | ||
| <span className="parameter-name"><span className="light-grey">params.</span>autoRefreshToken</span> | <code>boolean</code> | | When set to true, will automatically refresh token before it expires | | ||
| <span className="parameter-name"><span className="light-grey">params.</span>clientStorage</span> | [`ClientStorage`](/reference/javascript/nhost-js/types/client-storage) | | Object where the refresh token will be persisted and read locally. | | ||
| <span className="parameter-name"><span className="light-grey">params.</span>clientStorageType</span> | [`ClientStorageType`](/reference/javascript/nhost-js/types/client-storage-type) | | Define a way to get information about the refresh token and its exipration date. | | ||
| <span className="parameter-name"><span className="light-grey">params.</span>refreshIntervalTime</span> | <code>number</code> | | Time interval until token refreshes, in seconds | | ||
| <span className="parameter-name"><span className="light-grey">params.</span>start</span> | <code>boolean</code> | | | | ||
|
||
--- |
13 changes: 13 additions & 0 deletions
13
docs/reference/javascript/functions/nhost-functions-client.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
title: NhostFunctionsClient | ||
--- | ||
|
||
# `NhostFunctionsClient` | ||
|
||
## Parameters | ||
|
||
--- | ||
|
||
**<span className="parameter-name">params</span>** <span className="optional-status">required</span> <code>NhostFunctionsConstructorParams</code> | ||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
title: setAccessToken() | ||
sidebarTitle: setAccessToken() | ||
--- | ||
|
||
Use `nhost.functions.setAccessToken` to a set an access token to be used in subsequent functions requests. Note that if you're signin in users with `nhost.auth.signIn()` the access token will be set automatically. | ||
|
||
```ts | ||
nhost.functions.setAccessToken('some-access-token') | ||
``` | ||
|
||
## Parameters | ||
|
||
--- | ||
|
||
**<span className="parameter-name">accessToken</span>** <span className="optional-status">required</span> <code>undefined | string</code> | ||
|
||
--- |