@compass/api

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

Usage

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:

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,
    }
}

Last updated