Пример #1
0
    public void Field_DectectsProperType(string fieldName, Type expectedGraphType)
    {
        var graphType = new AutoRegisteringInputObjectGraphType <FieldTests>();
        var fieldType = graphType.Fields.Find(fieldName).ShouldNotBeNull();

        fieldType.Type.ShouldBe(expectedGraphType);
    }
Пример #2
0
    public void Field_IgnoresOutputTypeAttribute()
    {
        var graphType = new AutoRegisteringInputObjectGraphType <FieldTests>();
        var fieldType = graphType.Fields.Find("Field7").ShouldNotBeNull();

        fieldType.Type.ShouldBe(typeof(GraphQLClrInputTypeReference <int>));
    }
        public void auto_register_input_object_graph_type()
        {
            GraphTypeTypeRegistry.Register <Money, AutoRegisteringInputObjectGraphType <Money> >();

            var type = new AutoRegisteringInputObjectGraphType <TestObject>(o => o.valuePair, o => o.someEnumerable);

            type.Name.ShouldBe(nameof(TestObject));
            type.Description.ShouldBe("Object for test");
            type.DeprecationReason.ShouldBe("Obsolete for test");
            type.Fields.Count().ShouldBe(18);
            type.Fields.First(f => f.Name == nameof(TestObject.someString)).Description.ShouldBe("Super secret");
            type.Fields.First(f => f.Name == nameof(TestObject.someString)).Type.ShouldBe(typeof(StringGraphType));
            type.Fields.First(f => f.Name == nameof(TestObject.someRequiredString)).Type.ShouldBe(typeof(NonNullGraphType <StringGraphType>));
            type.Fields.First(f => f.Name == nameof(TestObject.someInt)).Type.ShouldBe(typeof(IntGraphType));
            type.Fields.First(f => f.Name == nameof(TestObject.someNotNullInt)).Type.ShouldBe(typeof(NonNullGraphType <IntGraphType>));
            type.Fields.First(f => f.Name == nameof(TestObject.someBoolean)).DeprecationReason.ShouldBe("Use someInt");
            type.Fields.First(f => f.Name == nameof(TestObject.someDate)).DefaultValue.ShouldBe(new DateTime(2019, 3, 14));
            type.Fields.First(f => f.Name == nameof(TestObject.someShort)).Description.ShouldBe("Description from xml comment");
            type.Fields.First(f => f.Name == nameof(TestObject.someEnumerableOfString)).Type.ShouldBe(typeof(ListGraphType <StringGraphType>));
            type.Fields.First(f => f.Name == nameof(TestObject.someEnum)).Type.ShouldBe(typeof(NonNullGraphType <EnumerationGraphType <Direction> >));
            type.Fields.First(f => f.Name == nameof(TestObject.someNullableEnum)).Type.ShouldBe(typeof(EnumerationGraphType <Direction>));
            type.Fields.First(f => f.Name == nameof(TestObject.someList)).Type.ShouldBe(typeof(ListGraphType <NonNullGraphType <IntGraphType> >));
            type.Fields.First(f => f.Name == nameof(TestObject.someListWithNullable)).Type.ShouldBe(typeof(ListGraphType <IntGraphType>));
            type.Fields.First(f => f.Name == nameof(TestObject.someRequiredList)).Type.ShouldBe(typeof(NonNullGraphType <ListGraphType <NonNullGraphType <IntGraphType> > >));
            type.Fields.First(f => f.Name == nameof(TestObject.someRequiredListWithNullable)).Type.ShouldBe(typeof(NonNullGraphType <ListGraphType <IntGraphType> >));
            type.Fields.First(f => f.Name == nameof(TestObject.someMoney)).Type.ShouldBe(typeof(AutoRegisteringInputObjectGraphType <Money>));

            var enumType = new EnumerationGraphType <Direction>();

            enumType.Values["DESC"].Description.ShouldBe("Descending Order");
            enumType.Values["RANDOM"].DeprecationReason.ShouldBe("Do not use Random. This makes no sense!");
        }
Пример #4
0
    public void Field_RecognizesDefaultValueAttribute()
    {
        var graphType = new AutoRegisteringInputObjectGraphType <FieldTests>();
        var fieldType = graphType.Fields.Find("Field8").ShouldNotBeNull();

        fieldType.DefaultValue.ShouldBeOfType <string>().ShouldBe("hello");
    }
Пример #5
0
    public void Field_RecognizesCustomGraphQLAttributes()
    {
        var graphType = new AutoRegisteringInputObjectGraphType <FieldTests>();
        var fieldType = graphType.Fields.Find("Field4").ShouldNotBeNull();

        fieldType.Description.ShouldBe("Test custom description for field");
    }
Пример #6
0
    public void Field_RecognizesInputTypeAttribute()
    {
        var graphType = new AutoRegisteringInputObjectGraphType <FieldTests>();
        var fieldType = graphType.Fields.Find("Field6").ShouldNotBeNull();

        fieldType.Type.ShouldBe(typeof(IdGraphType));
    }
Пример #7
0
    public void Field_RecognizesObsoleteAttribute()
    {
        var graphType = new AutoRegisteringInputObjectGraphType <FieldTests>();
        var fieldType = graphType.Fields.Find("Field3").ShouldNotBeNull();

        fieldType.DeprecationReason.ShouldBe("Test deprecation reason");
    }
Пример #8
0
    public void Field_RecognizesDescriptionAttribute()
    {
        var graphType = new AutoRegisteringInputObjectGraphType <FieldTests>();
        var fieldType = graphType.Fields.Find("Field2").ShouldNotBeNull();

        fieldType.Description.ShouldBe("Test description");
    }
Пример #9
0
    public void TestBasicRecordStructNoExtraFields()
    {
        var graphType = new AutoRegisteringInputObjectGraphType <TestBasicRecordStruct>();

        graphType.Fields.Find("Id").ShouldNotBeNull();
        graphType.Fields.Find("Name").ShouldNotBeNull();
        graphType.Fields.Count.ShouldBe(2);
    }
Пример #10
0
    public void Class_RecognizesMultipleAttributes()
    {
        var graphType = new AutoRegisteringInputObjectGraphType <TestClass_WithMultipleAttributes>();

        graphType.Description.ShouldBe("Test description");
        graphType.GetMetadata <string>("key1").ShouldBe("value1");
        graphType.GetMetadata <string>("key2").ShouldBe("value2");
    }
Пример #11
0
    public void Field_RecognizesMultipleAttributes()
    {
        var graphType = new AutoRegisteringInputObjectGraphType <FieldTests>();
        var fieldType = graphType.Fields.Find("Field5").ShouldNotBeNull();

        fieldType.Description.ShouldBe("Test description");
        fieldType.GetMetadata <string>("key1").ShouldBe("value1");
        fieldType.GetMetadata <string>("key2").ShouldBe("value2");
    }
Пример #12
0
    public void RegistersWritablePropertiesOnly()
    {
        var inputType = new AutoRegisteringInputObjectGraphType <TestClass>();

        inputType.Fields.Find("Field1").ShouldNotBeNull();
        inputType.Fields.Find("Field2").ShouldBeNull();
        inputType.Fields.Find("Field3").ShouldNotBeNull();
        inputType.Fields.Find("Field4").ShouldBeNull();
        inputType.Fields.Find("Field5").ShouldBeNull();
    }
Пример #13
0
    public void SkipsSpecifiedProperties()
    {
        var inputType = new AutoRegisteringInputObjectGraphType <TestClass>(x => x.Field1);

        inputType.Fields.Find("Field1").ShouldBeNull();
        inputType.Fields.Find("Field2").ShouldBeNull();
        inputType.Fields.Find("Field3").ShouldNotBeNull();
        inputType.Fields.Find("Field4").ShouldBeNull();
        inputType.Fields.Find("Field5").ShouldBeNull();
    }
    public void auto_register_input_object_graph_type()
    {
        try
        {
            GlobalSwitches.EnableReadDescriptionFromXmlDocumentation = true;
            var schema = new Schema();
            var type   = new AutoRegisteringInputObjectGraphType <TestObject>(o => o.valuePair, o => o.someEnumerable);
            var query  = new ObjectGraphType();
            query.Field <StringGraphType>("test", arguments: new QueryArguments(new QueryArgument(type)
            {
                Name = "input"
            }));
            schema.Query = query;
            schema.Initialize();

            type.Name.ShouldBe(nameof(TestObject));
            type.Description.ShouldBe("Object for test");
            type.DeprecationReason.ShouldBe("Obsolete for test");
            type.Fields.Count.ShouldBe(18);
            type.Fields.First(f => f.Name == nameof(TestObject.someString)).Description.ShouldBe("Super secret");
            type.Fields.First(f => f.Name == nameof(TestObject.someString)).Type.ShouldBe(typeof(StringGraphType));
            type.Fields.First(f => f.Name == nameof(TestObject.someRequiredString)).Type.ShouldBe(typeof(NonNullGraphType <StringGraphType>));
            type.Fields.First(f => f.Name == nameof(TestObject.someInt)).Type.ShouldBe(typeof(IntGraphType));
            type.Fields.First(f => f.Name == nameof(TestObject.someNotNullInt)).Type.ShouldBe(typeof(NonNullGraphType <IntGraphType>));
            type.Fields.First(f => f.Name == nameof(TestObject.someBoolean)).DeprecationReason.ShouldBe("Use someInt");
            type.Fields.First(f => f.Name == nameof(TestObject.someDate)).DefaultValue.ShouldBe(new DateTime(2019, 3, 14));
            type.Fields.First(f => f.Name == nameof(TestObject.someShort)).Description.ShouldBe("Description from XML comment");
            type.Fields.First(f => f.Name == nameof(TestObject.someEnumerableOfString)).Type.ShouldBe(typeof(ListGraphType <StringGraphType>));
            type.Fields.First(f => f.Name == nameof(TestObject.someEnum)).Type.ShouldBe(typeof(NonNullGraphType <EnumerationGraphType <Direction> >));
            type.Fields.First(f => f.Name == nameof(TestObject.someNullableEnum)).Type.ShouldBe(typeof(EnumerationGraphType <Direction>));
            type.Fields.First(f => f.Name == nameof(TestObject.someList)).Type.ShouldBe(typeof(ListGraphType <NonNullGraphType <IntGraphType> >));
            type.Fields.First(f => f.Name == nameof(TestObject.someListWithNullable)).Type.ShouldBe(typeof(ListGraphType <IntGraphType>));
            type.Fields.First(f => f.Name == nameof(TestObject.someRequiredList)).Type.ShouldBe(typeof(NonNullGraphType <ListGraphType <NonNullGraphType <IntGraphType> > >));
            type.Fields.First(f => f.Name == nameof(TestObject.someRequiredListWithNullable)).Type.ShouldBe(typeof(NonNullGraphType <ListGraphType <IntGraphType> >));
            type.Fields.First(f => f.Name == nameof(TestObject.someMoney)).Type.ShouldBe(typeof(AutoRegisteringInputObjectGraphType <Money>));

            var enumType = new EnumerationGraphType <Direction>();
            enumType.Values["DESC"].Description.ShouldBe("Descending Order");
            enumType.Values["RANDOM"].DeprecationReason.ShouldBe("Do not use Random. This makes no sense!");
        }
        finally
        {
            GlobalSwitches.EnableReadDescriptionFromXmlDocumentation = false;
        }
    }
Пример #15
0
    public void Field_IgnoresOutputNameAttribute()
    {
        var graphType = new AutoRegisteringInputObjectGraphType <FieldTests>();

        graphType.Fields.Find("Field10").ShouldNotBeNull();
    }
Пример #16
0
    public void Class_RecognizesCustomGraphQLAttributes()
    {
        var graphType = new AutoRegisteringInputObjectGraphType <TestClass_WithCustomAttributes>();

        graphType.Description.ShouldBe("Test custom description");
    }
Пример #17
0
    public void Class_RecognizesInheritedAttributes()
    {
        var graphType = new AutoRegisteringInputObjectGraphType <DerivedClass>();

        graphType.Fields.Find("Field1CustomName").ShouldNotBeNull();
    }
Пример #18
0
    public void Class_RecognizesObsoleteAttribute()
    {
        var graphType = new AutoRegisteringInputObjectGraphType <TestClass_WithCustomDeprecationReason>();

        graphType.DeprecationReason.ShouldBe("Test deprecation reason");
    }
Пример #19
0
    public void Class_IgnoresOutputNameAttribute()
    {
        var graphType = new AutoRegisteringInputObjectGraphType <TestClass_WithCustomOutputName>();

        graphType.Name.ShouldBe("TestClass_WithCustomOutputName");
    }
Пример #20
0
    public void Field_RecognizesNameAttribute()
    {
        var graphType = new AutoRegisteringInputObjectGraphType <FieldTests>();

        graphType.Fields.Find("Test1").ShouldNotBeNull();
    }
Пример #21
0
    public void Class_RecognizesInputNameAttribute()
    {
        var graphType = new AutoRegisteringInputObjectGraphType <TestClass_WithCustomInputName>();

        graphType.Name.ShouldBe("TestWithCustomName");
    }