示例#1
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));
        }
示例#2
0
 private Schema(
     IServiceProvider services,
     SchemaTypes types,
     IntrospectionFields introspectionFields)
 {
     _types = types;
     _introspectionFields = introspectionFields;
     Services             = services;
 }
示例#3
0
 private Schema(
     ServiceManager serviceManager,
     SchemaTypes types,
     IReadOnlySchemaOptions options,
     IntrospectionFields introspectionFields)
 {
     _serviceManager      = serviceManager;
     _types               = types;
     Options              = options;
     _introspectionFields = introspectionFields;
 }
示例#4
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));
        }