graphql-ruby
graphql-ruby copied to clipboard
Provide an API for explicitly ordering Traces
When adding Traces to a schema, they can be order-dependent. (OperationStore is a key example: it loads the query from the database based on Operation ID, so it has to be executed before any traces that need a query string.) Technically, you can do this by adding plugins in reverse order that you want them to be run (the last plugin is run first 😖 ), but it'd be better to add an API for building a Trace class with an explicit order.
This would also be an opportunity for building different trace modes. For example, you might have a default mode with minimal tracing but a profiling-enabled mode with more tracing. That would allow you to reduce the overhead in the default case. See for example: https://github.com/Shopify/graphql-metrics/blob/0889d54154ea5ff6333feea1c7eae5fc3aa3c235/lib/graphql/metrics/trace.rb#L19
The groundwork for this was laid in trace_mode, etc, in #4437
As it is, trace modes are implicitly ordered by the fact that they are included into the underlying Trace class. Using normal Ruby inheritance rules, the last one included (which is the last one use....d) is the first one called. That trace module's super call passes control to the module use ...d before it. I don't have plans to modify this arrangement now, but I'm definitely open to improving it somehow.