示例#1
0
        private static Trace.Node CreateNodes(IReadOnlyCollection <object> path, Trace.Node node, ApolloTrace.ResolverTrace[] resolvers, ExecutionError[] executionErrors)
        {
            bool isArray = node.Type.StartsWith("[") && node.Type.TrimEnd('!').EndsWith("]");

            if (isArray)
            {
                foreach (int index in resolvers.Where(x => x.Path.Count == path.Count + 2).Select(x => (int)x.Path[x.Path.Count - 2]).Distinct().OrderBy(x => x))
                {
                    var subPath = path.Concat(new object[] { index }).ToList();

                    node.Childs.Add(CreateNodes(subPath,
                                                new Trace.Node
                    {
                        Index      = (uint)index,
                        ParentType = node.Type,
                        Type       = node.Type.TrimStart('[').TrimEnd('!').TrimEnd(']')
                    }, GetSubResolvers(subPath, resolvers), GetSubErrors(subPath, executionErrors)));
                }
            }
            else
            {
                foreach (var resolver in resolvers.Where(x => x.Path.Count == path.Count + 1 && x.Path.Take(path.Count).SequenceEqual(path)))
                {
                    var errors = executionErrors?.Where(x => x.Path.SequenceEqual(resolver.Path)).ToArray();
                    node.Childs.Add(CreateNodes(resolver.Path, CreateNodeForResolver(resolver, errors), GetSubResolvers(resolver.Path, resolvers), GetSubErrors(resolver.Path, executionErrors)));
                }
            }

            return(node);
        }
示例#2
0
        private static Trace.Node CreateNodeForResolver(ApolloTrace.ResolverTrace resolver, ExecutionError[] executionErrors)
        {
            var node = new Trace.Node
            {
                ResponseName = resolver.FieldName,
                Type         = resolver.ReturnType,
                StartTime    = (ulong)resolver.StartOffset,
                EndTime      = (ulong)(resolver.StartOffset + resolver.Duration),
                ParentType   = resolver.ParentType
            };

            if (executionErrors != null)
            {
                foreach (var executionError in executionErrors)
                {
                    node.Errors.Add(CreateTraceError(executionError));
                }
            }

            return(node);
        }