Ejemplo n.º 1
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 = CreateSchemaContext();

            // deserialize schema objects
            SchemaSyntaxVisitor 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);
            }));
        }
Ejemplo n.º 2
0
        public static Schema Create(
            DocumentNode schemaDocument,
            Action <ISchemaConfiguration> configure,
            bool strict,
            IServiceProvider services)
        {
            if (schemaDocument == null)
            {
                throw new ArgumentNullException(nameof(schemaDocument));
            }

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

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

            SchemaContext context = CreateSchemaContext();

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

            visitor.Visit(schemaDocument);

            SchemaNames names = new SchemaNames(
                visitor.QueryTypeName,
                visitor.MutationTypeName,
                visitor.SubscriptionTypeName);

            return(CreateSchema(services, context, names, configure, strict));
        }
Ejemplo n.º 3
0
        private IEnumerable <ITypeReference> ParseDocuments(
            IServiceProvider services,
            IBindingLookup bindingLookup)
        {
            var types = new List <ITypeReference>();

            foreach (LoadSchemaDocument fetchSchema in _documents)
            {
                // TODO: retrieve root type names
                DocumentNode schemaDocument = fetchSchema(services);

                var visitor = new SchemaSyntaxVisitor(bindingLookup);
                visitor.Visit(schemaDocument, null);
                types.AddRange(visitor.Types);

                RegisterOperationName(OperationType.Query,
                                      visitor.QueryTypeName);
                RegisterOperationName(OperationType.Mutation,
                                      visitor.MutationTypeName);
                RegisterOperationName(OperationType.Subscription,
                                      visitor.SubscriptionTypeName);
            }

            return(types);
        }
Ejemplo n.º 4
0
            private static IEnumerable <ITypeReference> ParseDocuments(
                SchemaBuilder builder,
                IServiceProvider services,
                IReadOnlySchemaOptions options,
                IBindingLookup bindingLookup)
            {
                var types = new List <ITypeReference>();

                foreach (LoadSchemaDocument fetchSchema in builder._documents)
                {
                    DocumentNode schemaDocument = fetchSchema(services);
                    schemaDocument = schemaDocument.RemoveBuiltInTypes();

                    var visitorContext = new SchemaSyntaxVisitorContext(bindingLookup, options);
                    var visitor        = new SchemaSyntaxVisitor();
                    visitor.Visit(schemaDocument, visitorContext);

                    types.AddRange(visitorContext.Types);

                    RegisterOperationName(
                        builder,
                        OperationType.Query,
                        visitorContext.QueryTypeName);

                    RegisterOperationName(
                        builder,
                        OperationType.Mutation,
                        visitorContext.MutationTypeName);

                    RegisterOperationName(
                        builder,
                        OperationType.Subscription,
                        visitorContext.SubscriptionTypeName);

                    IReadOnlyCollection <DirectiveNode> directives =
                        visitorContext.Directives ?? Array.Empty <DirectiveNode>();

                    if (builder._schema is null &&
                        (directives.Count > 0 ||
                         visitorContext.Description != null))
                    {
                        builder.SetSchema(new Schema(d =>
                        {
                            d.Description(visitorContext.Description);
                            foreach (DirectiveNode directive in directives)
                            {
                                d.Directive(directive);
                            }
                        }));
                    }
                }

                return(types);
            }
Ejemplo n.º 5
0
        private IEnumerable <ITypeReference> ParseDocuments(
            IServiceProvider services,
            IBindingLookup bindingLookup)
        {
            var types = new List <ITypeReference>();

            foreach (LoadSchemaDocument fetchSchema in _documents)
            {
                // TODO: retrieve root type names
                DocumentNode schemaDocument = fetchSchema(services);

                var visitor = new SchemaSyntaxVisitor(bindingLookup);
                visitor.Visit(schemaDocument, null);
                types.AddRange(visitor.Types);

                RegisterOperationName(OperationType.Query,
                                      visitor.QueryTypeName);
                RegisterOperationName(OperationType.Mutation,
                                      visitor.MutationTypeName);
                RegisterOperationName(OperationType.Subscription,
                                      visitor.SubscriptionTypeName);

                IReadOnlyCollection <DirectiveNode> directives =
                    visitor.Directives ?? Array.Empty <DirectiveNode>();

                if (_schema == null &&
                    (directives.Count > 0 ||
                     visitor.Description != null))
                {
                    SetSchema(new Schema(d =>
                    {
                        d.Description(visitor.Description);
                        foreach (DirectiveNode directive in directives)
                        {
                            d.Directive(directive);
                        }
                    }));
                }
            }

            return(types);
        }