Size for FaunaDB GraphQL nested query

69 Views Asked by At

How do I set the size for a nested query?

For instance, the following will only return max. 50 users for each group.

const query = gql`
  query GetGroups {
      groups(_size: 100){
          data{
              _id
              name
              users(_size: 500){
                  data{
                      _id
                      name
                  }
              }
          }
      }
  }
`

1

There are 1 best solutions below

0
ptpaterson On

It looks like you wrote your query correctly. You will get a GraphQL error if you provide the _size argument where it is not allowed.

If there are only 50 results showing up when providing a size greater than 50, then there most likely exactly 50 matches.

The GraphQL query you shared will be compiled to FQL that works roughly like the following, and return the result of paginating the nested relationship with the size that you provide.

Let(
  v0: Paginate(Match(Index("groups")), { size: 100 }),
  {
    groups: {
      data: Map(
        Var("v0"),
        Lambda(
          "ref",
          Let(
            {
              v1: Paginate(
                Match(Index("group_users_by_group"), Var("ref")),
                { size: 500 }
              )
            },
            {
              users: Map(Var("v1"), /* ... select fields for users */),
              /* ... select other fields for group */
            }
          )
        )
      )
    }
  }
)

If you are still concerned that there is an issue, please contact Fauna support at support.fauna.com or by emailing [email protected], using the email you used to sign up. Then we can take a closer look at your account.