0

I'm experimenting graphql with php using lighthouse-php package. Fetching 8000 records from a table with RESTful implementation takes 1.7s to complete the request. Whereas with grapql implementation takes 4.99s to complete the request. Why graphql is slower than REST, is there any possible ways that would increase the performance of graphql.

REST Request

GraphQL Request

Ahmed
  • 71
  • 1
  • 8

1 Answers1

1

In that scenario, a GraphQL server will always be slower. It is doing extra work to ensure the data you are sending actually lines up with the schema. It will shine in other cases, where you save extra roundtrips to the server by being able to fetch all information in one go.

That said, here are a few suggestions on how you can improve performance:

  • Read the Lighthouse docs about performance. Schema caching and server settings can make a big difference.
  • Don't fetch all the data at once. Usually pagination is used to slice up large lists.
spawnia
  • 879
  • 6
  • 13