🎆Multiple Queries Execution

Learn how you can do multiple queries execution using Airstack GraphQL API to fetch data more efficiently in a single request.

In GraphQL, you are able to call multiple queries in a single request.

As Airstack is a GraphQL API, it inherits this feature that enables you to call multiple API in one request:

Try Demo

Code

query MyQuery {
  SocialFollowers( # 1st query fetching social followers
    input: {filter: {identity: {_in: ["0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "vitalik.eth", "lens/@vitalik", "fc_fname:vitalik"]}}, blockchain: ALL, limit: 200, order: {followerSince: DESC}}
  ) {
    Follower {
      followerAddress {
        addresses
        domains {
          isPrimary
          name
        }
        socials {
          dappName
          profileName
        }
        xmtp {
          isXMTPEnabled
        }
      }
    }
  }
  SocialFollowings( # 2nd query fetching social followings
    input: {filter: {identity: {_in: ["0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "vitalik.eth", "lens/@vitalik", "fc_fname:vitalik"]}}, blockchain: ALL, limit: 200, order: {followingSince: DESC}}
  ) {
    Following {
      followingAddress {
        addresses
        domains {
          isPrimary
          name
        }
        socials {
          dappName
          profileName
        }
        xmtp {
          isXMTPEnabled
        }
      }
    }
  }
}

This allow you to not only fetch data that you need more efficiently, but also allow you to do the same query with different inputs when the _in operator is not available for the API input.

This is particularly useful for building cross-chain queries:

Try Demo

Code

query ERC20OwnedByLensProfiles {
  Ethereum: TokenBalances( # first query fetch Ethereum ERC20 balance
    input: {
      filter: {
        owner: {
          _in: [
            "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
            "vitalik.eth"
            "lens/@vitalik"
            "fc_fname:vitalik"
          ]
        }
        tokenType: { _eq: ERC20 }
      }
      blockchain: ethereum
      limit: 50
    }
  ) {
    TokenBalance {
      owner {
        addresses
        domains {
          name
          isPrimary
        }
        socials {
          profileName
          profileTokenId
          profileTokenIdHex
          userAssociatedAddresses
        }
        xmtp {
          isXMTPEnabled
        }
      }
      amount
      tokenAddress
      token {
        name
        symbol
      }
    }
    pageInfo {
      nextCursor
      prevCursor
    }
  }
  Base: TokenBalances( # third query fetch Base ERC20 balance
    input: {
      filter: {
        owner: {
          _in: [
            "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
            "vitalik.eth"
            "lens/@vitalik"
            "fc_fname:vitalik"
          ]
        }
        tokenType: { _eq: ERC20 }
      }
      blockchain: base
      limit: 50
    }
  ) {
    TokenBalance {
      owner {
        addresses
        domains {
          name
          isPrimary
        }
        socials {
          profileName
          profileTokenId
          profileTokenIdHex
          userAssociatedAddresses
        }
        xmtp {
          isXMTPEnabled
        }
      }
      amount
      tokenAddress
      token {
        name
        symbol
      }
    }
    pageInfo {
      nextCursor
      prevCursor
    }
  }
}

Developer Support

If you have any questions or need help regarding adding variables into your Airstack query, please join our Airstack's Telegram group.

More Resources

Last updated

Was this helpful?

Change request #946: