Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document fetchOptions #206

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions 040-SDK/010-TypeScript/020-configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ const xata = new XataClient({ apiKey: XATA_API_KEY });

In case your runtime does not provide a built-in Fetch API (such as with versions prior to Node 18), you will need to pass a fetch implementation to the `fetch ` constructor parameter of the XataClient in the `xata.ts` / `xata.js `file in your project.

## Passing options to fetch

Some frameworks, like Next.js, support additional fetch options which allow you to configure the caching and revalidating behavior for each fetch request on the server.
kostasb marked this conversation as resolved.
Show resolved Hide resolved

The Xata SDK supports the `fetchOptions` parameter for passing options to fetch.

This parameter can be used to configure cache revalidation at a timed interval:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd make this more clear it's only for Next.js

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add clarifications once we have findings from xataio/client-ts#1311 as it doesn't seem to actually work as documented, maybe there's more steps needed in Next.js.


```ts
const records = xata.db.users.getMany({ pagination: { size: 10 }, fetchOptions: { next: { revalidate: '3060' } } });
```

or, to disable the cache for a fetch request:

```ts
const records = xata.db.users.getMany({ pagination: { size: 10 }, fetchOptions: { cache: 'no-store' } });
```

## Updating the schema

The command `xata codegen` updates the schema for the Xata client. Applying schema changes from the CLI, such as using the command `xata schema edit`, will automatically run codegen to update your client. However, in case schema changes have been applied from the web UI, you should run `xata codegen` to update your existing client with the latest schema.
Loading