public Type GetSerializationType(IType type) { if (type is null) { throw new ArgumentNullException(nameof(type)); } INamedType namedType = type.NamedType(); if (!namedType.IsLeafType()) { throw new ArgumentException("Only leaf types are allowed.", nameof(type)); } if (namedType.IsEnumType()) { return(typeof(string)); } if (!_leafTypes.TryGetValue(namedType.Name, out LeafTypeInfo? typeInfo)) { throw new NotSupportedException( $"Leaf type `{namedType.Name}` is not supported."); } return(typeInfo.SerializationType); }
public ITypeInfo GetTypeInfo(IType fieldType, bool readOnly) { INamedType namedType = fieldType.NamedType(); if (namedType.IsLeafType()) { if (!_leafTypes.TryGetValue(namedType.Name, out LeafTypeInfo type)) { throw new NotSupportedException( $"Leaf type `{namedType.Name}` is not supported."); } var typeInfo = new TypeInfo(); typeInfo.Type = fieldType; typeInfo.SchemaTypeName = namedType.Name; typeInfo.SerializationType = type.SerializationType; BuildTypeInfo(type.ClrType, fieldType, readOnly, typeInfo); return(typeInfo); } throw new NotSupportedException( "Type infos are only supported for leaf types."); }
protected override ISyntaxVisitorAction Enter( ObjectValueNode node, IDocumentValidatorContext context) { context.Names.Clear(); for (var i = 0; i < node.Fields.Count; i++) { ObjectFieldNode field = node.Fields[i]; if (!context.Names.Add(field.Name.Value)) { context.Errors.Add(context.InputFieldAmbiguous(field)); } } INamedType namedType = context.Types.Peek().NamedType(); if (namedType.IsLeafType()) { return(Enter((IValueNode)node, context)); } if (namedType is InputObjectType inputObjectType) { if (context.Names.Count >= inputObjectType.Fields.Count) { return(Continue); } for (var i = 0; i < inputObjectType.Fields.Count; i++) { IInputField field = inputObjectType.Fields[i]; if (field.Type.IsNonNullType() && field.DefaultValue.IsNull() && context.Names.Add(field.Name)) { context.Errors.Add( context.FieldIsRequiredButNull(node, field.Name)); } } } else { context.UnexpectedErrorsDetected = true; } return(Continue); }