Exemple #1
0
    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 Location(5, 29));
                e.Locations.Add(new Location(8, 29));
            });
        });
    }
Exemple #2
0
    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 Location(5, 29));
                e.Locations.Add(new Location(8, 29));
            });
        });
    }
Exemple #3
0
    public void Compatible_return_shapes_on_different_return_types()
    {
        ISchema schema = new ResultTypeValidationSchema();

        const string query = @"
                {
                    someBox {
                        ... on SomeBox {
                            deepBox {
                                unrelatedField
                            }
                        }
                        ... on StringBox {
                            deepBox {
                                unrelatedField
                            }
                        }
                    }
                }
            ";

        ShouldPassRule(config =>
        {
            config.Schema = schema;
            config.Query  = query;
        });
    }
Exemple #4
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 Location(5, 29));
                e.Locations.Add(new Location(6, 33));
                e.Locations.Add(new Location(10, 29));
                e.Locations.Add(new Location(11, 33));
            });
        });
    }
Exemple #5
0
    public void Allows_inline_typeless_fragments()
    {
        ISchema schema = new ResultTypeValidationSchema();

        const string query = @"
                {
                    a
                    ... {
                        a
                    }
                }
            ";

        ShouldPassRule(config =>
        {
            config.Schema = schema;
            config.Query  = query;
        });
    }
Exemple #6
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 Location(6, 33));
                e.Locations.Add(new Location(7, 33));
            });
        });
    }
Exemple #7
0
    public void Ignores_unknown_types()
    {
        ISchema schema = new ResultTypeValidationSchema();

        const string query = @"
                {
                    someBox {
                        ...on UnknownType {
                            scalar
                        }
                        ...on NonNullStringBox2 {
                            scalar
                        }
                    }
                }
            ";

        ShouldPassRule(config =>
        {
            config.Schema = schema;
            config.Query  = query;
        });
    }
Exemple #8
0
    public void Same_wrapped_scalar_return_types()
    {
        ISchema schema = new ResultTypeValidationSchema();

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

        ShouldPassRule(config =>
        {
            config.Schema = schema;
            config.Query  = query;
        });
    }
Exemple #9
0
    public void Allows_non_conflicting_overlapping_types()
    {
        ISchema schema = new ResultTypeValidationSchema();

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

        ShouldPassRule(config =>
        {
            config.Schema = schema;
            config.Query  = query;
        });
    }
Exemple #10
0
    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 Location(31, 21));
                e.Locations.Add(new Location(39, 21));
                e.Locations.Add(new Location(34, 21));
                e.Locations.Add(new Location(42, 21));
            });
        });
    }
Exemple #11
0
    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 Location(5, 29));
                e.Locations.Add(new Location(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 Location(5, 29));
                e.Locations.Add(new Location(10, 29));
            });
        });
    }