graphql-php icon indicating copy to clipboard operation
graphql-php copied to clipboard

Support Apollo Tracing

Open jsaur opened this issue 6 years ago • 2 comments

It would be great to be able to leverage Apollo Engine for performance tracing (https://www.apollographql.com/docs/engine/performance.html). I believe in order to do that we would need to implement an apollo-tracing extension in PHP (https://github.com/apollographql/apollo-tracing).

jsaur avatar Jun 19 '18 17:06 jsaur

Hey, we discussed this feature couple times. Please check #200 and #94 for reference.

In short, we discussed two ways how to do this at the library level:

  1. Add a mechanism for logging and metadata collection (we'll do this after the reference implementation, see https://github.com/graphql/graphql-js/issues/284)

  2. Loop through all types in a schema and wrap all field resolvers of all types with apollo-metrics closure. Apollo JS server does this. The problem with this approach in PHP is that schema is created on each request (vs once in nodejs), so there is a huge overhead when doing so.

  3. Current workaround: wrap all resolvers in the userland code when defining a type.

But we've got type loading mechanism since then and I think we can do something else now: we can wrap type loader with our own closure which will, in turn, wrap all field resolvers of a type being loaded.

So any schema using type loading can benefit from it. It will be still not ideal in terms of performance (still have to loop through all fields of all types loaded during a query), but it will be way more performant than full schema scan.

PRs are welcome! I guess we can just write a simple function somewhere under GraphQL\Utils for such a wrapper.

vladar avatar Jun 23 '18 05:06 vladar

This feature is implemented in Lighthouse - see https://github.com/nuwave/lighthouse/tree/master/src/Tracing.

spawnia avatar Jun 09 '22 13:06 spawnia