# Building Queries

We will take the example of the **spl-governance** program and build graphQL queries to fetch data, instead of the usual **getProgramAccounts()** call.

{% hint style="info" %}
Use our [GraphQL demo project](https://github.com/Shyft-to/community-projects/tree/main/graphql-demo) to easily get started and try out these queries in code.
{% endhint %}

<mark style="color:yellow;">**#Get all proposalsV2 accounts**</mark>

```graphql
query MyQuery {
  GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_ProposalV2 {
    abstainVoteWeight
    closedAt
    denyVoteWeight
    descriptionLink
    draftAt
    executingAt
    executionFlags
    governance
    governingTokenMint
    lamports
    maxVoteWeight
    maxVotingTime
    name
    options
    reserved1
    signatoriesCount
    signatoriesSignedOffCount
    signingOffAt
    startVotingAt
    state
    tokenOwnerRecord
    vetoVoteWeight
    voteThreshold
    voteType
    votingAt
    votingAtSlot
    votingCompletedAt
    pubkey
  }
}

```

Note how we have included all the data fields that are available to us, you can cherry pick fields that are useful to you. For example if you only want <mark style="color:yellow;">names</mark> and <mark style="color:yellow;">addresses</mark> of the proposals. The the query becomes like

```graphql
query MyQuery {
  GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_ProposalV2 {
    name
    pubkey
  }
}
```

<figure><img src="/files/16Ef3yZ76JIW5zQ0XBkY" alt=""><figcaption><p>Fetching All Proposals V2 from spl-governance</p></figcaption></figure>

By default the API will return <mark style="color:yellow;">1000 accounts</mark> data in response. You can control how many accounts you need by specifying <mark style="color:yellow;">**limit**</mark>**.** The query becomes like below.

```graphql
query MyQuery {
  GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_ProposalV2(limit: 100) {
    name
    pubkey
  }
}
```

Ideally there would be thousands of accounts in a program, so lets see how can we paginate and get more responses.


---

# 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.shyft.to/solana-indexers/graphql-apis/building-queries.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.
