Ejemplo n.º 1
0
 private IGraphType CacheType(GraphTypeInfo typeInfo, IGraphType graphType)
 {
     //string:StringGraphType
     _typeDescriptors.AddEntity(typeInfo.TypeRepresentation.AsType(), WrapNonNullableType(typeInfo, graphType));
     //StringGraphType:StringGraphType
     _typeDescriptors.AddEntity(graphType.GetType(), graphType);
     return(graphType);
 }
Ejemplo n.º 2
0
        public GraphTypeInfo GetType(TypeInfo typeInfo, bool isInjected = false)
        {
            if (typeInfo.IsGenericType(typeof(Task <>)))
            {
                typeInfo = typeInfo.TypeParameter();
            }

            var type = _typeCache.GetEntity(typeInfo);

            if (type != null)
            {
                return(type);
            }

            type = _typeCache.AddEntity(typeInfo, new GraphTypeInfo(_typeResolver, typeInfo));
            if (type.IsPrimitive && !type.IsEnumerationType)
            {
                return(type);
            }

            if (isInjected)
            {
                type.IsIgnored = true;
                return(type);
            }

            if (typeInfo.IsGenericParameter || typeInfo.ContainsGenericParameters)
            {
                type.IsIgnored = true;
                return(type);
            }

            type.EnsureTypeParameterInitialized();

            var isInjectedType =
                type.TypeRepresentation.AsType() == typeof(IResolutionContext) ||
                type.TypeRepresentation.AsType() == typeof(IUserContext);

            if (!type.IsEnumerationType &&
                !type.IsScalarType &&
                !type.IsInterfaceType &&
                !type.IsUnionType &&
                !type.IsIgnored &&
                !isInjectedType)
            {
                DeriveInterfaces(type);
            }

            if ((!type.IsScalarType || type.IsEnumerationType) &&
                !type.IsUnionType &&
                !isInjectedType)
            {
                DeriveFields(type);
            }

            _metaDataHandler.DeriveMetaData(type, GetTypeInfo(typeInfo));

            if (type.IsInterfaceType && !type.IsIgnored && !isInjectedType)
            {
                var iface = type.GetTypeRepresentation();
                var types = TypeRegistry.Get(iface).Where(t => iface.IsAssignableFrom(t));
                foreach (var t in types)
                {
                    var ti = t.GetTypeInfo();
                    if (!ti.IsInterface && IsValidType(ti))
                    {
                        GetType(ti);
                    }
                }
            }

            return(type);
        }