Beispiel #1
0
        public void OverwriteDefaultValueLiteralWithNativeDefaultValue()
        {
            // arrange
            InputFieldDescriptor inputFieldDescriptor = new InputFieldDescriptor(
                typeof(Field).GetProperty("Arguments"));

            // act
            ((IInputFieldDescriptor)inputFieldDescriptor)
            .DefaultValue(new StringValueNode("123"))
            .DefaultValue("string");

            // assert
            Assert.Null(inputFieldDescriptor.DefaultValue);
            Assert.Equal("string", inputFieldDescriptor.NativeDefaultValue);
        }
Beispiel #2
0
        public void OverwriteName2()
        {
            // arrange
            var descriptor = InputFieldDescriptor.New(
                Context,
                typeof(ObjectField).GetProperty("Arguments"));

            // act
            descriptor.Name("args");

            // assert
            InputFieldDefinition description = descriptor.CreateDefinition();

            Assert.Equal("args", description.Name);
        }
Beispiel #3
0
        public void OverwriteName2()
        {
            // arrange
            var descriptor = new InputFieldDescriptor(
                typeof(ObjectField).GetProperty("Arguments"));

            // act
            ((IInputFieldDescriptor)descriptor)
            .Name("args");

            // assert
            InputFieldDescription description = descriptor.CreateDescription();

            Assert.Equal("args", description.Name);
        }
Beispiel #4
0
        public void OverwriteName()
        {
            // arrange
            var descriptor = InputFieldDescriptor.New(
                Context,
                "field1234");

            // act
            descriptor.Name("args");

            // assert
            InputFieldDefinition description = descriptor.CreateDefinition();

            Assert.Equal("args", description.Name);
        }
Beispiel #5
0
        public void SchemaTypesOverwriteDotNetTypes()
        {
            // arrange
            InputFieldDescriptor inputFieldDescriptor = new InputFieldDescriptor(
                typeof(Field).GetProperty("Arguments"));

            // act
            ((IInputFieldDescriptor)inputFieldDescriptor)
            .Type <NativeType <IReadOnlyDictionary <string, string> > >()
            .Type <ListType <StringType> >();

            // assert
            TypeReference typeRef = inputFieldDescriptor.TypeReference;

            Assert.Equal(typeof(ListType <StringType>), typeRef.NativeType);
        }
        public void SetSchemaType()
        {
            // arrange
            var descriptor = new InputFieldDescriptor(
                typeof(ObjectField).GetProperty("Arguments"));

            // act
            ((IInputFieldDescriptor)descriptor)
            .Type(new StringType());

            // assert
            InputFieldDescription description = descriptor.CreateDescription();
            TypeReference         typeRef     = description.TypeReference;

            Assert.IsType <StringType>(typeRef.SchemaType);
        }
Beispiel #7
0
        public void SettingTheNativeDefaultValueToNullCreatesNullLiteral()
        {
            // arrange
            InputFieldDescriptor inputFieldDescriptor = new InputFieldDescriptor(
                typeof(Field).GetProperty("Arguments"));

            // act
            ((IInputFieldDescriptor)inputFieldDescriptor)
            .DefaultValue(new StringValueNode("123"))
            .DefaultValue("string")
            .DefaultValue(null);

            // assert
            Assert.IsType <NullValueNode>(inputFieldDescriptor.DefaultValue);
            Assert.Null(inputFieldDescriptor.NativeDefaultValue);
        }
Beispiel #8
0
        public void SetDescription()
        {
            // arrange
            string expectedDescription = Guid.NewGuid().ToString();
            var    descriptor          = InputFieldDescriptor.New(
                Context,
                typeof(ObjectField).GetProperty("Arguments"));

            // act
            descriptor.Description(expectedDescription);

            // assert
            InputFieldDefinition description = descriptor.CreateDefinition();

            Assert.Equal(expectedDescription, description.Description);
        }
Beispiel #9
0
        public void SetDefaultValueAndInferType()
        {
            // arrange
            var descriptor = new InputFieldDescriptor(
                typeof(ObjectField).GetProperty("Arguments"));

            // act
            ((IInputFieldDescriptor)descriptor)
            .DefaultValue("string");

            // assert
            InputFieldDescription description = descriptor.CreateDescription();

            Assert.Equal(typeof(string), description.TypeReference.ClrType);
            Assert.Equal("string", description.NativeDefaultValue);
        }
Beispiel #10
0
        public void SetSchemaType()
        {
            // arrange
            var descriptor = InputFieldDescriptor.New(
                Context,
                typeof(ObjectField).GetProperty("Arguments"));

            // act
            descriptor.Type(new StringType());

            // assert
            InputFieldDefinition description = descriptor.CreateDefinition();
            ITypeReference       typeRef     = description.Type;

            Assert.IsType <StringType>(
                Assert.IsType <SchemaTypeReference>(typeRef).Type);
        }
Beispiel #11
0
        public void SetDefaultValueAndInferType()
        {
            // arrange
            var descriptor = InputFieldDescriptor.New(
                Context,
                typeof(ObjectField).GetProperty("Arguments"));

            // act
            descriptor.DefaultValue("string");

            // assert
            InputFieldDefinition description = descriptor.CreateDefinition();

            Assert.Equal(typeof(string),
                         Assert.IsType <ClrTypeReference>(description.Type).Type);
            Assert.Equal("string", description.NativeDefaultValue);
        }
Beispiel #12
0
        public void OverwriteDefaultValueLiteralWithNativeDefaultValue()
        {
            // arrange
            var descriptor = new InputFieldDescriptor(
                typeof(ObjectField).GetProperty("Arguments"));

            // act
            ((IInputFieldDescriptor)descriptor)
            .DefaultValue(new StringValueNode("123"))
            .DefaultValue("string");

            // asser
            InputFieldDescription description = descriptor.CreateDescription();

            Assert.Null(description.DefaultValue);
            Assert.Equal("string", description.NativeDefaultValue);
        }
Beispiel #13
0
        public void SchemaTypesOverwriteDotNetTypes()
        {
            // arrange
            var descriptor = new InputFieldDescriptor(
                typeof(ObjectField).GetProperty("Arguments"));

            // act
            ((IInputFieldDescriptor)descriptor)
            .Type <NativeType <IReadOnlyDictionary <string, string> > >()
            .Type <ListType <StringType> >();

            // assert
            InputFieldDescription description = descriptor.CreateDescription();
            TypeReference         typeRef     = description.TypeReference;

            Assert.Equal(typeof(ListType <StringType>), typeRef.ClrType);
        }
Beispiel #14
0
        public void SetNonGenericType()
        {
            // arrange
            var descriptor = InputFieldDescriptor.New(
                Context,
                typeof(ObjectField).GetProperty("Arguments"));

            // act
            descriptor.Type(typeof(StringType));

            // assert
            InputFieldDefinition description = descriptor.CreateDefinition();
            ITypeReference       typeRef     = description.Type;

            Assert.Equal(
                typeof(StringType),
                Assert.IsType <ClrTypeReference>(typeRef).Type);
        }
Beispiel #15
0
        public void SettingTheNativeDefaultValueToNullCreatesNullLiteral()
        {
            // arrange
            var descriptor = new InputFieldDescriptor(
                typeof(ObjectField).GetProperty("Arguments"));

            // act
            ((IInputFieldDescriptor)descriptor)
            .DefaultValue(new StringValueNode("123"))
            .DefaultValue("string")
            .DefaultValue(null);

            // assert
            InputFieldDescription description = descriptor.CreateDescription();

            Assert.IsType <NullValueNode>(description.DefaultValue);
            Assert.Null(description.NativeDefaultValue);
        }
Beispiel #16
0
        public void SchemaTypesOverwriteDotNetTypes()
        {
            // arrange
            var descriptor = InputFieldDescriptor.New(
                Context,
                typeof(ObjectField).GetProperty("Arguments"));

            // act
            descriptor
            .Type <NativeType <IReadOnlyDictionary <string, string> > >()
            .Type <ListType <StringType> >();

            // assert
            InputFieldDefinition description = descriptor.CreateDefinition();
            ITypeReference       typeRef     = description.Type;

            Assert.Equal(typeof(ListType <StringType>),
                         Assert.IsType <ClrTypeReference>(typeRef).Type);
        }
Beispiel #17
0
        public void OverwriteNativeDefaultValueWithDefaultValueLiteral()
        {
            // arrange
            var descriptor = InputFieldDescriptor.New(
                Context,
                typeof(ObjectField).GetProperty("Arguments"));

            // act
            ((IInputFieldDescriptor)descriptor)
            .DefaultValue("string")
            .DefaultValue(new StringValueNode("123"));

            // assert
            InputFieldDefinition description = descriptor.CreateDefinition();

            Assert.IsType <StringValueNode>(description.DefaultValue);
            Assert.Equal("123",
                         ((StringValueNode)description.DefaultValue).Value);
            Assert.Null(description.NativeDefaultValue);
        }
        protected InputFieldDescriptor Field(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException(
                          "The name cannot be null or empty.",
                          nameof(name));
            }

            if (!ValidationHelper.IsFieldNameValid(name))
            {
                throw new ArgumentException(
                          "The specified name is not a valid GraphQL field name.",
                          nameof(name));
            }

            var field = new InputFieldDescriptor(name);

            Fields.Add(field);
            return(field);
        }
Beispiel #19
0
        internal InputField(InputFieldDescriptor descriptor)
        {
            if (descriptor == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            if (string.IsNullOrEmpty(descriptor.Name))
            {
                throw new ArgumentException(
                          "An input value name must not be null or empty.",
                          nameof(descriptor));
            }

            _typeReference      = descriptor.TypeReference;
            _nativeDefaultValue = descriptor.NativeDefaultValue;

            SyntaxNode   = descriptor.SyntaxNode;
            Name         = descriptor.Name;
            Description  = descriptor.Description;
            DefaultValue = descriptor.DefaultValue;
            Property     = descriptor.Property;
        }
Beispiel #20
0
        public void Type_Syntax_Type_Null()
        {
            void Error() => InputFieldDescriptor.New(Context, "foo").Type((string)null);

            Assert.Throws <ArgumentNullException>(Error);
        }