public void ParseLiteral_Polygon_With_Missing_Fields_Throws() { InputObjectType type = CreateInputType(); Assert.Throws <InputObjectSerializationException>(() => type.ParseLiteral( new ObjectValueNode( new ObjectFieldNode("coordinates", polygon), new ObjectFieldNode("missingType", new StringValueNode("ignored"))))); }
public void ParseLiteral_LineString_With_Wrong_Geometry_Type_Throws() { // arrange InputObjectType type = CreateInputType(); Assert.Throws <InputObjectSerializationException>(() => type.ParseLiteral( new ObjectValueNode( new ObjectFieldNode("type", new EnumValueNode(GeoJSONGeometryType.Polygon)), new ObjectFieldNode("coordinates", linestring)))); }
private static Expression CreateInstance( InputObjectType inputType, ConstructorInfo constructor, Expression data, Expression converter) { return(Expression.New( constructor, CreateParameters(inputType, constructor, data, converter))); }
private void VisitInput(InputObjectType type) { VisitDirectives(type); foreach (InputField field in type.Fields) { VisitDirectives(field); Visit((TypeSystemObjectBase)field.Type.NamedType()); } }
public void ParseLiteral_MultiLineString_Is_Not_ObjectType_Throws() { // arrange InputObjectType type = CreateInputType(); // act // assert Assert.Throws <InvalidOperationException>( () => type.ParseLiteral(new ListValueNode())); }
public static List <KeyValuePair <string, InputObjectField> > GetInputFields( this SchemaBuilder builder, InputObjectType inputObjectType) { var fields = new List <KeyValuePair <string, InputObjectField> >(); builder.Connections(connections => fields = connections.GetInputFields(inputObjectType).ToList()); return(fields); }
public SchemaBuilder InputObject( string name, out InputObjectType definition, string?description = null, IEnumerable <DirectiveInstance>?directives = null) { definition = new InputObjectType(name, description, directives); Include(definition); return(this); }
public void ParseLiteral_MultiLineString_Is_Null() { // arrange InputObjectType type = CreateInputType(); // act object?result = type.ParseLiteral(NullValueNode.Default); // assert Assert.Null(result); }
public void ParseLiteral_MultiLineString_With_Empty_Coordinates_Throws() { // arrange InputObjectType type = CreateInputType(); Assert.Throws <InputObjectSerializationException>(() => type.ParseLiteral( new ObjectValueNode( new ObjectFieldNode("type", new EnumValueNode(GeoJSONGeometryType.MultiLineString)), new ObjectFieldNode("coordinates", new ListValueNode())))); }
public InputClassDescriptor( string name, string ns, InputObjectType type, IReadOnlyList <IInputFieldDescriptor> fields) { Name = name ?? throw new ArgumentNullException(nameof(name)); Namespace = ns ?? throw new ArgumentNullException(nameof(ns)); Type = type ?? throw new ArgumentNullException(nameof(type)); Fields = fields ?? throw new ArgumentNullException(nameof(fields)); }
public QueryableSortVisitor( InputObjectType initialType, Type source) : base(initialType) { if (initialType is null) { throw new ArgumentNullException(nameof(initialType)); } Closure = new SortQueryableClosure(source, _parameterName); }
public void ParseLiteral_LineString_Is_Not_ObjectType_Throws() { // arrange var inputParser = new InputParser(new DefaultTypeConverter()); InputObjectType type = CreateInputType(); // act // assert Assert.Throws <SerializationException>( () => inputParser.ParseLiteral(new ListValueNode(), type)); }
/// <summary> /// Initializes a new instance of <see cref="InputObjectTypeModel" /> /// </summary> /// <param name="name">The class name.</param> /// <param name="description">The class description.</param> /// <param name="type">The input object type.</param> /// <param name="fields">The field models of this input type.</param> public InputObjectTypeModel( NameString name, string?description, InputObjectType type, IReadOnlyList <InputFieldModel> fields) { Name = name.EnsureNotEmpty(nameof(name)); Description = description; Type = type ?? throw new ArgumentNullException(nameof(type)); Fields = fields ?? throw new ArgumentNullException(nameof(fields)); }
public static string SelectTypeName(INamedType namedType) { return(namedType switch { ScalarType scalar => SelectScalarTypeName(scalar), ObjectType objectType => SelectObjectTypeName(objectType), EnumType enumType => SelectEnumTypeName(enumType), InputObjectType inputObjectType => SelectInputObjectTypeName(inputObjectType), InterfaceType interfaceType => SelectInterfaceTypeName(interfaceType), UnionType unionType => SelectUnionTypeName(unionType), _ => "object" });
public ConnectionBuilder Remove(InputObjectType inputObject, string fieldName) { if (_inputFields.TryGetValue(inputObject.Name, out var fields)) { if (fields.ContainsKey(fieldName)) { fields.Remove(fieldName); } } return(this); }
private static InputFieldDefinition CreateDefinition( IDescriptorContext context, InputObjectType filterType) { InputFieldDefinition definition = InputFieldDescriptor .New(context, "AND") .CreateDefinition(); definition.Type = new SchemaTypeReference( new ListType(new NonNullType(filterType))); return(definition); }
public static Dictionary <string, object> DeserializeToDictionary( InputObjectType type, IReadOnlyDictionary <string, object> value, ITypeConverter converter) { var dict = new Dictionary <string, object>(); Deserialize(type, value, dict, converter); SetDefaultValues(type, dict, converter); return(dict); }
public void ParseLiteral_MultiPoint_Is_Null() { // arrange var inputParser = new InputParser(new DefaultTypeConverter()); InputObjectType type = CreateInputType(); // act var result = inputParser.ParseLiteral(NullValueNode.Default, type); // assert Assert.Null(result); }
public QueryableSortVisitor( InputObjectType initialType, Type source) { if (initialType is null) { throw new ArgumentNullException(nameof(initialType)); } Types.Push(initialType); _parameter = Expression.Parameter(source); }
public QueryableFilterVisitor( InputObjectType initialType, Type source, ITypeConversion converter) : this( initialType, source, converter, ExpressionOperationHandlers.All, ExpressionFieldHandlers.All) { }
public void ParseLiteral_LineString_Is_Null() { // arrange InputObjectType type = CreateInputType(); var inputParser = new InputParser(new DefaultTypeConverter()); // act object?result = inputParser.ParseLiteral(NullValueNode.Default, type); // assert Assert.Null(result); }
public static object ParseLiteralToDictionary( InputObjectType type, ObjectValueNode value, ITypeConverter converter) { var dict = new Dictionary <string, object>(); Parse(type, value, dict, converter); SetDefaultValues(type, dict, converter); return(dict); }
public void ChangeInputType(HEU_SessionBase session, InputObjectType newType) { if (newType == _inputObjectType) { return; } DisconnectAndDestroyInputs(session); _inputObjectType = newType; _pendingInputObjectType = _inputObjectType; }
private static void SetDefaultValues( InputObjectType type, IDictionary <string, object> dict) { foreach (InputField field in type.Fields) { if (!field.IsOptional && !dict.ContainsKey(field.Name)) { dict[field.Name] = field.Type.ParseLiteral(field.DefaultValue); } } }
private static ObjectValueNode Rewrite( ObjectValueNode node, InputObjectType type, IVariableValueCollection variableValues) { if (node.Fields.Count == 0) { return(node); } if (node.Fields.Count == 1) { ObjectFieldNode value = node.Fields[0]; return(type.Fields.TryGetField(value.Name.Value, out InputField? field) && TryRewriteField(value, field, variableValues, out ObjectFieldNode? rewritten) ? node.WithFields(new[] { rewritten }) : node); } ObjectFieldNode[]? rewrittenItems = null; for (var i = 0; i < node.Fields.Count; i++) { ObjectFieldNode value = node.Fields[i]; if (type.Fields.TryGetField(value.Name.Value, out InputField? field) && TryRewriteField(value, field, variableValues, out ObjectFieldNode? rewritten)) { if (rewrittenItems is null) { rewrittenItems = new ObjectFieldNode[node.Fields.Count]; for (var j = 0; j < node.Fields.Count; j++) { rewrittenItems[j] = node.Fields[j]; } } rewrittenItems[i] = rewritten; } else if (rewrittenItems is not null) { rewrittenItems[i] = node.Fields[i]; } } if (rewrittenItems is not null) { return(node.WithFields(rewrittenItems)); } return(node); }
public ConnectionBuilder InputField( InputObjectType owner, string fieldName, IType to, object defaultValue = null, string description = null, IEnumerable <DirectiveInstance> directives = null) { if (owner == null) { throw new ArgumentNullException(nameof(owner)); } if (fieldName == null) { throw new ArgumentNullException(nameof(fieldName)); } if (to == null) { throw new ArgumentNullException(nameof(to)); } if (!Builder.TryGetType <InputObjectType>(owner.Name, out _)) { throw new SchemaBuilderException(owner.Name, $"Cannot add InputField. Owner type {owner.Name} is not known for {fieldName}."); } var target = to.Unwrap(); if (!Builder.TryGetType <INamedType>(target.Name, out _)) { throw new SchemaBuilderException(owner.Name, $"Cannot add Field '{fieldName} to {owner.Name}'. Target type {target.Name} is not known."); } if (!_inputFields.ContainsKey(owner.Name)) { _inputFields[owner.Name] = new Dictionary <string, InputObjectField>(); } if (_inputFields[owner.Name].ContainsKey(fieldName)) { throw new SchemaBuilderException(owner.Name, $"Cannot add input field '{fieldName}'. Type '{owner.Name}' already has field with same name."); } _inputFields[owner.Name].Add( fieldName, new InputObjectField(to, description, defaultValue, directives)); return(this); }
public void ParseLiteral_MultiLineString_With_Missing_Fields_Throws() { // arrange InputObjectType type = CreateInputType(); // act // assert Assert.Throws <SerializationException>( () => type.ParseLiteral( new ObjectValueNode( new ObjectFieldNode("coordinates", _multiLinestring), new ObjectFieldNode("missingType", new StringValueNode("ignored"))))); }
public bool TryGetInputField(InputObjectType owner, string fieldName, out InputObjectField field) { if (_inputFields.TryGetValue(owner.Name, out var fields)) { if (fields.TryGetValue(fieldName, out field)) { return(true); } } field = null; return(false); }
public void ParseLiteral_Point_With_Wrong_Geometry_Type_Throws() { // arrange InputObjectType type = CreateInputType(); // act // assert Assert.Throws <SerializationException>( () => type.ParseLiteral( new ObjectValueNode( new ObjectFieldNode("type", new EnumValueNode(GeoJsonGeometryType.Polygon)), new ObjectFieldNode("coordinates", _point)))); }
public void ParseLiteral_MultiPoint_With_Empty_Coordinates_Throws() { // arrange InputObjectType type = CreateInputType(); // act // assert Assert.Throws <SerializationException>( () => type.ParseLiteral( new ObjectValueNode( new ObjectFieldNode("type", new EnumValueNode("MultiPoint")), new ObjectFieldNode("coordinates", new ListValueNode())))); }