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}."); } }
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 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."); } }
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.Value == null) { completionContext.IntegrateResult(null); } else { nextHandler?.Invoke(completionContext); } }