public void CompleteValue(
            IFieldValueCompletionContext completionContext,
            Action <IFieldValueCompletionContext> nextHandler)
        {
            if (completionContext.Type.IsListType())
            {
                IType elementType      = completionContext.Type.ElementType();
                bool  isNonNullElement = elementType.IsNonNullType();
                elementType = elementType.InnerType();

                Action <object, int, List <object> > completeElement =
                    (element, index, list) =>
                {
                    nextHandler?.Invoke(completionContext.AsElementValueContext(
                                            completionContext.Path.Append(index), elementType,
                                            element, item => list.Add(item)));
                };

                CompleteList(completionContext, completeElement, isNonNullElement);
            }
            else
            {
                nextHandler?.Invoke(completionContext);
            }
        }
Пример #2
0
 public void CompleteValue(
     IFieldValueCompletionContext completionContext,
     Action <IFieldValueCompletionContext> nextHandler)
 {
     if (completionContext.Type.IsObjectType() ||
         completionContext.Type.IsInterfaceType() ||
         completionContext.Type.IsUnionType())
     {
         ObjectType objectType = ResolveObjectType(
             completionContext.ResolverContext, completionContext.Type, completionContext.Value);
         if (objectType == null)
         {
             completionContext.ReportError(new FieldError(
                                               "Could not resolve the schema type from " +
                                               $"`{completionContext.Value.GetType().GetTypeName()}`.",
                                               completionContext.Selection.Selection));
             return;
         }
         CompleteObjectValue(completionContext, objectType);
     }
     else
     {
         nextHandler?.Invoke(completionContext);
     }
 }
 private void CompleteList(
     IFieldValueCompletionContext completionContext,
     Action <object, int, List <object> > completeElement,
     bool isNonNullElement)
 {
     if (completionContext.Value is IEnumerable enumerable)
     {
         int i    = 0;
         var list = new List <object>();
         foreach (object element in enumerable)
         {
             if (isNonNullElement && element == null)
             {
                 completionContext.ReportError(
                     "The list does not allow null elements");
                 return;
             }
             completeElement(element, i++, list);
         }
         completionContext.IntegrateResult(list);
     }
     else
     {
         completionContext.ReportError(
             "A list value must implement " +
             $"{typeof(IEnumerable).FullName}.");
     }
 }
Пример #4
0
 public void CompleteValue(
     IFieldValueCompletionContext completionContext,
     Action <IFieldValueCompletionContext> nextHandler)
 {
     if (completionContext.Type.IsScalarType() ||
         completionContext.Type.IsEnumType())
     {
         if (completionContext.Type is ISerializableType serializable)
         {
             try
             {
                 completionContext.IntegrateResult(
                     serializable.Serialize(completionContext.Value));
             }
             catch (ArgumentException ex)
             {
                 completionContext.ReportError(ex.Message);
             }
             catch (Exception)
             {
                 completionContext.ReportError(
                     "Undefined field serialization error.");
             }
         }
         else
         {
             completionContext.ReportError(
                 "Scalar types and enum types must be serializable.");
         }
     }
     else
     {
         nextHandler?.Invoke(completionContext);
     }
 }
Пример #5
0
        private void CompleteList(
            IFieldValueCompletionContext completionContext,
            Action <object, int, List <object> > completeElement,
            bool isNonNullElement,
            IEnumerable enumerable)
        {
            int i    = 0;
            var list = new List <object>();

            foreach (object element in enumerable)
            {
                if (element == null)
                {
                    if (isNonNullElement)
                    {
                        completionContext.ReportError(
                            "The list does not allow null elements");
                        return;
                    }
                    else
                    {
                        i++;
                        list.Add(null);
                    }
                }
                else
                {
                    completeElement(element, i++, list);
                }
            }
            completionContext.IntegrateResult(list);
        }
 private static void SerializeAndCompleteValue(
     IFieldValueCompletionContext completionContext,
     ISerializableType serializable)
 {
     try
     {
         if (TryConvertToScalarValue(
                 completionContext.Converter,
                 completionContext.Type,
                 completionContext.Value,
                 out object value))
         {
             value = serializable.Serialize(value);
             completionContext.IntegrateResult(value);
         }
         else
         {
             completionContext.ReportError(
                 "The internal resolver value could not be " +
                 "converted to a valid value of " +
                 $"`{completionContext.Type.TypeName()}`.");
         }
     }
     catch (ScalarSerializationException ex)
     {
         completionContext.ReportError(ex.Message);
     }
     catch (Exception)
     {
         completionContext.ReportError(
             "Undefined field serialization error.");
     }
 }
Пример #7
0
        private void CompleteObjectValue(
            IFieldValueCompletionContext context,
            ObjectType objectType)
        {
            var objectResult = new OrderedDictionary();

            context.IntegrateResult(objectResult);
            context.EnqueueForProcessing(objectType, objectResult);
        }
 public void CompleteValue(
     IFieldValueCompletionContext completionContext,
     Action <IFieldValueCompletionContext> nextHandler)
 {
     if (completionContext.Type.IsNonNullType())
     {
         nextHandler?.Invoke(completionContext.AsNonNullValueContext());
     }
     else
     {
         nextHandler?.Invoke(completionContext);
     }
 }
 public void CompleteValue(
     IFieldValueCompletionContext completionContext,
     Action <IFieldValueCompletionContext> nextHandler)
 {
     if (completionContext.Value == null)
     {
         completionContext.IntegrateResult(null);
     }
     else
     {
         nextHandler?.Invoke(completionContext);
     }
 }
Пример #10
0
 public void CompleteValue(
     IFieldValueCompletionContext completionContext,
     Action <IFieldValueCompletionContext> nextHandler)
 {
     if (completionContext.Value is IQueryError error)
     {
         completionContext.ReportError(error);
     }
     else if (completionContext.Value is IEnumerable <IQueryError> errors)
     {
         completionContext.ReportError(errors);
     }
     else
     {
         nextHandler?.Invoke(completionContext);
     }
 }
Пример #11
0
        private void CompleteObjectValue(
            IFieldValueCompletionContext context,
            Action <IFieldValueCompletionContext> nextHandler,
            ObjectType objectType)
        {
            OrderedDictionary objectResult = new OrderedDictionary();

            context.SetResult(objectResult);

            IReadOnlyCollection <FieldSelection> fields = context.ExecutionContext
                                                          .CollectFields(objectType, context.SelectionSet);

            foreach (FieldSelection field in fields)
            {
                context.ExecutionContext.NextBatch.Add(new FieldResolverTask(
                                                           context.Source.Push(context.Value), objectType, field,
                                                           context.Path.Append(field.ResponseName), objectResult));
            }
        }
Пример #12
0
 private void CompleteList(
     IFieldValueCompletionContext completionContext,
     Action <object, int, List <object> > completeElement,
     bool isNonNullElement)
 {
     if (completionContext.Value is IEnumerable enumerable)
     {
         CompleteList(
             completionContext,
             completeElement,
             isNonNullElement,
             enumerable);
     }
     else
     {
         completionContext.ReportError(
             "A list value must implement " +
             $"{typeof(IEnumerable).FullName}.");
     }
 }
 public void CompleteValue(
     IFieldValueCompletionContext completionContext,
     Action <IFieldValueCompletionContext> nextHandler)
 {
     if (completionContext.Type.IsLeafType())
     {
         if (completionContext.Type is ISerializableType serializable)
         {
             SerializeAndCompleteValue(completionContext, serializable);
         }
         else
         {
             completionContext.ReportError(
                 "Scalar types and enum types must be serializable.");
         }
     }
     else
     {
         nextHandler?.Invoke(completionContext);
     }
 }
Пример #14
0
 public void CompleteValue(IFieldValueCompletionContext context)
 {
     _completeValue(context);
 }