Search code examples
graphqlaws-amplifyaws-appsyncampl

AWS Appsync - setting limit on rows returned from a list query


I want to increase the number of rows returned greater than the default 10. Using the limit parameter does not seem to work.

I have tried passing the limit in several different ways but I always receive only the default 10 rows returned. There should be 12 rows returned which match the filter criteria.

  const filter = {
    or: [
      { firstname: { contains: searchValue } },
      { lastname: { contains: searchValue } },
      { emailaddress: { contains: searchValue } },
      { phone: { contains: searchValue } }
    ]

  };

  const limit = {limit: 50};
  // const limit = 50; // this does not work either

  const result = await API.graphql(
    graphqlOperation(listProviders, {filter}, {limit})
  );

I expect to receive true number of rows which match the filter criteria. Only receive 10 rows back. What am I doing incorrectly?


Solution

  • You were close.

    const result = await API.graphql(
      graphqlOperation(listProviders, {filter}, {limit})
    );
    

    is the wrong syntax. graphqlOperation only takes two arguments: the query and some options. You want to put both keys onto that object.

    const limit = 50;
    const result = await API.graphql(
      graphqlOperation(listProviders, {filter, limit})
    );