Exemplo n.º 1
0
            private static Schema CompleteSchema(
                SchemaBuilder builder,
                DescriptorContext context,
                LazySchema lazySchema,
                TypeRegistry typeRegistry)
            {
                SchemaTypesDefinition definition =
                    CreateSchemaDefinition(builder, context, typeRegistry);

                if (definition.QueryType is null && builder._options.StrictValidation)
                {
                    throw new SchemaException(
                              SchemaErrorBuilder.New()
                              .SetMessage(TypeResources.SchemaBuilder_NoQueryType)
                              .Build());
                }

                Schema schema = typeRegistry.Types
                                .Select(t => t.Type).OfType <Schema>().First();

                schema.CompleteSchema(definition);
                lazySchema.Schema = schema;
                context.SchemaInterceptor.OnAfterCreate(context, schema);
                return(schema);
            }
Exemplo n.º 2
0
        public void CreateSchemaError_SetExtension()
        {
            // arrange
            var message = "FooBar";
            var key     = "foo";
            var value   = "bar";

            // act
            ISchemaError schemaError = SchemaErrorBuilder.New()
                                       .SetMessage(message)
                                       .SetExtension(key, value)
                                       .Build();

            // assert
            Assert.Equal(message, schemaError.Message);
            Assert.Empty(schemaError.SyntaxNodes);
            Assert.Collection(schemaError.Extensions,
                              t =>
            {
                Assert.Equal(key, t.Key);
                Assert.Equal(value, t.Value);
            });
            Assert.Null(schemaError.Exception);
            Assert.Null(schemaError.TypeSystemObject);
            Assert.Null(schemaError.Path);
            Assert.Null(schemaError.Code);
        }
Exemplo n.º 3
0
        public Schema Create()
        {
            IServiceProvider services      = _services ?? new EmptyServiceProvider();
            IBindingLookup   bindingLookup =
                _bindingCompiler.Compile(DescriptorContext.Create(services));

            var types = new List <ITypeReference>(_types);

            if (_documents.Count > 0)
            {
                types.AddRange(ParseDocuments(services, bindingLookup));
            }

            var lazy = new LazySchema();

            TypeInitializer initializer =
                InitializeTypes(services, bindingLookup, types, () => lazy.Schema);

            SchemaDefinition definition = CreateSchemaDefinition(initializer);

            if (definition.QueryType == null && _options.StrictValidation)
            {
                // TODO : Resources
                throw new SchemaException(
                          SchemaErrorBuilder.New()
                          .SetMessage("No QUERY TYPE")
                          .Build());
            }

            var schema = new Schema(definition);

            lazy.Schema = schema;
            return(schema);
        }
Exemplo n.º 4
0
        public Schema Create()
        {
            IServiceProvider  services          = _services ?? new EmptyServiceProvider();
            DescriptorContext descriptorContext =
                DescriptorContext.Create(_options, services);

            IBindingLookup bindingLookup =
                _bindingCompiler.Compile(descriptorContext);

            var types = new List <ITypeReference>(_types);

            if (_documents.Count > 0)
            {
                types.AddRange(ParseDocuments(services, bindingLookup));
            }

            if (_schema == null)
            {
                types.Add(new SchemaTypeReference(new Schema()));
            }
            else
            {
                types.Add(_schema);
            }

            var lazy = new LazySchema();

            TypeInitializer initializer =
                InitializeTypes(
                    services,
                    descriptorContext,
                    bindingLookup,
                    types,
                    () => lazy.Schema);

            SchemaTypesDefinition definition =
                CreateSchemaDefinition(initializer);

            if (definition.QueryType == null && _options.StrictValidation)
            {
                throw new SchemaException(
                          SchemaErrorBuilder.New()
                          .SetMessage(TypeResources.SchemaBuilder_NoQueryType)
                          .Build());
            }

            Schema schema = initializer.Types.Values
                            .Select(t => t.Type)
                            .OfType <Schema>()
                            .First();

            schema.CompleteSchema(definition);
            lazy.Schema = schema;
            return(schema);
        }
        public Schema Create()
        {
            IServiceProvider services = _services ?? new EmptyServiceProvider();

            var descriptorContext = DescriptorContext.Create(
                _options,
                services,
                CreateConventions(services),
                _contextData);

            foreach (Action <IDescriptorContext> action in _onBeforeCreate)
            {
                action(descriptorContext);
            }

            IBindingLookup bindingLookup =
                _bindingCompiler.Compile(descriptorContext);

            IReadOnlyCollection <ITypeReference> types =
                GetTypeReferences(services, bindingLookup);

            var lazy = new LazySchema();

            TypeInitializer initializer =
                CreateTypeInitializer(
                    services,
                    descriptorContext,
                    bindingLookup,
                    types);

            DiscoveredTypes discoveredTypes = initializer.Initialize(() => lazy.Schema, _options);

            SchemaTypesDefinition definition = CreateSchemaDefinition(initializer, discoveredTypes);

            if (definition.QueryType == null && _options.StrictValidation)
            {
                throw new SchemaException(
                          SchemaErrorBuilder.New()
                          .SetMessage(TypeResources.SchemaBuilder_NoQueryType)
                          .Build());
            }

            Schema schema = discoveredTypes.Types
                            .Select(t => t.Type)
                            .OfType <Schema>()
                            .First();

            schema.CompleteSchema(definition);
            lazy.Schema = schema;
            TypeInspector.Default.Clear();
            return(schema);
        }
Exemplo n.º 6
0
        public Schema Create()
        {
            IServiceProvider services = _services
                                        ?? new EmptyServiceProvider();

            var descriptorContext = DescriptorContext.Create(
                _options,
                services,
                CreateConventions(services));

            IBindingLookup bindingLookup =
                _bindingCompiler.Compile(descriptorContext);

            IReadOnlyCollection <ITypeReference> types =
                GetTypeReferences(services, bindingLookup);

            var lazy = new LazySchema();

            TypeInitializer initializer =
                InitializeTypes(
                    services,
                    descriptorContext,
                    bindingLookup,
                    types,
                    () => lazy.Schema);

            SchemaTypesDefinition definition =
                CreateSchemaDefinition(initializer);

            if (definition.QueryType == null && _options.StrictValidation)
            {
                throw new SchemaException(
                          SchemaErrorBuilder.New()
                          .SetMessage(TypeResources.SchemaBuilder_NoQueryType)
                          .Build());
            }

            Schema schema = initializer.Types.Values
                            .Select(t => t.Type)
                            .OfType <Schema>()
                            .First();

            schema.CompleteSchema(definition);
            lazy.Schema = schema;
            return(schema);
        }
Exemplo n.º 7
0
        public void CreateSchemaError_Exception()
        {
            // arrange
            var exception = new Exception("FooBar");

            // act
            ISchemaError schemaError = SchemaErrorBuilder.New()
                                       .SetException(exception)
                                       .Build();

            // assert
            Assert.Equal(exception.Message, schemaError.Message);
            Assert.Equal(exception, schemaError.Exception);
            Assert.Empty(schemaError.SyntaxNodes);
            Assert.Empty(schemaError.Extensions);
            Assert.Null(schemaError.TypeSystemObject);
            Assert.Null(schemaError.Path);
            Assert.Null(schemaError.Code);
        }
Exemplo n.º 8
0
        public void CreateSchemaError_ThreeArguments_PopertiesAreSet()
        {
            // arrange
            var message   = "FooBar";
            var exception = new Exception();
            var type      = new StringType();

            // act
            ISchemaError schemaError = SchemaErrorBuilder.New()
                                       .SetMessage(message)
                                       .SetException(exception)
                                       .SetTypeSystemObject(type)
                                       .Build();

            // assert
            Assert.Equal(message, schemaError.Message);
            Assert.Equal(exception, schemaError.Exception);
            Assert.Equal(type, schemaError.TypeSystemObject);
            Assert.Empty(schemaError.SyntaxNodes);
            Assert.Empty(schemaError.Extensions);
            Assert.Null(schemaError.Path);
            Assert.Null(schemaError.Code);
        }
Exemplo n.º 9
0
        public void CreateSchemaError_AddSyntaxNode()
        {
            // arrange
            var message = "FooBar";
            var node    = new NameNode("foo");


            // act
            ISchemaError schemaError = SchemaErrorBuilder.New()
                                       .SetMessage(message)
                                       .AddSyntaxNode(node)
                                       .Build();

            // assert
            Assert.Equal(message, schemaError.Message);
            Assert.Collection(schemaError.SyntaxNodes,
                              t => Assert.Equal(node, t));
            Assert.Empty(schemaError.Extensions);
            Assert.Null(schemaError.Exception);
            Assert.Null(schemaError.TypeSystemObject);
            Assert.Null(schemaError.Path);
            Assert.Null(schemaError.Code);
        }