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}.");
     }
 }
示例#2
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);
     }
 }
 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.");
     }
 }
示例#4
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);
     }
 }
示例#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);
        }
示例#6
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);
     }
 }
示例#7
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);
     }
 }