GraphQL
Query tables, users, teams and files in a single call, asking only for the fields your app uses, with the same permissions as the REST API.
Besides the REST API, the project answers GraphQL at https://cloud.owbase.dev/v1/graphql. One query can combine several reads (rows from a table, the number of users, the files in a bucket) and return only the fields the screen uses. The same permissions and scopes as REST apply: the user’s session in the app, or the API key on the server.
In the console, GraphQL (in the project menu) opens the explorer: the searchable schema, sample queries, the editor with variables and headers, the response and the operation history.
Run a query
Section titled “Run a query”import { Graphql } from '@owbase/web';import { client } from './client';
const graphql = new Graphql(client);
// One row from the "orders" table, with only the fields the screen uses. The user's session permissions apply.const response = await graphql.query({ query: { query: `query Order($table: String!, $row: String!) { tablesDBGetRow(databaseId: "main-store", tableId: $table, rowId: $row) { _id data }}`, variables: { table: 'orders', row: '<ROW_ID>' }, },});console.log(response);import { Graphql } from '@owbase/node';import { client } from './client';
// The key needs the scopes of what the query reads (here, users.read and files.read).const graphql = new Graphql(client);const response = await graphql.query({ query: { query: '{ users: usersList { total } files: storageListFiles(bucketId: "products") { total } }' },});console.log(response);curl -X POST "https://cloud.owbase.dev/v1/graphql" \ -H "Content-Type: application/json" \ -H "X-Owbase-Project: <PROJECT_ID>" \ -H "X-Owbase-Key: $OWBASE_API_KEY" \ -H "x-sdk-graphql: true" \ -d '{"query":"{ usersList { total } }"}'Mutations use graphql.mutation(...) (or POST /v1/graphql/mutation). Field names are the REST methods prefixed with the service (tablesDBListRows, usersList, storageListFiles), and system attributes swap $ for _ (_id, _createdAt). The queries filters go as JSON text, one per list item, as in REST.
What Owbase GraphQL accepts
Section titled “What Owbase GraphQL accepts”| Service | Queries | Mutations |
|---|---|---|
Database (tablesDB, databases), users (users), files (storage) and teams (teams) |
yes | yes |
Account (account), locale (locale), functions and sites |
yes | no |
Introspection (__schema, __type) |
yes | — |
| Messaging, project, domains, migrations and the rest | no | no |
Creating a function, site, deployment or execution is left to REST and the CLI. Subscriptions (subscription) don’t exist: use Realtime. File uploads (multipart) don’t go through GraphQL either: use storage.createFile.
Errors
Section titled “Errors”Status and type |
When |
|---|---|
400 owbase_graphql_syntax |
The document isn’t valid GraphQL. |
400 owbase_graphql_body_unsupported |
A body that isn’t JSON or application/graphql (for example, multipart). |
403 owbase_graphql_field_unavailable |
A query to a field outside the list above. |
403 owbase_graphql_mutation_blocked |
A mutation outside the list above. |
403 owbase_compute_disabled |
A functions or sites mutation. |
403 owbase_graphql_subscription_unsupported |
A subscription operation. |
In the console explorer, people with the Viewer role in the organization can only run queries: mutations are refused. The refusal body also includes errors[], in GraphQL format. See Errors.
History
Section titled “History”The explorer shows the project’s operations (from the app or the console) for the last 30 days: when, type, operation name, root fields, status and duration. Owbase does not store the document, the variables or the response.