Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.attio.com/llms.txt

Use this file to discover all available pages before exploring further.

import {runQuery} from "attio/client"

Parameters

query
string
required
A GraphQL query string.
If you’re using TypeScript and [default] import this value from a .graphql or .gql file, the variables and return value will be strongly typed.Read more.
variables
Record<string, any>
The named variables your query accepts. If your query has no variables, you needn’t pass any.

Returns

Promise<Record<string, any>>
A Promise to the structured JSON as defined by your query.

Example

To run multiple GraphQL queries in parallel, use runQuery() together with useAsyncCache(). Each call to runQuery() in the cache definition runs in parallel, and the component suspends until all have completed:
import React from "react"
import {runQuery, TextBlock, useAsyncCache} from "attio/client"
import getPersonName from "./get-person-name.graphql"
import getCurrentUser from "./get-current-user.graphql"

export function MeetPerson({recordId}: {recordId: string}) {
  // Will run in parallel and suspend until both queries have returned
  const {values} = useAsyncCache({
    currentUserResult: async () => await runQuery(getCurrentUser),
    personResult: async () => await runQuery(getPersonName, {recordId}),
  })
  const currentUserName: string = values.currentUserResult.currentUser.name
  const personName: string | null | undefined = values.personResult.person?.name?.full_name

  return (
    <TextBlock>
      {personName ?? "Unknown"} would like to meet with {currentUserName}.
    </TextBlock>
  )
}