Example #1
0
        public ComplexGraphType <TModel> BuildGraphType(GraphTypeCache cache, IServiceCollection services)
        {
            var graphType = CreateGraphTypeCore(cache, services);

            graphType.Name        = GraphTypeName;
            graphType.Description = typeof(TModel).GetCustomAttribute <DescriptionAttribute>()?.Description;

            if (!cache.TryPrime(graphType))
            {
                return(cache.GetOrCreate <TModel> (services));
            }

            foreach (var prop in typeof(TModel).GetProperties().Where(x => !_config.IsPropertyIgnored(x)))
            {
                var fieldConfig = _config.GetFieldConfig(prop);
                fieldConfig.ConfigureField(graphType, cache, services);
            }

            if (graphType is ObjectGraphType <TModel> objectGraphType)
            {
                foreach (var iFace in _config.Interfaces)
                {
                    objectGraphType.AddResolvedInterface((IInterfaceGraphType)cache.GetOrCreate(iFace, services));
                }
            }

            return(graphType);
        }
Example #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);
        }