Пример #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}.");
     }
 }
Пример #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);
     }
 }
Пример #3
0
 public void CompleteValue(
     IFieldValueCompletionContext context,
     Action <IFieldValueCompletionContext> nextHandler)
 {
     if (context.Value == null)
     {
         context.SetResult(null);
     }
     else
     {
         nextHandler?.Invoke(context);
     }
 }
Пример #4
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));
            }
        }