Esempio n. 1
0
        public void Different_args_second_adds_an_argument_should_fail()
        {
            const string query = @"
                fragment conflictingArgs on Dog {
                    doesKnowCommand
                    doesKnowCommand(dogCommand: HEEL)
                }
            ";

            ShouldFailRule(config =>
            {
                config.Query = query;
                config.Error(e =>
                {
                    e.Message = OverlappingFieldsCanBeMergedError.FieldsConflictMessage("doesKnowCommand", new OverlappingFieldsCanBeMerged.ConflictReason
                    {
                        Message = new OverlappingFieldsCanBeMerged.Message
                        {
                            Msg = "they have differing arguments"
                        }
                    });
                    e.Locations.Add(new ErrorLocation {
                        Line = 3, Column = 21
                    });
                    e.Locations.Add(new ErrorLocation {
                        Line = 4, Column = 21
                    });
                });
            });
        }
        public void Encounters_conflict_in_fragments_should_fail()
        {
            const string query = @"
                {
                    ...A
                    ...B
                }
                fragment A on Type {
                    x: a
                }
                fragment B on Type {
                    x: b
                }
            ";

            ShouldFailRule(config =>
            {
                config.Query = query;
                config.Error(e =>
                {
                    e.Message = OverlappingFieldsCanBeMergedError.FieldsConflictMessage("x", new OverlappingFieldsCanBeMerged.ConflictReason
                    {
                        Message = new OverlappingFieldsCanBeMerged.Message
                        {
                            Msg = "a and b are different fields"
                        }
                    });
                    e.Locations.Add(new ErrorLocation(7, 21));
                    e.Locations.Add(new ErrorLocation(10, 21));
                });
            });
        }
        public void Disallows_differing_return_type_nullability_despite_no_overlap()
        {
            ISchema schema = new ResultTypeValidationSchema();

            const string query = @"
                {
                    someBox {
                        ... on NonNullStringBox1 {
                            scalar
                        }
                        ... on StringBox {
                            scalar
                        }
                    }
                }
            ";

            ShouldFailRule(config =>
            {
                config.Schema = schema;
                config.Query  = query;
                config.Error(e =>
                {
                    e.Message = OverlappingFieldsCanBeMergedError.FieldsConflictMessage("scalar", new OverlappingFieldsCanBeMerged.ConflictReason
                    {
                        Message = new OverlappingFieldsCanBeMerged.Message
                        {
                            Msg = "they return conflicting types String! and String"
                        }
                    });
                    e.Locations.Add(new ErrorLocation(5, 29));
                    e.Locations.Add(new ErrorLocation(8, 29));
                });
            });
        }
        public void Conflicting_return_types_which_potentially_overlap()
        {
            ISchema schema = new ResultTypeValidationSchema();

            const string query = @"
                {
                    someBox {
                        ...on IntBox {
                            scalar
                        }
                        ...on NonNullStringBox1 {
                            scalar
                        }
                    }
                }
            ";

            ShouldFailRule(config =>
            {
                config.Schema = schema;
                config.Query  = query;
                config.Error(e =>
                {
                    e.Message = OverlappingFieldsCanBeMergedError.FieldsConflictMessage("scalar", new OverlappingFieldsCanBeMerged.ConflictReason
                    {
                        Message = new OverlappingFieldsCanBeMerged.Message
                        {
                            Msg = "they return conflicting types Int and String!"
                        }
                    });
                    e.Locations.Add(new ErrorLocation(5, 29));
                    e.Locations.Add(new ErrorLocation(8, 29));
                });
            });
        }
        public void Conflicting_args_should_fail()
        {
            const string query = @"
                fragment conflictingArgs on Dog {
                    doesKnowCommand(dogCommand: SIT)
                    doesKnowCommand(dogCommand: HEEL)
                }
            ";

            ShouldFailRule(config =>
            {
                config.Query = query;
                config.Error(e =>
                {
                    e.Message = OverlappingFieldsCanBeMergedError.FieldsConflictMessage("doesKnowCommand", new OverlappingFieldsCanBeMerged.ConflictReason
                    {
                        Message = new OverlappingFieldsCanBeMerged.Message
                        {
                            Msg = "they have differing arguments"
                        }
                    });
                    e.Locations.Add(new ErrorLocation(3, 21));
                    e.Locations.Add(new ErrorLocation(4, 21));
                });
            });
        }
        public void Finds_invalid_case_even_with_immediately_recursive_fragment()
        {
            const string query = @"
                fragment sameAliasesWithDifferentFieldTargets on Dog {
                    ...sameAliasesWithDifferentFieldTargets
                    fido: name
                    fido: nickname
                }
            ";

            ShouldFailRule(config =>
            {
                config.Query = query;
                config.Error(e =>
                {
                    e.Message = OverlappingFieldsCanBeMergedError.FieldsConflictMessage("fido", new OverlappingFieldsCanBeMerged.ConflictReason
                    {
                        Message = new OverlappingFieldsCanBeMerged.Message
                        {
                            Msg = "name and nickname are different fields"
                        }
                    });
                    e.Locations.Add(new ErrorLocation(4, 21));
                    e.Locations.Add(new ErrorLocation(5, 21));
                });
            });
        }
        public void Alias_masking_direct_field_access_should_fail()
        {
            const string query = @"
                fragment aliasMaskingDirectFieldAccess on Dog {
                    name: nickname
                    name
                }
            ";

            ShouldFailRule(config =>
            {
                config.Query = query;
                config.Error(e =>
                {
                    e.Message = OverlappingFieldsCanBeMergedError.FieldsConflictMessage("name", new OverlappingFieldsCanBeMerged.ConflictReason
                    {
                        Message = new OverlappingFieldsCanBeMerged.Message
                        {
                            Msg = "nickname and name are different fields"
                        }
                    });
                    e.Locations.Add(new ErrorLocation(3, 21));
                    e.Locations.Add(new ErrorLocation(4, 21));
                });
            });
        }
        public void Same_aliases_with_different_field_targets_should_fail()
        {
            const string query = @"
                fragment sameAliasesWithDifferentFieldTargets on Dog {
                    fido: name
                    fido: nickname
                }
            ";

            ShouldFailRule(config =>
            {
                config.Query = query;
                config.Error(e =>
                {
                    e.Message = OverlappingFieldsCanBeMergedError.FieldsConflictMessage("fido", new OverlappingFieldsCanBeMerged.ConflictReason
                    {
                        Message = new OverlappingFieldsCanBeMerged.Message
                        {
                            Msg = "name and nickname are different fields"
                        }
                    });
                    e.Locations.Add(new ErrorLocation(3, 21));
                    e.Locations.Add(new ErrorLocation(4, 21));
                });
            });
        }
Esempio n. 9
0
        public void Disallows_differing_deep_return_types_despite_no_overlap()
        {
            ISchema schema = new ResultTypeValidationSchema();

            const string query = @"
                {
                    someBox {
                        ... on IntBox {
                            box: stringBox {
                                scalar
                            }
                        }
                        ... on StringBox {
                            box: intBox {
                                scalar
                            }
                        }
                    }
                }
            ";

            ShouldFailRule(config =>
            {
                config.Schema = schema;
                config.Query  = query;
                config.Error(e =>
                {
                    e.Message = OverlappingFieldsCanBeMergedError.FieldsConflictMessage("box", new OverlappingFieldsCanBeMerged.ConflictReason
                    {
                        Message = new OverlappingFieldsCanBeMerged.Message
                        {
                            Msgs = new List <OverlappingFieldsCanBeMerged.ConflictReason>
                            {
                                new OverlappingFieldsCanBeMerged.ConflictReason
                                {
                                    Name    = "scalar",
                                    Message = new OverlappingFieldsCanBeMerged.Message
                                    {
                                        Msg = "they return conflicting types String and Int"
                                    }
                                }
                            }
                        }
                    });
                    e.Locations.Add(new ErrorLocation {
                        Line = 5, Column = 29
                    });
                    e.Locations.Add(new ErrorLocation {
                        Line = 6, Column = 33
                    });
                    e.Locations.Add(new ErrorLocation {
                        Line = 10, Column = 29
                    });
                    e.Locations.Add(new ErrorLocation {
                        Line = 11, Column = 33
                    });
                });
            });
        }
        public void Very_deep_conflict_should_fail()
        {
            const string query = @"
                {
                    field {
                        deepField {
                            x: a
                        }
                    },
                    field {
                        deepField {
                            x: b
                        }
                    }
                }
            ";

            ShouldFailRule(config =>
            {
                config.Query = query;
                config.Error(e =>
                {
                    e.Message = OverlappingFieldsCanBeMergedError.FieldsConflictMessage("field", new OverlappingFieldsCanBeMerged.ConflictReason
                    {
                        Message = new OverlappingFieldsCanBeMerged.Message
                        {
                            Msgs = new List <OverlappingFieldsCanBeMerged.ConflictReason>
                            {
                                new OverlappingFieldsCanBeMerged.ConflictReason
                                {
                                    Name    = "deepField",
                                    Message = new OverlappingFieldsCanBeMerged.Message
                                    {
                                        Msgs = new List <OverlappingFieldsCanBeMerged.ConflictReason>
                                        {
                                            new OverlappingFieldsCanBeMerged.ConflictReason
                                            {
                                                Name    = "x",
                                                Message = new OverlappingFieldsCanBeMerged.Message
                                                {
                                                    Msg = "a and b are different fields"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    });
                    e.Locations.Add(new ErrorLocation(3, 21));
                    e.Locations.Add(new ErrorLocation(4, 25));
                    e.Locations.Add(new ErrorLocation(5, 29));
                    e.Locations.Add(new ErrorLocation(8, 21));
                    e.Locations.Add(new ErrorLocation(9, 25));
                    e.Locations.Add(new ErrorLocation(10, 29));
                });
            });
        }
        public void Reports_deep_conflict_to_nearest_common_ancestor_in_fragments()
        {
            const string query = @"
                {
                    field {
                        ...F
                    }
                    field {
                        ...F
                    }
                }
                fragment F on T {
                    deepField {
                        deeperField {
                            x: a
                        }
                        deeperField {
                            x: b
                        }
                    },
                    deepField {
                        deeperField {
                            y
                        }
                    }
                }
            ";

            ShouldFailRule(config =>
            {
                config.Query = query;
                config.Error(e =>
                {
                    e.Message = OverlappingFieldsCanBeMergedError.FieldsConflictMessage("deeperField", new OverlappingFieldsCanBeMerged.ConflictReason
                    {
                        Message = new OverlappingFieldsCanBeMerged.Message
                        {
                            Msgs = new List <OverlappingFieldsCanBeMerged.ConflictReason>
                            {
                                new OverlappingFieldsCanBeMerged.ConflictReason
                                {
                                    Name    = "x",
                                    Message = new OverlappingFieldsCanBeMerged.Message
                                    {
                                        Msg = "a and b are different fields"
                                    }
                                }
                            }
                        }
                    });
                    e.Locations.Add(new ErrorLocation(12, 25));
                    e.Locations.Add(new ErrorLocation(13, 29));
                    e.Locations.Add(new ErrorLocation(15, 25));
                    e.Locations.Add(new ErrorLocation(16, 29));
                });
            });
        }
Esempio n. 12
0
        public void Reports_deep_conflict_to_nearest_common_ancestor_should_fail()
        {
            const string query = @"
                {
                    field {
                        deepField {
                            x: a
                        }
                        deepField {
                            x: b
                        }
                    },
                    field {
                        deepField {
                            y
                        }
                    }
                }
            ";

            ShouldFailRule(config =>
            {
                config.Query = query;
                config.Error(e =>
                {
                    e.Message = OverlappingFieldsCanBeMergedError.FieldsConflictMessage("deepField", new OverlappingFieldsCanBeMerged.ConflictReason
                    {
                        Message = new OverlappingFieldsCanBeMerged.Message
                        {
                            Msgs = new List <OverlappingFieldsCanBeMerged.ConflictReason>
                            {
                                new OverlappingFieldsCanBeMerged.ConflictReason
                                {
                                    Name    = "x",
                                    Message = new OverlappingFieldsCanBeMerged.Message
                                    {
                                        Msg = "a and b are different fields"
                                    }
                                }
                            }
                        }
                    });
                    e.Locations.Add(new ErrorLocation {
                        Line = 4, Column = 25
                    });
                    e.Locations.Add(new ErrorLocation {
                        Line = 5, Column = 29
                    });
                    e.Locations.Add(new ErrorLocation {
                        Line = 7, Column = 25
                    });
                    e.Locations.Add(new ErrorLocation {
                        Line = 8, Column = 29
                    });
                });
            });
        }
        public void Deep_conflict_with_multiple_issues_should_fail()
        {
            const string query = @"
                {
                    field {
                        x: a
                        y: c
                    },
                    field {
                        x: b
                        y: d
                    }
                }
            ";

            ShouldFailRule(config =>
            {
                config.Query = query;
                config.Error(e =>
                {
                    e.Message = OverlappingFieldsCanBeMergedError.FieldsConflictMessage("field", new OverlappingFieldsCanBeMerged.ConflictReason
                    {
                        Message = new OverlappingFieldsCanBeMerged.Message
                        {
                            Msgs = new List <OverlappingFieldsCanBeMerged.ConflictReason>
                            {
                                new OverlappingFieldsCanBeMerged.ConflictReason
                                {
                                    Name    = "x",
                                    Message = new OverlappingFieldsCanBeMerged.Message
                                    {
                                        Msg = "a and b are different fields"
                                    }
                                },
                                new OverlappingFieldsCanBeMerged.ConflictReason
                                {
                                    Name    = "y",
                                    Message = new OverlappingFieldsCanBeMerged.Message
                                    {
                                        Msg = "c and d are different fields"
                                    }
                                }
                            }
                        }
                    });
                    e.Locations.Add(new ErrorLocation(3, 21));
                    e.Locations.Add(new ErrorLocation(4, 25));
                    e.Locations.Add(new ErrorLocation(5, 25));
                    e.Locations.Add(new ErrorLocation(7, 21));
                    e.Locations.Add(new ErrorLocation(8, 25));
                    e.Locations.Add(new ErrorLocation(9, 25));
                });
            });
        }
Esempio n. 14
0
        public void Deep_conflict()
        {
            const string query = @"
                {
                    field {
                        x: a
                    },
                    field {
                        x: b
                    }
                }
            ";

            ShouldFailRule(config =>
            {
                config.Query = query;
                config.Error(e =>
                {
                    e.Message = OverlappingFieldsCanBeMergedError.FieldsConflictMessage("field", new OverlappingFieldsCanBeMerged.ConflictReason
                    {
                        Message = new OverlappingFieldsCanBeMerged.Message
                        {
                            Msgs = new List <OverlappingFieldsCanBeMerged.ConflictReason>
                            {
                                new OverlappingFieldsCanBeMerged.ConflictReason
                                {
                                    Name    = "x",
                                    Message = new OverlappingFieldsCanBeMerged.Message
                                    {
                                        Msg = "a and b are different fields"
                                    }
                                }
                            }
                        }
                    });
                    e.Locations.Add(new ErrorLocation {
                        Line = 3, Column = 21
                    });
                    e.Locations.Add(new ErrorLocation {
                        Line = 4, Column = 25
                    });
                    e.Locations.Add(new ErrorLocation {
                        Line = 6, Column = 21
                    });
                    e.Locations.Add(new ErrorLocation {
                        Line = 7, Column = 25
                    });
                });
            });
        }
Esempio n. 15
0
        public void Disallows_differing_subfields()
        {
            ISchema schema = new ResultTypeValidationSchema();

            const string query = @"
                {
                    someBox {
                        ... on IntBox {
                            box: stringBox {
                                val: scalar
                                val: unrelatedField
                            }
                        }
                        ... on StringBox {
                            box: stringBox {
                                val: scalar
                            }
                        }
                    }
                }
            ";

            ShouldFailRule(config =>
            {
                config.Schema = schema;
                config.Query  = query;
                config.Error(e =>
                {
                    e.Message = OverlappingFieldsCanBeMergedError.FieldsConflictMessage("val", new OverlappingFieldsCanBeMerged.ConflictReason
                    {
                        Message = new OverlappingFieldsCanBeMerged.Message
                        {
                            Msg = "scalar and unrelatedField are different fields"
                        }
                    });
                    e.Locations.Add(new ErrorLocation {
                        Line = 6, Column = 33
                    });
                    e.Locations.Add(new ErrorLocation {
                        Line = 7, Column = 33
                    });
                });
            });
        }
        public void Reports_correctly_when_a_non_exclusive_follows_an_exclusive()
        {
            ISchema schema = new ResultTypeValidationSchema();

            const string query = @"
                {
                    someBox {
                        ... on IntBox {
                            deepBox {
                                ...X
                            }
                        }
                    }
                    someBox {
                        ... on StringBox {
                            deepBox {
                                ...Y
                            }
                        }
                    }
                    memoed: someBox {
                        ... on IntBox {
                            deepBox {
                                ...X
                            }
                        }
                    }
                    memoed: someBox {
                        ... on StringBox {
                            deepBox {
                                ...Y
                            }
                        }
                    }
                    other: someBox {
                        ...X
                    }
                    other: someBox {
                        ...Y
                    }
                }
                fragment X on SomeBox {
                    scalar
                }
                fragment Y on SomeBox {
                    scalar: unrelatedField
                }
            ";

            ShouldFailRule(config =>
            {
                config.Schema = schema;
                config.Query  = query;
                config.Error(e =>
                {
                    e.Message = OverlappingFieldsCanBeMergedError.FieldsConflictMessage("other", new OverlappingFieldsCanBeMerged.ConflictReason
                    {
                        Message = new OverlappingFieldsCanBeMerged.Message
                        {
                            Msgs = new List <OverlappingFieldsCanBeMerged.ConflictReason>
                            {
                                new OverlappingFieldsCanBeMerged.ConflictReason
                                {
                                    Name    = "scalar",
                                    Message = new OverlappingFieldsCanBeMerged.Message
                                    {
                                        Msg = "scalar and unrelatedField are different fields"
                                    }
                                }
                            }
                        }
                    });
                    e.Locations.Add(new ErrorLocation(31, 21));
                    e.Locations.Add(new ErrorLocation(39, 21));
                    e.Locations.Add(new ErrorLocation(34, 21));
                    e.Locations.Add(new ErrorLocation(42, 21));
                });
            });
        }
        public void Reports_deep_conflict_in_nested_fragments()
        {
            const string query = @"
                {
                    field {
                        ...F
                    }
                    field {
                        ...I
                    }
                }
                fragment F on T {
                    x: a
                    ...G
                }
                fragment G on T {
                    y: c
                }
                fragment I on T {
                    y: d
                    ...J
                }
                fragment J on T {
                    x: b
                }
            ";

            ShouldFailRule(config =>
            {
                config.Query = query;
                config.Error(e =>
                {
                    e.Message = OverlappingFieldsCanBeMergedError.FieldsConflictMessage("field", new OverlappingFieldsCanBeMerged.ConflictReason
                    {
                        Message = new OverlappingFieldsCanBeMerged.Message
                        {
                            Msgs = new List <OverlappingFieldsCanBeMerged.ConflictReason>
                            {
                                new OverlappingFieldsCanBeMerged.ConflictReason
                                {
                                    Name    = "x",
                                    Message = new OverlappingFieldsCanBeMerged.Message
                                    {
                                        Msg = "a and b are different fields"
                                    }
                                },
                                new OverlappingFieldsCanBeMerged.ConflictReason
                                {
                                    Name    = "y",
                                    Message = new OverlappingFieldsCanBeMerged.Message
                                    {
                                        Msg = "c and d are different fields"
                                    }
                                }
                            }
                        }
                    });
                    e.Locations.Add(new ErrorLocation(3, 21));
                    e.Locations.Add(new ErrorLocation(11, 21));
                    e.Locations.Add(new ErrorLocation(15, 21));
                    e.Locations.Add(new ErrorLocation(6, 21));
                    e.Locations.Add(new ErrorLocation(22, 21));
                    e.Locations.Add(new ErrorLocation(18, 21));
                });
            });
        }
        public void Reports_each_conflict_once_should_fail()
        {
            const string query = @"
                {
                    f1 {
                        ...A
                        ...B
                    }
                    f2 {
                        ...B
                        ...A
                    }
                    f3 {
                        ...A
                        ...B
                        x: c
                    }
                }
                fragment A on Type {
                    x: a
                }
                fragment B on Type {
                    x: b
                }
            ";

            ShouldFailRule(config =>
            {
                config.Query = query;
                config.Error(e =>
                {
                    e.Message = OverlappingFieldsCanBeMergedError.FieldsConflictMessage("x", new OverlappingFieldsCanBeMerged.ConflictReason
                    {
                        Message = new OverlappingFieldsCanBeMerged.Message
                        {
                            Msg = "a and b are different fields"
                        }
                    });
                    e.Locations.Add(new ErrorLocation(18, 21));
                    e.Locations.Add(new ErrorLocation(21, 21));
                });

                config.Error(e =>
                {
                    e.Message = OverlappingFieldsCanBeMergedError.FieldsConflictMessage("x", new OverlappingFieldsCanBeMerged.ConflictReason
                    {
                        Message = new OverlappingFieldsCanBeMerged.Message
                        {
                            Msg = "c and a are different fields"
                        }
                    });
                    e.Locations.Add(new ErrorLocation(14, 25));
                    e.Locations.Add(new ErrorLocation(18, 21));
                });

                config.Error(e =>
                {
                    e.Message = OverlappingFieldsCanBeMergedError.FieldsConflictMessage("x", new OverlappingFieldsCanBeMerged.ConflictReason
                    {
                        Message = new OverlappingFieldsCanBeMerged.Message
                        {
                            Msg = "c and b are different fields"
                        }
                    });
                    e.Locations.Add(new ErrorLocation(14, 25));
                    e.Locations.Add(new ErrorLocation(21, 21));
                });
            });
        }
        public void Disallows_differing_return_type_list_despite_no_overlap()
        {
            ISchema schema = new ResultTypeValidationSchema();

            string query = @"
                {
                    someBox {
                        ... on IntBox {
                            box: listStringBox {
                                scalar
                            }
                        }
                        ... on StringBox {
                            box: stringBox {
                                scalar
                            }
                        }
                    }
                }
            ";

            ShouldFailRule(config =>
            {
                config.Schema = schema;
                config.Query  = query;
                config.Error(e =>
                {
                    e.Message = OverlappingFieldsCanBeMergedError.FieldsConflictMessage("box", new OverlappingFieldsCanBeMerged.ConflictReason
                    {
                        Message = new OverlappingFieldsCanBeMerged.Message
                        {
                            Msg = "they return conflicting types [StringBox] and StringBox"
                        }
                    });
                    e.Locations.Add(new ErrorLocation(5, 29));
                    e.Locations.Add(new ErrorLocation(10, 29));
                });
            });

            query = @"
                {
                    someBox {
                        ... on IntBox {
                            box: stringBox {
                                scalar
                            }
                        }
                        ... on StringBox {
                            box: listStringBox {
                                scalar
                            }
                        }
                    }
                }
            ";

            ShouldFailRule(config =>
            {
                config.Schema = schema;
                config.Query  = query;
                config.Error(e =>
                {
                    e.Message = OverlappingFieldsCanBeMergedError.FieldsConflictMessage("box", new OverlappingFieldsCanBeMerged.ConflictReason
                    {
                        Message = new OverlappingFieldsCanBeMerged.Message
                        {
                            Msg = "they return conflicting types StringBox and [StringBox]"
                        }
                    });
                    e.Locations.Add(new ErrorLocation(5, 29));
                    e.Locations.Add(new ErrorLocation(10, 29));
                });
            });
        }