public void AnnotateCostToInterfaceFieldCodeFirst()
        {
            // arrange
            // act
            var schema = Schema.Create(
                t =>
            {
                t.RegisterQueryType(new ObjectType(
                                        o => o.Name("Query")
                                        .Field("field")
                                        .Argument("a", a => a.Type <StringType>())
                                        .Type <StringType>()));

                t.RegisterType(new InterfaceType(
                                   o => o.Name("IQuery")
                                   .Field("field")
                                   .Argument("a", a => a.Type <StringType>())
                                   .Type <StringType>()
                                   .Cost(5)));

                t.RegisterDirective <CostDirectiveType>();

                t.Use(next => context => Task.CompletedTask);
            });

            InterfaceType queryInterface = schema.GetType <InterfaceType>("IQuery");
            IDirective    directive      = queryInterface.Fields["field"].Directives
                                           .Single(t => t.Name == "cost");
            CostDirective obj = directive.ToObject <CostDirective>();

            Assert.Equal(5, obj.Complexity);
        }
        public void AnnotateCostToObjectFieldCodeFirstTwoMultiplier()
        {
            // arrange
            // act
            var schema = Schema.Create(
                t =>
            {
                t.RegisterQueryType(new ObjectType(
                                        o => o.Name("Query")
                                        .Field("field")
                                        .Argument("a", a => a.Type <StringType>())
                                        .Type <StringType>()
                                        .Cost(5, "a", "b")));

                t.RegisterDirective <CostDirectiveType>();

                t.Use(next => context => Task.CompletedTask);
            });

            ObjectType query     = schema.GetType <ObjectType>("Query");
            IDirective directive = query.Fields["field"].Directives
                                   .Single(t => t.Name == "cost");
            CostDirective obj = directive.ToObject <CostDirective>();

            Assert.Equal(5, obj.Complexity);
            Assert.Collection(obj.Multipliers,
                              t => Assert.Equal("a", t),
                              t => Assert.Equal("b", t));
        }
        public void AnnotateCostToInterfaceFieldSchemaFirst()
        {
            // arrange
            // act
            var schema = SchemaBuilder.New()
                         .AddDocumentFromString(
                @"
                    type Query {
                        field(a: Int): String
                            @cost(complexity: 5 multipliers: [""a""])
                    }

                    interface IQuery {
                        field(a: Int): String
                            @cost(complexity: 5 multipliers: [""a""])
                    }
                    ")
                         .AddDirectiveType <CostDirectiveType>()
                         .Use(next => context => Task.CompletedTask)
                         .Create();

            InterfaceType queryInterface = schema.GetType <InterfaceType>("IQuery");
            IDirective    directive      =
                queryInterface.Fields["field"].Directives.Single(t => t.Name == "cost");
            CostDirective obj = directive.ToObject <CostDirective>();

            Assert.Equal(5, obj.Complexity);
            Assert.Collection(obj.Multipliers, t => Assert.Equal("a", t));
        }
        public void NoMultipliers()
        {
            // arrange
            // act
            var cost = new CostDirective(5);

            // assert
            Assert.Equal(5, cost.Complexity);
            Assert.Empty(cost.Multipliers);
        }
        public void ValidMultipliers()
        {
            // arrange
            // act
            var cost = new CostDirective(6, "", "b", "c", null);

            // assert
            Assert.Equal(6, cost.Complexity);
            Assert.Collection(cost.Multipliers,
                              s => Assert.Equal("b", s),
                              s => Assert.Equal("c", s));
        }
Esempio n. 6
0
        public void AnnotateCostToObjectFieldSchemaFirst()
        {
            // arrange
            // act
            var schema = Schema.Create(
                @"type Query {
                    field(a: Int): String
                        @cost(complexity: 5 multipliers: [""a""])
                }",
                t => t.Use(next => context => Task.CompletedTask));

            ObjectType query     = schema.GetType <ObjectType>("Query");
            IDirective directive = query.Fields["field"].Directives
                                   .Single(t => t.Name == "cost");
            CostDirective obj = directive.ToObject <CostDirective>();

            Assert.Equal(5, obj.Complexity);
            Assert.Collection(obj.Multipliers,
                              t => Assert.Equal("a", t));
        }