コード例 #1
0
        public ModelSchema(OttoSchemaInfo schema, IServiceProvider provider)
            : base(provider)
        {
            if (schema.QueryType?.Fields?.Any() == true)
            {
                Query = schema.QueryType;
            }
            if (schema.MutationType?.Fields?.Any() == true)
            {
                Mutation = schema.MutationType;
            }
            if (schema.SubscriptionType?.Fields?.Any() == true)
            {
                Subscription = schema.SubscriptionType;
            }

            RegisterTypes(schema.OtherTypes.ToArray());
        }
コード例 #2
0
        public OttoSchemaInfo Build(IServiceCollection services)
        {
            var cache             = new GraphTypeCache(_builders, _scalarTypeMap);
            var queryType         = _schemaType.GetGenericArguments().First();
            var mutationType      = _schemaType.GetGenericArguments().Skip(1).First();
            var queryGraphType    = cache.GetOrCreate(queryType, services);
            var mutationGraphType = cache.GetOrCreate(mutationType, services);

            var otherTypes = _builders.Values
                             .Where(x => x.NeedsRegistration)
                             .Select(x => x.BuildGraphType(cache, services))
                             .ToArray();

            cache.ValidateNoDuplicates();

            services.AddTransient(typeof(CustomScalarGraphType <,>));

            var schema = new OttoSchemaInfo((IObjectGraphType)queryGraphType, (IObjectGraphType)mutationGraphType, null, otherTypes);

            return(schema);
        }