public void Convention_DefaultScope_Extensions() { // arrange // act var convention = new SortConvention( x => x.UseMock() .Configure <TestSort>( y => y.Field("foo").Type <DefaultSortEnumType>()) .Operation(123).Name("test")); ISchemaBuilder builder = SchemaBuilder.New() .AddConvention <ISortConvention>(convention) .TryAddTypeInterceptor <SortTypeInterceptor>() .AddQueryType(c => c.Name("Query") .Field("foo") .Type <StringType>() .Resolver("bar") .Argument("test", x => x.Type <TestSort>())); ISchema schema = builder.Create(); // assert schema.ToString().MatchSnapshot(); }
public void SortConvention_Should_Fail_When_FieldHandlerIsNotRegistered() { // arrange var provider = new QueryableSortProvider( descriptor => { descriptor.AddOperationHandler <QueryableAscendingSortOperationHandler>(); }); var convention = new SortConvention( descriptor => { descriptor.Operation(DefaultSortOperations.Ascending).Name("asc"); descriptor.BindRuntimeType <string, TestEnumType>(); descriptor.Provider(provider); }); var type = new FooSortType(); //act SchemaException?error = Assert.Throws <SchemaException>(() => CreateSchemaWith(type, convention)); Assert.Single(error.Errors); error.Errors[0].Message.MatchSnapshot(); }
public void SortConvention_Should_Work_With_ProviderExtensionsType() { // arrange var provider = new QueryableSortProvider( descriptor => { descriptor.AddFieldHandler <QueryableDefaultSortFieldHandler>(); }); var convention = new SortConvention( descriptor => { descriptor.BindRuntimeType <string, TestEnumType>(); descriptor.Provider(provider); }); var extension1 = new SortConventionExtension( descriptor => { descriptor.Operation(DefaultSortOperations.Ascending).Name("ASC"); descriptor.AddProviderExtension <MockSortProviderExtensionConvention>(); }); IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral("{ bar: ASC}"); var type = new FooSortType(); //act CreateSchemaWith(type, convention, extension1); var executor = new ExecutorBuilder(type); Func <Foo[], Foo[]> func = executor.Build <Foo>(value); // assert Foo[]? a = new[] { new Foo { Bar = "a" }, new Foo { Bar = "b" }, new Foo { Bar = "c" } }; Assert.Collection( func(a), x => Assert.Equal("a", x.Bar), x => Assert.Equal("b", x.Bar), x => Assert.Equal("c", x.Bar)); Foo[]? b = new[] { new Foo { Bar = "c" }, new Foo { Bar = "b" }, new Foo { Bar = "a" } }; Assert.Collection( func(b), x => Assert.Equal("a", x.Bar), x => Assert.Equal("b", x.Bar), x => Assert.Equal("c", x.Bar)); }
protected ISchema CreateSchema <T>(T type) where T : ISortInputType { var convention = new SortConvention(x => x.AddDefaults()); ISchemaBuilder builder = SchemaBuilder.New() .AddConvention <ISortConvention>(convention) .TryAddTypeInterceptor <SortTypeInterceptor>() .AddQueryType(c => c .Name("Query") .Field("foo") .Type <StringType>() .Resolver("bar")) .AddType(type); return(builder.Create()); }
protected ISchema CreateSchemaWith( ISortInputType type, SortConvention convention, params SortConventionExtension[] extensions) { ISchemaBuilder builder = SchemaBuilder.New() .AddConvention <ISortConvention>(convention) .AddSorting() .AddQueryType( c => c.Name("Query") .Field("foo") .Type <StringType>() .Resolve("bar")) .AddType(type); foreach (SortConventionExtension?extension in extensions) { builder.AddConvention <ISortConvention>(extension); } return(builder.Create()); }