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 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();
        }
Exemplo n.º 3
0
        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_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
            });
        }