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)); }
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)); }
private Schema( IServiceProvider services, SchemaTypes types, IntrospectionFields introspectionFields) { _types = types; _introspectionFields = introspectionFields; Services = services; }
private Schema( ServiceManager serviceManager, SchemaTypes types, IReadOnlySchemaOptions options, IntrospectionFields introspectionFields) { _serviceManager = serviceManager; _types = types; Options = options; _introspectionFields = introspectionFields; }
private Schema( ServiceManager serviceManager, SchemaTypes types, IReadOnlyCollection <Directive> directives, IReadOnlySchemaOptions options) { _serviceManager = serviceManager; _types = types; Options = options; Directives = directives; }
private Schema( IServiceProvider services, SchemaTypes types, IReadOnlyCollection <Directive> directives, IReadOnlyCollection <DataLoaderDescriptor> dataLoaders, IReadOnlySchemaOptions options) { _types = types; Services = services; Directives = directives; DataLoaders = dataLoaders; Options = options; }
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; }
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); }
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; }
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)); }