> ## 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.

# Querying Attio data

> How to query Attio data with GraphQL

The App SDK provides a GraphQL API for querying data within Attio. You can use this API to retrieve Attio's standard and custom records, information about the current user, and other relevant data.

## How to use GraphQL in your app

Data can be queried using GraphQL by following these steps.

1. Create a new `.graphql` file within your application and include the GraphQL query you want to run.
2. Import the query into your app.
3. Run the query using the `runQuery` function or the `useQuery` hook.

## Exploring the GraphQL schema

To inspect the App SDK’s GraphQL schema, run `npm run dev` and press `o`.
This opens a local [GraphiQL instance](https://github.com/graphql/graphiql/tree/main/packages/graphiql#graphiql) in read-only mode, where you can browse available types and operations.

<Note>Query execution against workspace data is not yet supported in the playground.</Note>

## Type generation

Running `npm run dev` will watch for updates to `.graphql` files and automatically generate TypeScript types for them. These types will be used to type the `runQuery` and `useQuery` functions with responses that match your query.

## Making requests directly to the Attio REST API

The App SDK GraphQL API is read-only and client-side only. If you would like to read or write Attio data from server-side code, you can use the [Attio REST API](/rest-api/overview) with [`ATTIO_API_TOKEN`](../server/attio-api-token)
from within your [server functions](../server/server-functions)

## Example: Get a person's contact details

First, create a new `.graphql` file within your application and include the following GraphQL query:

```graphql get-person-contact-details.graphql theme={"system"}
query getPersonContactDetails($recordId: String!) {
  person(id: $recordId) {
    name {
      full_name
    }
    email_addresses
    phone_numbers
    company {
      name
    }
  }
}
```

This query retrieves person's full name, email addresses, phone numbers, and associated company name.

After defining the query, you can import and run it within your app.

```typescript theme={"system"}
import type {App} from "attio"
import {showToast, runQuery} from "attio/client"
import getPersonContactDetails from "./get-person-contact-details.graphql"

export const addToSequenceAction: App.Record.Action = {
  id: "add-to-sequence",
  label: "Add to Sequence",
  // Here, we are restricting the action to person records only
  objects: "people",
  onTrigger: async ({recordId}) => {
    const {person} = await runQuery(getPersonContactDetails, {recordId})

    if (!person) {
      showToast({
        variant: "error",
        title: "Person not found",
      })
      return
    }

    // Process the retrieved contact details
  },
}
```

<Info>The record action above must be included in [`app.ts`](../entry-points/app-ts)</Info>

<Tip>
  The App SDK includes [useQuery](../graphql/use-query) hook for querying within React components.
</Tip>

## Example: Get a text attributes value on a company record

First, create a new `.graphql` file within your application and include the following GraphQL query.

```graphql get-text-attribute-value.graphql theme={"system"}
query getTextAttributeValue($recordId: String!, $slug: String!) {
  company(id: $recordId) {
    attribute(slug: $slug) {
      __typename
      ... on TextValue {
        value
      }
    }
  }
}
```

After defining the query, you can import and run it within your app, be sure to pass the slug of the attribute you'd like to access.

<Tip>
  You can find the slug of an attribute in: **Settings** > **Data** > **Objects** > **Attributes** >
  (three dots menu) > **Copy slug**.
</Tip>

```typescript theme={"system"}
import type {App} from "attio"
import {showToast, runQuery} from "attio/client"
import getTextAttributeValue from "./get-text-attribute-value.graphql"

export const getStockPriceAction: App.Record.Action = {
  id: "get-stock-price",
  label: "Get Stock Price",
  // Here, we are restricting the action to company records only
  objects: "companies",
  onTrigger: async ({recordId}) => {
    const values = await runQuery(getTextAttributeValue, {recordId, slug: "ticker"})
    const ticker = (values.company?.attribute as {value: string}).value

    if (!ticker) {
      showToast({
        variant: "error",
        title: "Ticker not found",
      })
      return
    }

    // Process the retrieved ticker details and fetch stock price
  },
}
```
