Ejemplo n.º 1
0
        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)));
 }
Ejemplo n.º 4
0
        private void VisitInput(InputObjectType type)
        {
            VisitDirectives(type);

            foreach (InputField field in type.Fields)
            {
                VisitDirectives(field);
                Visit((TypeSystemObjectBase)field.Type.NamedType());
            }
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 7
0
 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);
 }
Ejemplo n.º 8
0
        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()))));
        }
Ejemplo n.º 10
0
 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));
 }
Ejemplo n.º 11
0
        public QueryableSortVisitor(
            InputObjectType initialType,
            Type source) : base(initialType)
        {
            if (initialType is null)
            {
                throw new ArgumentNullException(nameof(initialType));
            }

            Closure = new SortQueryableClosure(source, _parameterName);
        }
Ejemplo n.º 12
0
        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));
        }
Ejemplo n.º 13
0
 /// <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));
 }
Ejemplo n.º 14
0
 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);
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 19
0
        public QueryableSortVisitor(
            InputObjectType initialType,
            Type source)
        {
            if (initialType is null)
            {
                throw new ArgumentNullException(nameof(initialType));
            }

            Types.Push(initialType);
            _parameter = Expression.Parameter(source);
        }
Ejemplo n.º 20
0
 public QueryableFilterVisitor(
     InputObjectType initialType,
     Type source,
     ITypeConversion converter)
     : this(
         initialType,
         source,
         converter,
         ExpressionOperationHandlers.All,
         ExpressionFieldHandlers.All)
 {
 }
Ejemplo n.º 21
0
        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);
        }
Ejemplo n.º 23
0
	public void ChangeInputType(HEU_SessionBase session, InputObjectType newType)
	{
	    if (newType == _inputObjectType)
	    {
		return;
	    }

	    DisconnectAndDestroyInputs(session);

	    _inputObjectType = newType;
	    _pendingInputObjectType = _inputObjectType;
	}
Ejemplo n.º 24
0
 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);
         }
     }
 }
Ejemplo n.º 25
0
        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);
        }
Ejemplo n.º 26
0
        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);
        }
Ejemplo n.º 27
0
        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")))));
        }
Ejemplo n.º 28
0
        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);
        }
Ejemplo n.º 29
0
        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()))));
        }