# @compass/api

This package provides functionalities to interact with the Compass API using GraphQL queries and mutations.

### Usage

```javascript
import api from "@compass/api";
```

### API Reference

#### `api.query(document: string, variables?: Record<string, any>)`

Sends a GraphQL query to the Compass API.

* `document` (required, string): The GraphQL document to send.
* `variables` (optional, Record\<string, any>): The variables to send with the query.

Returns a Promise that resolves with the result of the query.

#### `api.mutate(document: string, variables?: Record<string, any>)`

Sends a GraphQL mutation to the Compass API.

* `document` (required, string): The GraphQL document to send.
* `variables` (optional, Record\<string, any>): The variables to send with the mutation.

Returns a Promise that resolves with the result of the mutation.

### Examples

To send a GraphQL query:

```javascript
import api from "@compass/api";

export default async function() {
    const document = `
      query($id: String!) {
        collection(where: { id: $id }) {
          id
          name
        }
      }
    `;

    const variables = {
      id: '1'
    };

    const {data} = await api.query(document, variables);
    log(data);

    return {
        user: data.user,
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.compass.art/automations/custom-actions/compass-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
