Esempio 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();
        }
Esempio 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"));
        }
Esempio 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"));
        }
Esempio 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();
        }
Esempio 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();
        }
Esempio 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();
        }
Esempio 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();
        }
Esempio 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();
        }
Esempio 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();
        }
Esempio 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();
        }
Esempio 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();
        }
Esempio 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();
        }
Esempio 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();
        }
Esempio 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();
        }
Esempio 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();
        }
Esempio 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();
        }
Esempio 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"));
        }
Esempio 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();
        }
Esempio 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();
        }