public async Task MapOperationTypeDescriptors() { // arrange ClientModel clientModel = await CreateClientModelAsync( @" query GetHero { hero(episode: NEW_HOPE) { name appearsIn } } mutation CreateReview { createReview(episode: NEW_HOPE, review: {stars: 5, commentary: ""splendid""}) { stars commentary } } subscription OnReview { onReview(episode: NEW_HOPE) { stars commentary } } "); // act var context = new MapperContext( "Foo.Bar", "FooClient", new Sha1DocumentHashProvider(), RequestStrategyGen.Default, new[] { TransportProfile.Default }); TypeDescriptorMapper.Map(clientModel, context); OperationDescriptorMapper.Map(clientModel, context); // assert Assert.Collection( context.Operations.OrderBy(t => t.Name), operation => { Assert.Equal("CreateReview", operation.Name); }, operation => { Assert.Equal("GetHero", operation.Name); }, operation => { Assert.Equal("OnReview", operation.Name); }); }
public async Task MapEnumTypeDescriptors() { // arrange ClientModel clientModel = await CreateClientModelAsync( @"query GetHero { hero(episode: NEW_HOPE) { name appearsIn } }"); // act var context = new MapperContext( "Foo.Bar", "FooClient", new Sha1DocumentHashProvider(), RequestStrategyGen.Default, new[] { TransportProfile.Default }); TypeDescriptorMapper.Map(clientModel, context); // assert Assert.Collection( context.Types.OfType <EnumTypeDescriptor>().OrderBy(t => t.Name), enumType => { Assert.Equal("Episode", enumType.Name); Assert.Collection( enumType.Values.OrderBy(t => t.RuntimeValue), value => { Assert.Equal("Empire", value.RuntimeValue); Assert.Null(value.Value); }, value => { Assert.Equal("Jedi", value.RuntimeValue); Assert.Null(value.Value); }, value => { Assert.Equal("NewHope", value.RuntimeValue); Assert.Null(value.Value); }); }); }
public async Task MapResultBuilderDescriptors() { // arrange ClientModel clientModel = await CreateClientModelAsync( @" query GetHero { hero(episode: NEW_HOPE) { name appearsIn } } mutation CreateReview { createReview(episode: NEW_HOPE, review: {stars: 5, commentary: ""splendid""}) { stars commentary } } subscription OnReview { onReview(episode: NEW_HOPE) { stars commentary } } "); // act var context = new MapperContext("Foo.Bar", "FooClient"); TypeDescriptorMapper.Map(clientModel, context); ResultBuilderDescriptorMapper.Map(clientModel, context); // assert Assert.Collection( context.ResultBuilders.OrderBy(t => t.Name), resultBuilder => { Assert.Equal("CreateReviewBuilder", resultBuilder.Name); }, resultBuilder => { Assert.Equal("GetHeroBuilder", resultBuilder.Name); }, resultBuilder => { Assert.Equal("OnReviewBuilder", resultBuilder.Name); }); }
public static void Map( ClientModel model, IMapperContext context) { context.Register( new DependencyInjectionDescriptor( context.ClientName, context.Namespace, EntityTypeDescriptorMapper.CollectEntityTypes(model, context).ToList(), context.Operations.ToList(), TypeDescriptorMapper .CollectTypeDescriptors(model, context) .Select(x => x.Item2) .ToList(), EnumDescriptorMapper.CollectEnumDescriptors(model, context).ToList())); }
public async Task MapClientDescriptor() { // arrange ClientModel clientModel = await CreateClientModelAsync( @" query GetHero { hero(episode: NEW_HOPE) { name appearsIn } } mutation CreateReview { createReview(episode: NEW_HOPE, review: {stars: 5, commentary: ""splendid""}) { stars commentary } } subscription OnReview { onReview(episode: NEW_HOPE) { stars commentary } } "); // act var clientName = "FooClient"; var context = new MapperContext( "Foo.Bar", clientName, new Sha1DocumentHashProvider(), Descriptors.Operations.RequestStrategy.Default, new[] { TransportProfile.Default }); TypeDescriptorMapper.Map(clientModel, context); OperationDescriptorMapper.Map(clientModel, context); ClientDescriptorMapper.Map(clientModel, context); // assert Assert.Equal(clientName, context.Client.Name); Assert.Equal(3, context.Client.Operations.Count); }
public void MapDataTypeDescriptors_DataInterfaceType() { // arrange var clientModel = CreateClientModelAsync( "interface.query.graphql", "interface.schema.graphql"); // act var context = new MapperContext( "Foo.Bar", "FooClient"); TypeDescriptorMapper.Map( clientModel, context); EntityTypeDescriptorMapper.Map( clientModel, context); DataTypeDescriptorMapper.Map( clientModel, context); // assert Assert.Collection( context.DataTypes.OrderBy(t => t.RuntimeType.ToString()), type => { Assert.Equal( "BookData", type.RuntimeType.Name); Assert.Equal( "Foo.Bar.State", type.RuntimeType.NamespaceWithoutGlobal); Assert.Collection( type.Properties.OrderBy(p => p.Name), property => { Assert.Equal( "Isbn", property.Name); }, property => { Assert.Equal( "Title", property.Name); }); }, type => { Assert.Equal( "IPrintData", type.RuntimeType.Name); Assert.Equal( "Foo.Bar.State", type.RuntimeType.NamespaceWithoutGlobal); Assert.Empty(type.Properties); }, type => { Assert.Equal( "ISearchResultData", type.RuntimeType.Name); Assert.Equal( "Foo.Bar.State", type.RuntimeType.NamespaceWithoutGlobal); Assert.Empty(type.Properties); }, type => { Assert.Equal( "MagazineData", type.RuntimeType.Name); Assert.Equal( "Foo.Bar.State", type.RuntimeType.NamespaceWithoutGlobal); Assert.Collection( type.Properties.OrderBy(p => p.Name), property => { Assert.Equal( "CoverImageUrl", property.Name); }, property => { Assert.Equal( "Isbn", property.Name); }); }); }
public async Task MapDataTypeDescriptors_SimpleCase() { // arrange ClientModel clientModel = await CreateClientModelAsync( @" query GetHeroNodes { hero(episode: NEW_HOPE) { friends { nodes { name } } } } query GetHeroEdges { hero(episode: NEW_HOPE) { friends { edges { cursor } } } }"); // act var context = new MapperContext( "Foo.Bar", "FooClient"); TypeDescriptorMapper.Map( clientModel, context); DataTypeDescriptorMapper.Map( clientModel, context); // assert Assert.Collection( context.DataTypes.OrderBy(t => t.RuntimeType.ToString()), type => { Assert.Equal( "CharacterConnectionData", type.RuntimeType.Name); Assert.Equal( "Foo.Bar.State", type.RuntimeType.NamespaceWithoutGlobal); Assert.Collection( type.Properties, property => { Assert.Equal( "Nodes", property.Name); Assert.Equal( "IGetHeroNodes_Hero_Friends_Nodes", property.Type.GetRuntimeType().Name); }, property => { Assert.Equal( "Edges", property.Name); Assert.Equal( "IGetHeroEdges_Hero_Friends_Edges", property.Type.GetRuntimeType().Name); }); }, type => { Assert.Equal( "CharacterEdgeData", type.RuntimeType.Name); Assert.Equal( "Foo.Bar.State", type.RuntimeType.NamespaceWithoutGlobal); Assert.Collection( type.Properties, property => { Assert.Equal( "Cursor", property.Name); Assert.Equal( "String", property.Type.GetRuntimeType().Name); }); }); }
public void MapDataTypeDescriptors_DataUnionType() { // arrange var clientModel = CreateClientModelAsync("union.query3.graphql", "union.schema.graphql"); // act var context = new MapperContext( "Foo.Bar", "FooClient", new Sha1DocumentHashProvider(), RequestStrategyGen.Default, new[] { TransportProfile.Default }); TypeDescriptorMapper.Map( clientModel, context); EntityTypeDescriptorMapper.Map( clientModel, context); DataTypeDescriptorMapper.Map( clientModel, context); // assert Assert.Collection( context.DataTypes.OrderBy(t => t.RuntimeType.ToString()), type => { Assert.Equal( "AuthorData", type.RuntimeType.Name); Assert.Equal( "Foo.Bar.State", type.RuntimeType.NamespaceWithoutGlobal); Assert.Collection( type.Properties.OrderBy(p => p.Name), property => { Assert.Equal( "Genres", property.Name); }, property => { Assert.Equal( "Name", property.Name); }); }, type => { Assert.Equal( "BookData", type.RuntimeType.Name); Assert.Equal( "Foo.Bar.State", type.RuntimeType.NamespaceWithoutGlobal); Assert.Collection( type.Properties.OrderBy(p => p.Name), property => { Assert.Equal( "Isbn", property.Name); }, property => { Assert.Equal( "Title", property.Name); }); }, type => { Assert.Equal( "ISearchResultData", type.RuntimeType.Name); Assert.Equal( "Foo.Bar.State", type.RuntimeType.NamespaceWithoutGlobal); Assert.Empty(type.Properties); }); }
public async Task MapClientTypeDescriptors() { // arrange ClientModel clientModel = await CreateClientModelAsync( @"query GetHero { hero(episode: NEW_HOPE) { name } }"); // act var context = new MapperContext( "Foo.Bar", "FooClient", new Sha1DocumentHashProvider(), RequestStrategyGen.Default, new[] { TransportProfile.Default }); TypeDescriptorMapper.Map(clientModel, context); // assert Assert.Collection( context.Types.OfType <ComplexTypeDescriptor>().OrderBy(t => t.Name), type => { Assert.Equal("IGetHero_Hero", type.RuntimeType.Name); Assert.Equal("Foo.Bar", type.RuntimeType.NamespaceWithoutGlobal); Assert.True(type.IsEntityType()); Assert.Collection( type.Properties, property => { Assert.Equal("Name", property.Name); Assert.Equal("String", property.Type.Name); Assert.False(property.Type.IsNullableType()); }); }, type => { Assert.Equal("GetHero_Hero_Droid", type.RuntimeType.Name); Assert.Equal("Foo.Bar", type.RuntimeType.NamespaceWithoutGlobal); Assert.Collection( type.Properties, property => { Assert.Equal("Name", property.Name); Assert.Equal("String", property.Type.Name); Assert.False(property.Type.IsNullableType()); }); }, type => { Assert.Equal("IGetHero_Hero_Droid", type.RuntimeType.Name); Assert.Equal("Foo.Bar", type.RuntimeType.NamespaceWithoutGlobal); Assert.True(type.IsEntityType()); }, type => { Assert.Equal("GetHero_Hero_Human", type.RuntimeType.Name); Assert.Equal("Foo.Bar", type.RuntimeType.NamespaceWithoutGlobal); Assert.Collection( type.Properties, property => { Assert.Equal("Name", property.Name); Assert.Equal("String", property.Type.Name); Assert.False(property.Type.IsNullableType()); }); }, type => { Assert.Equal("IGetHero_Hero_Human", type.RuntimeType.Name); Assert.Equal("Foo.Bar", type.RuntimeType.NamespaceWithoutGlobal); Assert.True(type.IsEntityType()); }, type => { Assert.Equal("GetHeroResult", type.RuntimeType.Name); Assert.Equal("Foo.Bar", type.RuntimeType.NamespaceWithoutGlobal); Assert.Collection( type.Properties, property => { Assert.Equal("Hero", property.Name); Assert.Equal("IGetHero_Hero", Assert.IsType <InterfaceTypeDescriptor>(property.Type) .RuntimeType.Name); Assert.True(property.Type.IsNullableType()); }); }, type => { Assert.Equal("IGetHeroResult", type.RuntimeType.Name); Assert.Equal("Foo.Bar", type.RuntimeType.NamespaceWithoutGlobal); Assert.Collection( type.Properties, property => { Assert.Equal("Hero", property.Name); Assert.Equal("IGetHero_Hero", Assert.IsType <InterfaceTypeDescriptor>(property.Type) .RuntimeType.Name); Assert.True(property.Type.IsNullableType()); }); }); }
public async Task MapDataTypeDescriptors_DataUnionType() { // arrange var clientModel = CreateClientModelAsync("union.query3.graphql", "union.schema.graphql"); // act var context = new MapperContext( "Foo.Bar", "FooClient"); TypeDescriptorMapper.Map( clientModel, context); EntityTypeDescriptorMapper.Map( clientModel, context); DataTypeDescriptorMapper.Map( clientModel, context); // assert Assert.Collection( context.DataTypes.OrderBy(t => t.Name), type => { Assert.Equal( "AuthorData", type.Name); Assert.Equal( "Foo.Bar.State", type.Namespace); Assert.Collection( type.Properties.OrderBy(p => p.Name), property => { Assert.Equal( "Genres", property.Name); }, property => { Assert.Equal( "Name", property.Name); }); }, type => { Assert.Equal( "BookData", type.Name); Assert.Equal( "Foo.Bar.State", type.Namespace); Assert.Collection( type.Properties.OrderBy(p => p.Name), property => { Assert.Equal( "Isbn", property.Name); }, property => { Assert.Equal( "Title", property.Name); }); }, type => { Assert.Equal( "ISearchResultData", type.Name); Assert.Equal( "Foo.Bar.State", type.Namespace); Assert.Empty(type.Properties); }); }
public async Task MapClientTypeDescriptors() { // arrange ClientModel clientModel = await CreateClientModelAsync( @"query GetHero { hero(episode: NEW_HOPE) { name } }"); // act var context = new MapperContext("Foo.Bar", "FooClient"); TypeDescriptorMapper.Map(clientModel, context); // assert Assert.Collection( context.Types.OrderBy(t => t.Name), type => { Assert.Equal("GetHero_Hero_Droid", type.Name); Assert.Equal("Foo.Bar", type.Namespace); Assert.Collection( type.Properties, property => { Assert.Equal("Name", property.Name); Assert.Equal("String", property.Type.Name); Assert.False(property.Type.IsNullableType()); }); }, type => { Assert.Equal("GetHero_Hero_Human", type.Name); Assert.Equal("Foo.Bar", type.Namespace); Assert.Collection( type.Properties, property => { Assert.Equal("Name", property.Name); Assert.Equal("String", property.Type.Name); Assert.False(property.Type.IsNullableType()); }); }, type => { Assert.Equal("GetHeroResult", type.Name); Assert.Equal("Foo.Bar", type.Namespace); Assert.Collection( type.Properties, property => { Assert.Equal("Hero", property.Name); Assert.Equal("IGetHero_Hero", property.Type.Name); Assert.True(property.Type.IsNullableType()); }); }, type => { Assert.Equal("IGetHero_Hero", type.Name); Assert.Equal("Foo.Bar", type.Namespace); Assert.True(type.IsEntityType()); Assert.Collection( type.Properties, property => { Assert.Equal("Name", property.Name); Assert.Equal("String", property.Type.Name); Assert.False(property.Type.IsNullableType()); }); }, type => { Assert.Equal("IGetHero_Hero_Droid", type.Name); Assert.Equal("Foo.Bar", type.Namespace); Assert.True(type.IsEntityType()); }, type => { Assert.Equal("IGetHero_Hero_Human", type.Name); Assert.Equal("Foo.Bar", type.Namespace); Assert.True(type.IsEntityType()); }, type => { Assert.Equal("IGetHeroResult", type.Name); Assert.Equal("Foo.Bar", type.Namespace); Assert.Collection( type.Properties, property => { Assert.Equal("Hero", property.Name); Assert.Equal("IGetHero_Hero", property.Type.Name); Assert.True(property.Type.IsNullableType()); }); }, type => { Assert.Equal("String", type.Name); Assert.Equal("global::System", type.Namespace); Assert.True(type.IsLeafType()); }); }