Compass Docs
  • Collections
    • ๐Ÿš€Trending
    • ๐ŸŒฑMinting Now
    • ๐Ÿ“ƒCollection Watchlists
    • ๐Ÿ–ผ๏ธToken Window
    • โ†”๏ธCollection Activity
    • ๐Ÿ†Collection Profit Leaderboard
    • ๐ŸŽจCollection Tokens
    • ๐Ÿ‹Collection Top Holders
    • โ›๏ธCollection Mint History
    • ๐Ÿ”Collection Analytics
  • Wallets
    • ๐Ÿš€Getting started with Wallets
    • ๐Ÿ‘›Wallet overview
    • ๐Ÿ”Wallet Activity with Filtering
    • ๐Ÿ™‹Own Wallets
    • ๐ŸฅžFlips
    • ๐Ÿ‘ฅWallet Groups
    • ๐Ÿ”—Related Wallets
  • Pulse
    • ๐Ÿฅ‡Profit leaderboard
    • ๐Ÿ“ˆCompass Pulse
  • Alerts
    • โฐGetting Started with Alerts
  • Automations
    • ๐Ÿš€Getting Started with Automations
    • ๐Ÿ’ฐWallets
    • ๐Ÿ“˜Key Terms in Automations
    • ๐Ÿ”€Inputs/Outputs
    • ๐ŸงชTesting Automations
    • ๐Ÿš€Set Up Your First Listing Alert
    • ๐Ÿ”ซTriggers
      • Token Received
      • Token Sent
      • Token Bought
      • Token Sold
      • Token Minted
      • Webhook
      • Repeat
      • Token Listed
      • Telegram
      • Trigger Advanced Settings
    • ๐Ÿ’ณPricing
    • โšกCustom Actions
      • @compass/http
      • @compass/api
      • @compass/cache
      • @compass/utils
      • @compass/variables
      • @compass/wallet
Powered by GitBook
On this page
  • Usage
  • API Reference
  • Examples
  1. Automations
  2. Custom Actions

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

Previous@compass/httpNext@compass/cache

Last updated 1 year ago

โšก