Esempio n. 1
0
        private static Schema CreateSchema(
            SchemaContext context,
            Action <ISchemaConfiguration> configure)
        {
            var errors = new List <SchemaError>();

            IReadOnlySchemaOptions options = ExecuteSchemaConfiguration(
                context, configure, errors);


            if (!context.Types.TryGetType(
                    options.QueryTypeName, out ObjectType ot))
            {
                errors.Add(new SchemaError(
                               "Schema is missing the mandatory `Query` type."));
            }

            if (options.StrictValidation && errors.Any())
            {
                throw new SchemaException(errors);
            }

            return(new Schema(
                       context.Services ?? new ServiceFactory(),
                       SchemaTypes.Create(
                           context.Types.GetTypes(),
                           context.Types.GetTypeBindings(),
                           options),
                       context.Directives.GetDirectives().ToArray(),
                       context.DataLoaders.ToArray(),
                       options));
        }
Esempio n. 2
0
        private static Schema CreateSchema(
            SchemaContext context,
            Action <ISchemaConfiguration> configure)
        {
            List <SchemaError> errors = new List <SchemaError>();

            // setup introspection fields
            IntrospectionFields introspectionFields =
                new IntrospectionFields(context, e => errors.Add(e));

            IReadOnlySchemaOptions options = ExecuteSchemaConfiguration(
                context, configure, errors);


            if (!context.Types.TryGetType(
                    options.QueryTypeName, out ObjectType ot))
            {
                errors.Add(new SchemaError(
                               "Schema is missing the mandatory `Query` type."));
            }

            if (options.StrictValidation && errors.Any())
            {
                throw new SchemaException(errors);
            }

            return(new Schema(
                       context.ServiceManager,
                       SchemaTypes.Create(
                           context.Types.GetTypes(),
                           context.Types.GetTypeBindings(),
                           options),
                       options,
                       introspectionFields));
        }
Esempio n. 3
0
 private Schema(
     IServiceProvider services,
     SchemaTypes types,
     IntrospectionFields introspectionFields)
 {
     _types = types;
     _introspectionFields = introspectionFields;
     Services             = services;
 }
Esempio n. 4
0
 private Schema(
     ServiceManager serviceManager,
     SchemaTypes types,
     IReadOnlySchemaOptions options,
     IntrospectionFields introspectionFields)
 {
     _serviceManager      = serviceManager;
     _types               = types;
     Options              = options;
     _introspectionFields = introspectionFields;
 }
Esempio n. 5
0
 private Schema(
     ServiceManager serviceManager,
     SchemaTypes types,
     IReadOnlyCollection <Directive> directives,
     IReadOnlySchemaOptions options)
 {
     _serviceManager = serviceManager;
     _types          = types;
     Options         = options;
     Directives      = directives;
 }
Esempio n. 6
0
 private Schema(
     IServiceProvider services,
     SchemaTypes types,
     IReadOnlyCollection <Directive> directives,
     IReadOnlyCollection <DataLoaderDescriptor> dataLoaders,
     IReadOnlySchemaOptions options)
 {
     _types      = types;
     Services    = services;
     Directives  = directives;
     DataLoaders = dataLoaders;
     Options     = options;
 }
Esempio n. 7
0
 private Schema(
     IServiceProvider services,
     ISchemaContext context,
     IReadOnlySchemaOptions options)
 {
     Services = services;
     _types   = SchemaTypes.Create(
         context.Types.GetTypes(),
         context.Types.GetTypeBindings(),
         options);
     _directiveTypes = context.Directives
                       .GetDirectiveTypes()
                       .ToDictionary(t => t.Name);
     DirectiveTypes = _directiveTypes.Values;
     Options        = options;
 }
Esempio n. 8
0
        internal Schema(SchemaDefinition definition)
        {
            if (definition == null)
            {
                throw new ArgumentNullException(nameof(definition));
            }

            Description    = definition.Description;
            Directives     = definition.Directives;
            Services       = definition.Services;
            Options        = definition.Options;
            DirectiveTypes = definition.DirectiveTypes;

            _types          = new SchemaTypes(definition);
            _directiveTypes = DirectiveTypes.ToDictionary(t => t.Name);
        }
Esempio n. 9
0
 private Schema(
     IServiceProvider services,
     ISchemaContext context,
     IReadOnlySchemaOptions options)
 {
     Services = services;
     _types   = SchemaTypes.Create(
         context.Types.GetTypes(),
         context.Types.GetTypeBindings(),
         options);
     Directives = context.Directives.GetDirectives();
     Options    = options;
     Sessions   = new SessionManager(
         services,
         context.DataLoaders,
         context.CustomContexts);
 }
        internal void CompleteSchema(
            SchemaTypesDefinition schemaTypesDefinition)
        {
            if (schemaTypesDefinition == null)
            {
                throw new ArgumentNullException(nameof(schemaTypesDefinition));
            }

            if (_sealed)
            {
                throw new InvalidOperationException(
                          "This schema is already sealed and cannot be mutated.");
            }

            DirectiveTypes  = schemaTypesDefinition.DirectiveTypes;
            _types          = new SchemaTypes(schemaTypesDefinition);
            _directiveTypes = DirectiveTypes.ToDictionary(t => t.Name);
            _sealed         = true;
        }
Esempio n. 11
0
        private static Schema CreateSchema(
            IServiceProvider services,
            SchemaContext context,
            SchemaNames names,
            Action <ISchemaConfiguration> configure,
            bool strict)
        {
            List <SchemaError> errors = new List <SchemaError>();

            // setup introspection fields
            IntrospectionFields introspectionFields =
                new IntrospectionFields(context, e => errors.Add(e));

            SchemaNames internalNames = names;

            try
            {
                // configure resolvers, custom types and type mappings.
                SchemaConfiguration configuration = new SchemaConfiguration(services);
                configure(configuration);
                errors.AddRange(configuration.RegisterTypes(context));
                configuration.RegisterResolvers(context);
                errors.AddRange(context.CompleteTypes());

                string queryTypeName        = configuration.QueryTypeName ?? names.QueryTypeName;
                string mutationTypeName     = configuration.MutationTypeName ?? names.MutationTypeName;
                string subscriptionTypeName = configuration.SubscriptionTypeName ?? names.SubscriptionTypeName;

                internalNames = new SchemaNames(queryTypeName, mutationTypeName, subscriptionTypeName);
            }
            catch (ArgumentException ex)
            {
                // TODO : maybe we should throw a more specific
                // argument exception that at least contains the config object.
                throw new SchemaException(new[]
                {
                    new SchemaError(ex.Message, null)
                });
            }

            if (strict && errors.Any())
            {
                throw new SchemaException(errors);
            }

            internalNames = string.IsNullOrEmpty(names.QueryTypeName)
                ? new SchemaNames(null, null, null)
                : names;

            if (strict && !context.Types.TryGetType <ObjectType>(
                    internalNames.QueryTypeName, out ObjectType ot))
            {
                throw new SchemaException(new SchemaError(
                                              "Schema is missing the mandatory `Query` type."));
            }

            return(new Schema(
                       services,
                       SchemaTypes.Create(
                           context.Types.GetTypes(),
                           context.Types.GetTypeBindings(),
                           internalNames),
                       introspectionFields));
        }