private static void HandleFieldValue(
     HashSet <object> processed,
     Dictionary <string, IValueNode> fieldValues,
     InputField field,
     IInputType fieldType,
     object fieldValue)
 {
     if (fieldValue == null)
     {
         fieldValues[field.Name] = NullValueNode.Default;
     }
     else if (fieldType.IsNonNullType())
     {
         HandleFieldValue(processed, fieldValues, field,
                          (IInputType)fieldType.InnerType(), fieldValue);
     }
     else if (fieldType.IsListType())
     {
         fieldValues[field.Name] = ParseList(
             processed, fieldType, fieldValue);
     }
     else if (fieldType.IsScalarType() || fieldType.IsEnumType())
     {
         fieldValues[field.Name] = ParseScalar(
             fieldType, fieldValue);
     }
     else if (fieldType.IsInputObjectType() &&
              !processed.Contains(fieldValue))
     {
         fieldValues[field.Name] = ParseObject(
             processed, (InputObjectType)fieldType, fieldValue);
     }
 }
 private static IValueNode ParseValue(
     HashSet <object> processed,
     IInputType inputType,
     object obj)
 {
     if (inputType.IsNonNullType())
     {
         return(ParseValue(processed,
                           (IInputType)inputType.InnerType(),
                           obj));
     }
     else if (inputType.IsListType())
     {
         return(ParseList(processed, inputType, obj));
     }
     else if (inputType.IsScalarType() || inputType.IsEnumType())
     {
         return(ParseScalar(inputType, obj));
     }
     else if (inputType.IsInputObjectType() &&
              !processed.Contains(obj))
     {
         return(ParseObject(processed, (InputObjectType)inputType, obj));
     }
     else
     {
         return(NullValueNode.Default);
     }
 }
Esempio n. 3
0
        private IValueNode RebuildScalarValue(IInputType type, IValueNode value)
        {
            if (type.IsEnumType() && value is StringValueNode s)
            {
                return(new EnumValueNode(s.Value));
            }

            return(value);
        }
Esempio n. 4
0
        private bool ValueNeedsCleanUp(IInputType type, IValueNode value)
        {
            if (type.IsEnumType() && value is StringValueNode)
            {
                return(true);
            }

            if (type.IsInputObjectType() &&
                type.NamedType() is InputObjectType iot &&
                value is ObjectValueNode ov)
            {
                return(ObjectNeedsCleanUp(iot, ov));
            }

            if (type.IsListType() && value is ListValueNode listValue)
            {
                return(ListNeedsCleanUp(type.ListType(), listValue));
            }

            return(false);
        }
Esempio n. 5
0
        public static object ParseLiteral(
            IInputType sourceType,
            Type targetType,
            IValueNode literal)
        {
            if (sourceType.IsScalarType() || sourceType.IsEnumType())
            {
                return(ParseScalarType(sourceType, targetType, literal));
            }
            else if (sourceType.IsListType())
            {
                return(ParseListType(sourceType, targetType, literal));
            }
            else if (sourceType.IsInputObjectType() &&
                     sourceType.NamedType() is InputObjectType iot)
            {
                return(ParseObjectType(iot, targetType, literal));
            }

            throw new NotSupportedException(
                      "The serializer does not support the specified source type.");
        }
Esempio n. 6
0
        private IValueNode RebuildValue(IInputType type, IValueNode value)
        {
            if (type.IsEnumType() || type.IsScalarType())
            {
                return(RebuildScalarValue(type, value));
            }

            if (type.IsListType() &&
                type.ListType() is ListType lt &&
                value is ListValueNode lv)
            {
                return(RebuildListValue(lt, lv));
            }

            if (type.IsInputObjectType() &&
                type.NamedType() is InputObjectType iot &&
                value is ObjectValueNode ov)
            {
                return(RebuildObjectValue(iot, ov));
            }

            return(value);
        }