예제 #1
0
        /// <summary>
        /// Generates the execution result, a list of individual results for each resolver tracked.
        /// </summary>
        /// <returns>IDictionary&lt;System.String, System.Object&gt;.</returns>
        private IResponseFieldSet GenerateExecutionResult()
        {
            // apollo tracing does not specifiy providing startOffset and duration keys for the execution
            // phase, just output the resolvers array
            var list = new ResponseList();

            foreach (var timeEntry in _resolverEntries.OrderBy(x => x.Value.StartOffsetTicks))
            {
                var resolverEntry = new ResponseFieldSet();
                resolverEntry.Add("path", new ResponseList(timeEntry
                                                           .Key
                                                           .Request
                                                           .Origin
                                                           .Path
                                                           .ToArray()
                                                           .Select(x => new ResponseSingleValue(x))));

                var parentType = _schema.KnownTypes.FindGraphType(timeEntry.Key.Request?.DataSource?.Value);
                if (parentType != null)
                {
                    resolverEntry.AddSingleValue("parentType", parentType.Name);
                }

                resolverEntry.AddSingleValue("fieldName", timeEntry.Key.Request.Field.Name);
                resolverEntry.AddSingleValue("returnType", timeEntry.Key.Request.Field.TypeExpression.ToString());
                resolverEntry.AddSingleValue("startOffset", timeEntry.Value.StartOffsetNanoseconds);
                resolverEntry.AddSingleValue("duration", timeEntry.Value.DurationNanoSeconds);
                list.Add(resolverEntry);
            }

            var dictionary = new ResponseFieldSet();

            dictionary.Add("resolvers", list);
            return(dictionary);
        }
예제 #2
0
        /// <summary>
        /// Formats the output of the metrics into a set of nested key/value pairs that can be written to a graph
        /// ql data response. The keys returned will be written directly to the "extensions" section of the graphql response.
        /// It is recommended to return a single toplevel key containing the entirety of your metrics data.
        /// </summary>
        /// <returns>KeyValuePair&lt;System.String, System.Object&gt;.</returns>
        public virtual IResponseFieldSet GenerateResult()
        {
            var results = new ResponseFieldSet();

            results.AddSingleValue("version", VERSION);

            // the apollo tracing specification says the date MUST be in RFC3339 format
            // do not leave the formatting up to the serializer.
            results.AddSingleValue("startTime", this.StartDate);
            results.AddSingleValue("endTime", this.StartDate.AddTicks(this.TotalTicks));
            results.AddSingleValue("duration", this.TotalTicks);

            if (_phaseEntries.TryGetValue(ApolloExecutionPhase.PARSING, out var entry))
            {
                results.Add("parsing", this.GeneratePhaseResult(entry));
            }
            if (_phaseEntries.TryGetValue(ApolloExecutionPhase.VALIDATION, out entry))
            {
                results.Add("validation", this.GeneratePhaseResult(entry));
            }

            results.Add("execution", this.GenerateExecutionResult());

            var finalResult = new ResponseFieldSet();

            finalResult.Add("tracing", results);
            return(finalResult);
        }
예제 #3
0
        /// <summary>
        /// Generates the phase metrics result for inclusion in the output json.
        /// </summary>
        /// <param name="entry">The entry.</param>
        /// <returns>System.Object.</returns>
        private IResponseItem GeneratePhaseResult(ApolloMetricsEntry entry)
        {
            var dictionary = new ResponseFieldSet();

            dictionary.AddSingleValue("startOffset", entry.StartOffsetNanoseconds);
            dictionary.AddSingleValue("duration", entry.DurationNanoSeconds);
            return(dictionary);
        }