示例#1
0
        public ValueTask InvokeAsync(IMiddlewareContext context)
        {
            if (context.Result is SerializedData s)
            {
                context.Result = s.Data is IReadOnlyDictionary <string, object> d
                    ? d
                    : DictionaryDeserializer.DeserializeResult(
                    context.Selection.Type,
                    s.Data,
                    context.Service <InputParser>(),
                    context.Path);
            }
            else if (context.Result is null &&
                     !context.Selection.Field.Directives.Contains(DirectiveNames.Computed) &&
                     context.Parent <object>() is IReadOnlyDictionary <string, object> dict)
            {
                string responseName = context.Selection.SyntaxNode.Alias == null
                    ? context.Selection.SyntaxNode.Name.Value
                    : context.Selection.SyntaxNode.Alias.Value;

                dict.TryGetValue(responseName, out var obj);
                context.Result = DictionaryDeserializer.DeserializeResult(
                    context.Selection.Type,
                    obj,
                    context.Service <InputParser>(),
                    context.Path);
            }

            return(_next.Invoke(context));
        }
    public ValueTask InvokeAsync(IMiddlewareContext context)
    {
        var parent = context.Parent <object?>();

        if (parent == ErrorMiddleware.ErrorObject || parent is null)
        {
            context.Result = null;
            return(default);
示例#3
0
        public Task InvokeAsync(IMiddlewareContext context)
        {
            if (context.Result is null &&
                context.Parent <object>() is IDictionary <string, object> dict)
            {
                string responseName = context.FieldSelection.Alias == null
                    ? context.FieldSelection.Name.Value
                    : context.FieldSelection.Alias.Value;

                if (dict.TryGetValue(responseName, out object obj) &&
                    context.Field.Type.IsLeafType() &&
                    context.Field.Type.NamedType() is ISerializableType t &&
                    t.TryDeserialize(obj, out object value))
                {
                    context.Result = value;
                }
示例#4
0
        public ValueTask InvokeAsync(IMiddlewareContext context)
        {
            if (context.Result is SerializedData s)
            {
                context.Result = s.Data is IDictionary <string, object> d
                    ? d
                    : DictionaryDeserializer.DeserializeResult(context.Field.Type, s.Data);
            }
            else if (context.Result is null &&
                     !context.Field.Directives.Contains(DirectiveNames.Computed) &&
                     context.Parent <object>() is IDictionary <string, object> dict)
            {
                string responseName = context.FieldSelection.Alias == null
                    ? context.FieldSelection.Name.Value
                    : context.FieldSelection.Alias.Value;

                dict.TryGetValue(responseName, out object?obj);
                context.Result = DictionaryDeserializer.DeserializeResult(context.Field.Type, obj);
            }

            return(_next.Invoke(context));
        }