public void Field_DectectsProperType(string fieldName, Type expectedGraphType) { var graphType = new AutoRegisteringInputObjectGraphType <FieldTests>(); var fieldType = graphType.Fields.Find(fieldName).ShouldNotBeNull(); fieldType.Type.ShouldBe(expectedGraphType); }
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!"); }
public void Field_RecognizesDefaultValueAttribute() { var graphType = new AutoRegisteringInputObjectGraphType <FieldTests>(); var fieldType = graphType.Fields.Find("Field8").ShouldNotBeNull(); fieldType.DefaultValue.ShouldBeOfType <string>().ShouldBe("hello"); }
public void Field_RecognizesCustomGraphQLAttributes() { var graphType = new AutoRegisteringInputObjectGraphType <FieldTests>(); var fieldType = graphType.Fields.Find("Field4").ShouldNotBeNull(); fieldType.Description.ShouldBe("Test custom description for field"); }
public void Field_RecognizesInputTypeAttribute() { var graphType = new AutoRegisteringInputObjectGraphType <FieldTests>(); var fieldType = graphType.Fields.Find("Field6").ShouldNotBeNull(); fieldType.Type.ShouldBe(typeof(IdGraphType)); }
public void Field_RecognizesObsoleteAttribute() { var graphType = new AutoRegisteringInputObjectGraphType <FieldTests>(); var fieldType = graphType.Fields.Find("Field3").ShouldNotBeNull(); fieldType.DeprecationReason.ShouldBe("Test deprecation reason"); }
public void Field_RecognizesDescriptionAttribute() { var graphType = new AutoRegisteringInputObjectGraphType <FieldTests>(); var fieldType = graphType.Fields.Find("Field2").ShouldNotBeNull(); fieldType.Description.ShouldBe("Test description"); }
public void TestBasicRecordStructNoExtraFields() { var graphType = new AutoRegisteringInputObjectGraphType <TestBasicRecordStruct>(); graphType.Fields.Find("Id").ShouldNotBeNull(); graphType.Fields.Find("Name").ShouldNotBeNull(); graphType.Fields.Count.ShouldBe(2); }
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"); }
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"); }
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(); }
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; } }
public void Field_IgnoresOutputNameAttribute() { var graphType = new AutoRegisteringInputObjectGraphType <FieldTests>(); graphType.Fields.Find("Field10").ShouldNotBeNull(); }
public void Class_RecognizesCustomGraphQLAttributes() { var graphType = new AutoRegisteringInputObjectGraphType <TestClass_WithCustomAttributes>(); graphType.Description.ShouldBe("Test custom description"); }
public void Class_RecognizesInheritedAttributes() { var graphType = new AutoRegisteringInputObjectGraphType <DerivedClass>(); graphType.Fields.Find("Field1CustomName").ShouldNotBeNull(); }
public void Class_RecognizesObsoleteAttribute() { var graphType = new AutoRegisteringInputObjectGraphType <TestClass_WithCustomDeprecationReason>(); graphType.DeprecationReason.ShouldBe("Test deprecation reason"); }
public void Class_IgnoresOutputNameAttribute() { var graphType = new AutoRegisteringInputObjectGraphType <TestClass_WithCustomOutputName>(); graphType.Name.ShouldBe("TestClass_WithCustomOutputName"); }
public void Field_RecognizesNameAttribute() { var graphType = new AutoRegisteringInputObjectGraphType <FieldTests>(); graphType.Fields.Find("Test1").ShouldNotBeNull(); }
public void Class_RecognizesInputNameAttribute() { var graphType = new AutoRegisteringInputObjectGraphType <TestClass_WithCustomInputName>(); graphType.Name.ShouldBe("TestWithCustomName"); }