Пример #1
0
        public void CreateIncludeDirective()
        {
            // arrange
            SchemaContext       schemaContext       = SchemaContextFactory.Create();
            SchemaConfiguration schemaConfiguration =
                new SchemaConfiguration(sp => { }, schemaContext.Types);
            TypeFinalizer typeFinalizer = new TypeFinalizer(schemaConfiguration);

            typeFinalizer.FinalizeTypes(schemaContext, null);

            // assert
            Directive directive = schemaContext.Directives
                                  .GetDirectives().FirstOrDefault(t => t.Name == "include");

            // assert
            Assert.NotNull(directive);
            Assert.IsType <IncludeDirective>(directive);
            Assert.Equal("include", directive.Name);
            Assert.Collection(directive.Arguments,
                              t =>
            {
                Assert.Equal("if", t.Name);
                Assert.IsType <NonNullType>(t.Type);
                Assert.IsType <BooleanType>(((NonNullType)t.Type).Type);
            });
            Assert.Collection(directive.Locations,
                              t => Assert.Equal(DirectiveLocation.Field, t),
                              t => Assert.Equal(DirectiveLocation.FragmentSpread, t),
                              t => Assert.Equal(DirectiveLocation.InlineFragment, t));
        }
Пример #2
0
        public static Schema Create(
            DocumentNode schemaDocument,
            Action <ISchemaConfiguration> configure)
        {
            if (schemaDocument == null)
            {
                throw new ArgumentNullException(nameof(schemaDocument));
            }

            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            SchemaContext context = SchemaContextFactory.Create();

            // deserialize schema objects
            var visitor = new SchemaSyntaxVisitor(context.Types);

            visitor.Visit(schemaDocument);

            return(CreateSchema(context, c =>
            {
                c.Options.QueryTypeName = visitor.QueryTypeName;
                c.Options.MutationTypeName = visitor.MutationTypeName;
                c.Options.SubscriptionTypeName = visitor.SubscriptionTypeName;

                configure(c);
            }));
        }
Пример #3
0
        public static Schema Create(
            Action <ISchemaConfiguration> configure)
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            SchemaContext context = SchemaContextFactory.Create();

            return(CreateSchema(context, configure));
        }
        public void CreateCostDirective()
        {
            // arrange
            SchemaContext schemaContext = SchemaContextFactory.Create();

            var schemaConfiguration = new SchemaConfiguration(
                sp => { },
                schemaContext.Types,
                schemaContext.Resolvers,
                schemaContext.Directives);

            var typeFinalizer = new TypeFinalizer(schemaConfiguration);

            typeFinalizer.FinalizeTypes(schemaContext, null);

            // assert
            DirectiveType directive = schemaContext.Directives
                                      .GetDirectiveTypes()
                                      .FirstOrDefault(t => t.Name == "cost");

            // assert
            Assert.NotNull(directive);
            Assert.IsType <CostDirectiveType>(directive);
            Assert.Equal("cost", directive.Name);
            Assert.Collection(directive.Arguments,
                              t =>
            {
                Assert.Equal("complexity", t.Name);
                Assert.IsType <IntType>(
                    Assert.IsType <NonNullType>(t.Type).Type);
            },
                              t =>
            {
                Assert.Equal("multipliers", t.Name);
                Assert.IsType <MultiplierPathType>(
                    Assert.IsType <NonNullType>(
                        Assert.IsType <ListType>(t.Type).ElementType).Type);
            });
            Assert.Collection(directive.Locations,
                              t => Assert.Equal(DirectiveLocation.FieldDefinition, t));
        }