public void Merge_ObjectWithDifferentInterfaces_TypesMerge() { // arrange DocumentNode schema_a = Parser.Default.Parse("type A implements IA { b: String }"); DocumentNode schema_b = Parser.Default.Parse("type A implements IB { b : String }"); DocumentNode schema_c = Parser.Default.Parse("type A implements IC { b: String }"); var types = new List <ITypeInfo> { TypeInfo.Create( schema_a.Definitions.OfType <ITypeDefinitionNode>().First(), new SchemaInfo("Schema_A", schema_a)), TypeInfo.Create( schema_b.Definitions.OfType <ITypeDefinitionNode>().First(), new SchemaInfo("Schema_B", schema_b)), TypeInfo.Create( schema_c.Definitions.OfType <ITypeDefinitionNode>().First(), new SchemaInfo("Schema_C", schema_c)) }; var context = new SchemaMergeContext(); // act var typeMerger = new ObjectTypeMergeHandler((c, t) => { }); typeMerger.Merge(context, types); // assert SchemaSyntaxSerializer.Serialize(context.CreateSchema()) .MatchSnapshot(); }
public void MergeUnionTypes() { // arrange DocumentNode schema_a = Parser.Default.Parse("union Foo = Bar | Baz"); DocumentNode schema_b = Parser.Default.Parse("union Foo = Bar | Baz"); var types = new List <ITypeInfo> { TypeInfo.Create( schema_a.Definitions.OfType <ITypeDefinitionNode>().First(), new SchemaInfo("Schema_A", schema_a)), TypeInfo.Create( schema_b.Definitions.OfType <ITypeDefinitionNode>().First(), new SchemaInfo("Schema_B", schema_b)) }; var context = new SchemaMergeContext(); // act var typeMerger = new UnionTypeMergeHandler((c, t) => { }); typeMerger.Merge(context, types); // assert SchemaSyntaxSerializer.Serialize(context.CreateSchema()) .MatchSnapshot(); }
public void Merge_ThreeObjectsWhereTwoAreIdentical_TwoTypesAfterMerge() { // arrange DocumentNode schema_a = Parser.Default.Parse("type A { b: String }"); DocumentNode schema_b = Parser.Default.Parse("type A { b(a: String): String }"); DocumentNode schema_c = Parser.Default.Parse("type A { b: String }"); var types = new List <ITypeInfo> { TypeInfo.Create( schema_a.Definitions.OfType <ITypeDefinitionNode>().First(), new SchemaInfo("Schema_A", schema_a)), TypeInfo.Create( schema_b.Definitions.OfType <ITypeDefinitionNode>().First(), new SchemaInfo("Schema_B", schema_b)), TypeInfo.Create( schema_c.Definitions.OfType <ITypeDefinitionNode>().First(), new SchemaInfo("Schema_C", schema_c)) }; var context = new SchemaMergeContext(); // act var typeMerger = new ObjectTypeMergeHandler((c, t) => { }); typeMerger.Merge(context, types); // assert SchemaSyntaxSerializer.Serialize(context.CreateSchema()) .MatchSnapshot(); }
public void Merge_SimpleIdenticalObjects_TypeMerges() { // arrange DocumentNode schema_a = Utf8GraphQLParser.Parse("type A { b: String }"); DocumentNode schema_b = Utf8GraphQLParser.Parse("type A { b: String }"); var types = new List <ITypeInfo> { TypeInfo.Create( schema_a.Definitions.OfType <ITypeDefinitionNode>().First(), new SchemaInfo("Schema_A", schema_a)), TypeInfo.Create( schema_b.Definitions.OfType <ITypeDefinitionNode>().First(), new SchemaInfo("Schema_B", schema_b)) }; var context = new SchemaMergeContext(); // act var typeMerger = new ObjectTypeMergeHandler((c, t) => { }); typeMerger.Merge(context, types); // assert context .CreateSchema() .Print() .MatchSnapshot(); }
public void Merge_SimpleIdenticalDirectives_TypeMerges() { // arrange DocumentNode schema_a = Parser.Default.Parse("directive @test(arg: String) on OBJECT"); DocumentNode schema_b = Parser.Default.Parse("directive @test(arg: String) on OBJECT"); var types = new List <IDirectiveTypeInfo> { new DirectiveTypeInfo(schema_a.Definitions.OfType <DirectiveDefinitionNode>().First(), new SchemaInfo("Schema_A", schema_a)), new DirectiveTypeInfo(schema_b.Definitions.OfType <DirectiveDefinitionNode>().First(), new SchemaInfo("Schema_B", schema_b)), }; var context = new SchemaMergeContext(); // act var typeMerger = new DirectiveTypeMergeHandler((c, t) => { }); typeMerger.Merge(context, types); // assert SchemaSyntaxSerializer.Serialize(context.CreateSchema()) .MatchSnapshot(); }
public void Merge_RootTypeWithCollisions_CollidingFieldsAreRenamed() { // arrange DocumentNode schema_a = Utf8GraphQLParser.Parse("type Query { a: String }"); DocumentNode schema_b = Utf8GraphQLParser.Parse("type Query { a: String }"); var types = new List <ITypeInfo> { TypeInfo.Create( schema_a.Definitions.OfType <ITypeDefinitionNode>().First(), new SchemaInfo("Schema_A", schema_a)), TypeInfo.Create( schema_b.Definitions.OfType <ITypeDefinitionNode>().First(), new SchemaInfo("Schema_B", schema_b)) }; var context = new SchemaMergeContext(); // act var typeMerger = new RootTypeMergeHandler((c, t) => { }); typeMerger.Merge(context, types); // assert SchemaSyntaxSerializer.Serialize(context.CreateSchema()) .MatchSnapshot(); }
public void Merge_SimpleIdenticalInputs_TypeMerges() { // arrange DocumentNode schema_a = Parser.Default.Parse("input A { b: String }"); DocumentNode schema_b = Parser.Default.Parse("input A { b: String }"); var types = new List<ITypeInfo> { TypeInfo.Create( schema_a.Definitions.OfType<ITypeDefinitionNode>().First(), new SchemaInfo("Schema_A", schema_a)), TypeInfo.Create( schema_b.Definitions.OfType<ITypeDefinitionNode>().First(), new SchemaInfo("Schema_B", schema_b)) }; var context = new SchemaMergeContext(); // act var typeMerger = new InputObjectTypeMergeHandler((c, t) => { }); typeMerger.Merge(context, types); // assert SchemaSyntaxSerializer.Serialize(context.CreateSchema()) .MatchSnapshot(); }
public void MergeNonIdenticalEnums() { // arrange DocumentNode schema_a = Utf8GraphQLParser.Parse("enum Foo { BAR BAZ }"); DocumentNode schema_b = Utf8GraphQLParser.Parse("enum Foo { BAR BAZ }"); DocumentNode schema_c = Utf8GraphQLParser.Parse("enum Foo { BAR BAZ QUX }"); var types = new List <ITypeInfo> { TypeInfo.Create( schema_a.Definitions.OfType <ITypeDefinitionNode>().First(), new SchemaInfo("Schema_A", schema_a)), TypeInfo.Create( schema_b.Definitions.OfType <ITypeDefinitionNode>().First(), new SchemaInfo("Schema_B", schema_b)), TypeInfo.Create( schema_c.Definitions.OfType <ITypeDefinitionNode>().First(), new SchemaInfo("Schema_C", schema_c)) }; var context = new SchemaMergeContext(); // act var typeMerger = new EnumTypeMergeHandler((c, t) => { }); typeMerger.Merge(context, types); // assert SchemaSyntaxSerializer.Serialize(context.CreateSchema()) .MatchSnapshot(); }
public void MergeIdenticalEnumsTakeDescriptionFromSecondType() { // arrange DocumentNode schema_a = Utf8GraphQLParser.Parse("enum Foo { BAR BAZ }"); DocumentNode schema_b = Utf8GraphQLParser.Parse(@"""Foo Bar"" enum Foo { BAR BAZ }"); var types = new List <ITypeInfo> { TypeInfo.Create( schema_a.Definitions.OfType <ITypeDefinitionNode>().First(), new SchemaInfo("Schema_A", schema_a)), TypeInfo.Create( schema_b.Definitions.OfType <ITypeDefinitionNode>().First(), new SchemaInfo("Schema_B", schema_b)) }; var context = new SchemaMergeContext(); // act var typeMerger = new EnumTypeMergeHandler((c, t) => { }); typeMerger.Merge(context, types); // assert context .CreateSchema() .Print() .MatchSnapshot(); }
public void Merge_ThreeDirectivessWhereTwoAreIdentical_TwoTypesAfterMerge() { // arrange DocumentNode schema_a = Utf8GraphQLParser.Parse( "directive @test(arg: String) on OBJECT"); DocumentNode schema_b = Utf8GraphQLParser.Parse( "directive @test1(arg: String) on OBJECT"); DocumentNode schema_c = Utf8GraphQLParser.Parse( "directive @test(arg: String) on OBJECT"); var types = new List <IDirectiveTypeInfo> { new DirectiveTypeInfo(schema_a.Definitions .OfType <DirectiveDefinitionNode>().First(), new SchemaInfo("Schema_A", schema_a)), new DirectiveTypeInfo(schema_b.Definitions .OfType <DirectiveDefinitionNode>().First(), new SchemaInfo("Schema_B", schema_b)), new DirectiveTypeInfo(schema_c.Definitions .OfType <DirectiveDefinitionNode>().First(), new SchemaInfo("Schema_C", schema_c)) }; var context = new SchemaMergeContext(); // act var typeMerger = new DirectiveTypeMergeHandler((c, t) => { }); typeMerger.Merge(context, types); // assert context .CreateSchema() .Print() .MatchSnapshot(); }
public void Merge_DifferentTypes_ObjectMergesLeftoversArePassed() { // arrange DocumentNode schema_a = Parser.Default.Parse("type A { b: String }"); DocumentNode schema_b = Parser.Default.Parse("enum A { B C }"); var types = new List <ITypeInfo> { TypeInfo.Create( schema_a.Definitions.OfType <ITypeDefinitionNode>().First(), new SchemaInfo("Schema_A", schema_a)), TypeInfo.Create( schema_b.Definitions.OfType <ITypeDefinitionNode>().First(), new SchemaInfo("Schema_B", schema_b)), }; var context = new SchemaMergeContext(); var leftovers = new List <ITypeInfo>(); // act var typeMerger = new ObjectTypeMergeHandler( (c, t) => leftovers.AddRange(t)); typeMerger.Merge(context, types); // assert Assert.Collection(leftovers, t => Assert.IsType <EnumTypeInfo>(t)); Snapshot.Match(new List <object> { SchemaSyntaxSerializer.Serialize(context.CreateSchema()), leftovers }); }
public void Merge_ThreeInterfWhereTwoAreIdentical_TwoTypesAfterMerge() { // arrange DocumentNode schema_a = Utf8GraphQLParser.Parse("interface A { b: String }"); DocumentNode schema_b = Utf8GraphQLParser.Parse("interface A { b(a: String): String }"); DocumentNode schema_c = Utf8GraphQLParser.Parse("interface A { b: String }"); var types = new List <ITypeInfo> { TypeInfo.Create( schema_a.Definitions.OfType <ITypeDefinitionNode>().First(), new SchemaInfo("Schema_A", schema_a)), TypeInfo.Create( schema_b.Definitions.OfType <ITypeDefinitionNode>().First(), new SchemaInfo("Schema_B", schema_b)), TypeInfo.Create( schema_c.Definitions.OfType <ITypeDefinitionNode>().First(), new SchemaInfo("Schema_C", schema_c)) }; var context = new SchemaMergeContext(); // act var typeMerger = new InterfaceTypeMergeHandler((c, t) => { }); typeMerger.Merge(context, types); // assert context .CreateSchema() .Print() .MatchSnapshot(); }