Functions
Functions run on the backend and are written in JavaScript (or TypeScript). Theyare automatically available as APIs accessed throughclient libraries. Everything you do in the Convex backendstarts from functions.
There are three types of functions:
- Queries read data from your Convex databaseand are automatically cached and subscribable (realtime, reactive).
- Mutations write data to the database andrun as a transaction.
- Actions can call OpenAI, Stripe, Twilio, or anyother service or API you need to make your app work.
You can also buildHTTP actions when you want tocall your functions from a webhook or a custom client.
Here's an overview of the three different types of Convex functions and whatthey can do:
| Queries | Mutations | Actions | |
|---|---|---|---|
| Database access | Yes | Yes | No |
| Transactional | Yes | Yes | No |
| Cached | Yes | No | No |
| Real-time Updates | Yes | No | No |
| External API Calls (fetch) | No | No | Yes |