From d1541d73bebb4a47725ed9c02e82cfeb1521f99c Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 5 Feb 2018 14:25:51 -0700 Subject: [PATCH] Add support for query batching --- src/Tracing.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Tracing.php b/src/Tracing.php index 1d513f6..34cba2d 100755 --- a/src/Tracing.php +++ b/src/Tracing.php @@ -253,6 +253,8 @@ public static function get_trace() { ] ]; + + /** * Filer and return the trace data * @param array $trace An array of Trace data @@ -293,11 +295,17 @@ public static function add_tracing_to_response_extensions( $response, $schema, $ */ if ( is_array( $response ) ) { foreach ( $response as $key => $res ) { + /** + * Only include the trace data once per request + */ + if ( 0 !== $key ) { + return false; + } if ( true === self::include_tracing_in_response( $res, $schema, $operation_name, $request, $variables ) ) { if ( is_object( $res ) ) { - $res->extensions['tracing'] = self::get_trace(); + $res->extensions['tracing'] = self::get_trace( $key ); } else if ( is_array( $res ) ) { - $res['extensions']['tracing'] = self::get_trace(); + $res['extensions']['tracing'] = self::get_trace( $key ); } } $response[ $key ] = $res; @@ -329,11 +337,17 @@ public static function add_tracked_queries_to_response_extensions( $response, $s if ( is_array( $response ) ) { foreach( $response as $key => $res ) { + /** + * Only include the trace data once per request + */ + if ( 0 !== $key ) { + return false; + } if ( true === self::include_tracing_in_response( $res, $schema, $operation_name, $request, $variables ) ) { if ( is_object( $res ) ) { - $res->extensions['queryLog'] = self::get_trace(); + $res->extensions['queryLog'] = QueryTrace::get_trace( $key ); } else if ( is_array( $res ) ) { - $res['extensions']['queryLog'] = self::get_trace(); + $res['extensions']['queryLog'] = QueryTrace::get_trace( $key ); } } $response[ $key ] = $res;