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