Ejemplo n.º 1
0
        public void MergeTypeWithCustomRule()
        {
            // arrange
            DocumentNode schema_a =
                Utf8GraphQLParser.Parse("type Foo { a: String }");
            DocumentNode schema_b =
                Utf8GraphQLParser.Parse("type Foo { b: String }");

            // act
            DocumentNode a = SchemaMerger.New()
                             .AddSchema("A", schema_a)
                             .AddSchema("B", schema_b)
                             .AddTypeMergeRule(next => (context, types) =>
            {
                var typeInfos = types.OfType <ObjectTypeInfo>().ToArray();
                var fields    = typeInfos[0].Definition.Fields.ToList();
                fields.AddRange(typeInfos[1].Definition.Fields);
                context.AddType(
                    typeInfos[0].Definition.WithFields(fields));
            })
                             .Merge();

            // assert
            SchemaSyntaxSerializer.Serialize(a).MatchSnapshot();
        }
Ejemplo n.º 2
0
        public void LastFieldRenameWins()
        {
            // arrange
            DocumentNode schema_a =
                Utf8GraphQLParser.Parse(
                    "type A { b1: B } " +
                    "type B implements D { c: String } " +
                    "type C implements D { c: String } " +
                    "interface D { c: String }");

            DocumentNode schema_b =
                Utf8GraphQLParser.Parse(
                    "type B { b1: String b3: String } type C { c: String }");

            // act
            DocumentNode a = SchemaMerger.New()
                             .AddSchema("A", schema_a)
                             .AddSchema("B", schema_b)
                             .RenameField(new FieldReference("B", "c"), "c123", "A")
                             .RenameField(new FieldReference("C", "c"), "c456", "A")
                             .RenameField(new FieldReference("D", "c"), "c789", "A")
                             .Merge();

            DocumentNode b = SchemaMerger.New()
                             .AddSchema("A", schema_a)
                             .AddSchema("B", schema_b)
                             .RenameField(new FieldReference("B", "c"), "c123", "A")
                             .RenameField(new FieldReference("D", "c"), "c789", "A")
                             .RenameField(new FieldReference("C", "c"), "c456", "A")
                             .Merge();

            // assert
            a.Print().MatchSnapshot(SnapshotNameExtension.Create("A"));
            b.Print().MatchSnapshot(SnapshotNameExtension.Create("B"));
        }
Ejemplo n.º 3
0
        public void RenameReferencingType()
        {
            // arrange
            DocumentNode schema_a =
                Utf8GraphQLParser.Parse(
                    "type A { b1: B } " +
                    "type B implements C { c: String } " +
                    "interface C { c: String }");

            DocumentNode schema_b =
                Utf8GraphQLParser.Parse(
                    "type B { b1: String b3: String } type C { c: String }");

            // act
            DocumentNode a = SchemaMerger.New()
                             .AddSchema("A", schema_a)
                             .AddSchema("B", schema_b)
                             .RenameType("A", "B", "Foo")
                             .Merge();

            DocumentNode b = SchemaMerger.New()
                             .AddSchema("B", schema_b)
                             .AddSchema("A", schema_a)
                             .RenameType("A", "B", "Foo")
                             .Merge();

            // assert
            SchemaSyntaxSerializer.Serialize(a).MatchSnapshot(
                SnapshotNameExtension.Create("A"));
            SchemaSyntaxSerializer.Serialize(b).MatchSnapshot(
                SnapshotNameExtension.Create("B"));
        }
Ejemplo n.º 4
0
        public void MergeSimpleSchemaWithDefaultHandler()
        {
            // arrange
            DocumentNode schema_a =
                Utf8GraphQLParser.Parse("union Foo = Bar | Baz union A = B | C");
            DocumentNode schema_b =
                Utf8GraphQLParser.Parse("union Foo = Bar | Baz");

            // act
            DocumentNode schema = SchemaMerger.New()
                                  .AddSchema("A", schema_a)
                                  .AddSchema("B", schema_b)
                                  .Merge();

            // assert
            SchemaSyntaxSerializer.Serialize(schema).MatchSnapshot();
        }
Ejemplo n.º 5
0
        public void MergeTypeWithCustomHandler()
        {
            // arrange
            DocumentNode schema_a =
                Utf8GraphQLParser.Parse("type Foo { a: String }");
            DocumentNode schema_b =
                Utf8GraphQLParser.Parse("type Foo { b: String }");

            // act
            DocumentNode a = SchemaMerger.New()
                             .AddSchema("A", schema_a)
                             .AddSchema("B", schema_b)
                             .AddTypeMergeHandler <CustomTypeMergeHandler>()
                             .Merge();

            // assert
            SchemaSyntaxSerializer.Serialize(a).MatchSnapshot();
        }
Ejemplo n.º 6
0
        public void MergeDirectivesWithCustomHandler()
        {
            // arrange
            DocumentNode schema_a =
                Utf8GraphQLParser.Parse("directive @foo on FIELD");
            DocumentNode schema_b =
                Utf8GraphQLParser.Parse("directive @foo(a: String) on FIELD");

            // act
            DocumentNode a = SchemaMerger.New()
                             .AddSchema("A", schema_a)
                             .AddSchema("B", schema_b)
                             .AddDirectiveMergeHandler <CustomDirectiveMergeHandler>()
                             .Merge();

            // assert
            SchemaSyntaxSerializer.Serialize(a).MatchSnapshot();
        }
Ejemplo n.º 7
0
        public void Rename_Type_With_Various_Variants()
        {
            // arrange
            DocumentNode initial =
                Utf8GraphQLParser.Parse(
                    "type A { b1: B! b2: [B!] b3: [B] b4: [B!]! } " +
                    "type B implements C { c: String } " +
                    "interface C { c: String }");

            // act
            DocumentNode merged = SchemaMerger.New()
                                  .AddSchema("A", initial)
                                  .RenameType("A", "B", "Foo")
                                  .Merge();

            // assert
            SchemaSyntaxSerializer.Serialize(merged).MatchSnapshot();
        }
Ejemplo n.º 8
0
        public void MergeDemoSchemaWithDefaultHandler()
        {
            // arrange
            DocumentNode schema_a =
                Utf8GraphQLParser.Parse(
                    FileResource.Open("Contract.graphql"));
            DocumentNode schema_b =
                Utf8GraphQLParser.Parse(
                    FileResource.Open("Customer.graphql"));

            // act
            DocumentNode schema = SchemaMerger.New()
                                  .AddSchema("A", schema_a)
                                  .AddSchema("B", schema_b)
                                  .Merge();

            // assert
            SchemaSyntaxSerializer.Serialize(schema).MatchSnapshot();
        }
Ejemplo n.º 9
0
        public void FieldDefinitionDoesNotHaveSameTypeShape()
        {
            // arrange
            DocumentNode schema_a =
                Utf8GraphQLParser.Parse(
                    "type A { b1: String b2: String } type B { c: String! }");
            DocumentNode schema_b =
                Utf8GraphQLParser.Parse(
                    "type A { b1: String b3: String } type B { c: String }");

            // act
            DocumentNode merged = SchemaMerger.New()
                                  .AddSchema("A", schema_a)
                                  .AddSchema("B", schema_b)
                                  .Merge();

            // assert
            SchemaSyntaxSerializer.Serialize(merged).MatchSnapshot();
        }
Ejemplo n.º 10
0
        public void MergeSchemaAndRenameFieldB1toB11OnSchemaA()
        {
            // arrange
            DocumentNode schema_a =
                Utf8GraphQLParser.Parse(
                    "type A { b1: String b2: String } type B { c: String }");
            DocumentNode schema_b =
                Utf8GraphQLParser.Parse(
                    "type A { b1: String b3: String } type B { c: String }");

            // act
            DocumentNode schema = SchemaMerger.New()
                                  .AddSchema("A", schema_a)
                                  .AddSchema("B", schema_b)
                                  .RenameField("A", new FieldReference("A", "b1"), "b11")
                                  .Merge();

            // assert
            SchemaSyntaxSerializer.Serialize(schema).MatchSnapshot();
        }
Ejemplo n.º 11
0
        public void MergeSchemaAndRemoveTypeAOnSchemaA()
        {
            // arrange
            DocumentNode schema_a =
                Utf8GraphQLParser.Parse(
                    "type A { b1: String } type B { c: String }");
            DocumentNode schema_b =
                Utf8GraphQLParser.Parse(
                    "type A { b2: String } type B { c: String }");

            // act
            DocumentNode schema = SchemaMerger.New()
                                  .AddSchema("A", schema_a)
                                  .AddSchema("B", schema_b)
                                  .IgnoreType("A", "A")
                                  .Merge();

            // assert
            SchemaSyntaxSerializer.Serialize(schema).MatchSnapshot();
        }
Ejemplo n.º 12
0
        public void MergeSchemaAndRemoveFieldB1OnSchemaA()
        {
            // arrange
            DocumentNode schema_a =
                Parser.Default.Parse(
                    "type A { b1: String b2: String } type B { c: String }");
            DocumentNode schema_b =
                Parser.Default.Parse(
                    "type A { b1: String b3: String } type B { c: String }");

            // act
            DocumentNode schema = SchemaMerger.New()
                                  .AddSchema("A", schema_a)
                                  .AddSchema("B", schema_b)
                                  .IgnoreField("A", new FieldReference("A", "b1"))
                                  .Merge();

            // assert
            SchemaSyntaxSerializer.Serialize(schema).MatchSnapshot();
        }
Ejemplo n.º 13
0
        public void MergeSchemaAndRenameTypeAtoXyzOnAllSchemas()
        {
            // arrange
            DocumentNode schema_a =
                Utf8GraphQLParser.Parse(
                    "type A { b1: String b2: String } type B { c: String }");
            DocumentNode schema_b =
                Utf8GraphQLParser.Parse(
                    "type A { b1: String b3: String } type B { c: String }");

            // act
            DocumentNode schema = SchemaMerger.New()
                                  .AddSchema("A", schema_a)
                                  .AddSchema("B", schema_b)
                                  .RenameType("A", "Xyz")
                                  .Merge();

            // assert
            SchemaSyntaxSerializer.Serialize(schema).MatchSnapshot();
        }
Ejemplo n.º 14
0
        public void MergeSchemaAndRemoveFieldB1OnSchemaA()
        {
            // arrange
            DocumentNode schema_a =
                Utf8GraphQLParser.Parse(
                    "type A { b1: String b2: String } type B { c: String }");
            DocumentNode schema_b =
                Utf8GraphQLParser.Parse(
                    "type A { b1: String b3: String } type B { c: String }");

            // act
            DocumentNode schema = SchemaMerger.New()
                                  .AddSchema("A", schema_a)
                                  .AddSchema("B", schema_b)
                                  .IgnoreField(new FieldReference("A", "b1"), "A")
                                  .Merge();

            // assert
            schema.Print().MatchSnapshot();
        }
Ejemplo n.º 15
0
        public void MergeDemoSchemaAndRemoveRootTypesOnSchemaA()
        {
            // arrange
            DocumentNode schema_a =
                Utf8GraphQLParser.Parse(
                    FileResource.Open("Contract.graphql"));
            DocumentNode schema_b =
                Utf8GraphQLParser.Parse(
                    FileResource.Open("Customer.graphql"));

            // act
            DocumentNode schema = SchemaMerger.New()
                                  .AddSchema("A", schema_a)
                                  .AddSchema("B", schema_b)
                                  .IgnoreRootTypes("A")
                                  .Merge();

            // assert
            SchemaSyntaxSerializer.Serialize(schema).MatchSnapshot();
        }
Ejemplo n.º 16
0
        public void MergeDirectivesWithCustomRule()
        {
            // arrange
            DocumentNode schema_a =
                Utf8GraphQLParser.Parse("directive @foo on FIELD");
            DocumentNode schema_b =
                Utf8GraphQLParser.Parse("directive @foo(a: String) on FIELD");

            // act
            DocumentNode a = SchemaMerger.New()
                             .AddSchema("A", schema_a)
                             .AddSchema("B", schema_b)
                             .AddDirectiveMergeRule(next => (context, directives) =>
            {
                context.AddDirective(
                    directives.First(t =>
                                     t.Definition.Arguments.Any()).Definition);
            })
                             .Merge();

            // assert
            SchemaSyntaxSerializer.Serialize(a).MatchSnapshot();
        }
Ejemplo n.º 17
0
        public void LastFieldRenameWins()
        {
            // arrange
            DocumentNode schema_a =
                Parser.Default.Parse(
                    "type A { b1: B } " +
                    "type B implements D { c: String } " +
                    "type C implements D { c: String } " +
                    "interface D { c: String }");

            DocumentNode schema_b =
                Parser.Default.Parse(
                    "type B { b1: String b3: String } type C { c: String }");

            // act
            DocumentNode a = SchemaMerger.New()
                             .AddSchema("A", schema_a)
                             .AddSchema("B", schema_b)
                             .RenameField("A", new FieldReference("B", "c"), "c123")
                             .RenameField("A", new FieldReference("C", "c"), "c456")
                             .RenameField("A", new FieldReference("D", "c"), "c789")
                             .Merge();

            DocumentNode b = SchemaMerger.New()
                             .AddSchema("A", schema_a)
                             .AddSchema("B", schema_b)
                             .RenameField("A", new FieldReference("B", "c"), "c123")
                             .RenameField("A", new FieldReference("D", "c"), "c789")
                             .RenameField("A", new FieldReference("C", "c"), "c456")
                             .Merge();

            // assert
            SchemaSyntaxSerializer.Serialize(a).MatchSnapshot(
                SnapshotNameExtension.Create("A"));
            SchemaSyntaxSerializer.Serialize(b).MatchSnapshot(
                SnapshotNameExtension.Create("B"));
        }
Ejemplo n.º 18
0
        public void RenameObjectFieldThatImplementsInterface()
        {
            // arrange
            DocumentNode schema_a =
                Utf8GraphQLParser.Parse(
                    "type A { b1: B } " +
                    "type B implements D { c: String } " +
                    "type C implements D { c: String } " +
                    "interface D { c: String }");

            DocumentNode schema_b =
                Utf8GraphQLParser.Parse(
                    "type B { b1: String b3: String } type C { c: String }");

            // act
            DocumentNode a = SchemaMerger.New()
                             .AddSchema("A", schema_a)
                             .AddSchema("B", schema_b)
                             .RenameField(new FieldReference("B", "c"), "c123", "A")
                             .Merge();

            // assert
            a.Print().MatchSnapshot();
        }
Ejemplo n.º 19
0
        public void RenameInterfaceField()
        {
            // arrange
            DocumentNode schema_a =
                Utf8GraphQLParser.Parse(
                    "type A { b1: B } " +
                    "type B implements D { c: String } " +
                    "type C implements D { c: String } " +
                    "interface D { c: String }");

            DocumentNode schema_b =
                Utf8GraphQLParser.Parse(
                    "type B { b1: String b3: String } type C { c: String }");

            // act
            DocumentNode a = SchemaMerger.New()
                             .AddSchema("A", schema_a)
                             .AddSchema("B", schema_b)
                             .RenameField("A", new FieldReference("D", "c"), "c123")
                             .Merge();

            // assert
            SchemaSyntaxSerializer.Serialize(a).MatchSnapshot();
        }