Exemplo n.º 1
0
        public RegisteredType(
            TypeSystemObjectBase type,
            bool isInferred,
            TypeRegistry typeRegistry,
            TypeLookup typeLookup,
            IDescriptorContext descriptorContext,
            ITypeInterceptor typeInterceptor,
            string?scope)
        {
            Type              = type;
            _typeRegistry     = typeRegistry;
            _typeLookup       = typeLookup;
            IsInferred        = isInferred;
            DescriptorContext = descriptorContext;
            TypeInterceptor   = typeInterceptor;
            IsExtension       = Type is INamedTypeExtensionMerger;
            IsSchema          = Type is ISchema;
            Scope             = scope;

            if (type is INamedType nt)
            {
                IsNamedType         = true;
                IsIntrospectionType = nt.IsIntrospectionType();
                Kind = nt.Kind;
            }
            else if (type is DirectiveType)
            {
                IsDirectiveType = true;
                Kind            = TypeKind.Directive;
            }
        }
Exemplo n.º 2
0
        public void Register_SchemaType_ClrTypeExists_NoSystemTypes()
        {
            // arrange
            var context      = DescriptorContext.Create();
            var typeRegistry = new TypeRegistry();
            var typeLookup   = new TypeLookup(context.TypeInspector, typeRegistry);

            var typeDiscoverer = new TypeDiscoverer(
                context,
                typeRegistry,
                typeLookup,
                new HashSet <ITypeReference>
            {
                _typeInspector.GetTypeRef(typeof(FooType), TypeContext.Output)
            },
                new AggregateTypeInterceptor(),
                false);

            // act
            IReadOnlyList <ISchemaError> errors = typeDiscoverer.DiscoverTypes();

            // assert
            Assert.Empty(errors);

            new
            {
                registered = typeRegistry.Types
                             .Select(t => new
                {
                    type        = t.Type.GetType().GetTypeName(),
                    runtimeType = t.Type is IHasRuntimeType hr
                            ? hr.RuntimeType.GetTypeName()
                            : null,
                    references = t.References.Select(t => t.ToString()).ToList()
                }).ToList(),
Exemplo n.º 3
0
        public TypeDiscoveryContext(
            ITypeSystemObject type,
            TypeRegistry typeRegistry,
            TypeLookup typeLookup,
            IDescriptorContext descriptorContext,
            ITypeInterceptor typeInterceptor,
            string scope)
        {
            Type = type ??
                   throw new ArgumentNullException(nameof(type));
            _typeRegistry = typeRegistry ??
                            throw new ArgumentNullException(nameof(typeRegistry));
            _typeLookup = typeLookup ??
                          throw new ArgumentNullException(nameof(typeLookup));
            DescriptorContext = descriptorContext ??
                                throw new ArgumentNullException(nameof(descriptorContext));
            TypeInterceptor = typeInterceptor ??
                              throw new ArgumentNullException(nameof(typeInterceptor));
            Scope = scope;

            IsDirective = type is DirectiveType;
            IsSchema    = type is Schema;

            if (type is INamedType nt)
            {
                IsType = true;
                IsIntrospectionType = nt.IsIntrospectionType();
            }

            InternalName = "Type_" + Guid.NewGuid().ToString("N");
        }
Exemplo n.º 4
0
        public TypeInitializer(
            IDescriptorContext descriptorContext,
            TypeRegistry typeRegistry,
            IReadOnlyList <ITypeReference> initialTypes,
            IReadOnlyList <Type> externalResolverTypes,
            IsOfTypeFallback?isOfType,
            Func <TypeSystemObjectBase, bool> isQueryType)
        {
            _context = descriptorContext ??
                       throw new ArgumentNullException(nameof(descriptorContext));
            _typeRegistry = typeRegistry ??
                            throw new ArgumentNullException(nameof(typeRegistry));
            _initialTypes = initialTypes ??
                            throw new ArgumentNullException(nameof(initialTypes));
            _externalResolverTypes = externalResolverTypes ??
                                     throw new ArgumentNullException(nameof(externalResolverTypes));
            _isOfType    = isOfType;
            _isQueryType = isQueryType ??
                           throw new ArgumentNullException(nameof(isQueryType));

            _interceptor           = descriptorContext.TypeInterceptor;
            _typeInspector         = descriptorContext.TypeInspector;
            _typeLookup            = new TypeLookup(_typeInspector, _typeRegistry);
            _typeReferenceResolver = new TypeReferenceResolver(
                _typeInspector, _typeRegistry, _typeLookup);
        }
Exemplo n.º 5
0
        public TypeDiscoverer(
            IDescriptorContext context,
            TypeRegistry typeRegistry,
            TypeLookup typeLookup,
            IEnumerable <ITypeReference> initialTypes,
            ITypeInterceptor interceptor,
            bool includeSystemTypes = true)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (typeRegistry is null)
            {
                throw new ArgumentNullException(nameof(typeRegistry));
            }

            if (typeLookup is null)
            {
                throw new ArgumentNullException(nameof(typeLookup));
            }

            if (initialTypes is null)
            {
                throw new ArgumentNullException(nameof(initialTypes));
            }

            if (interceptor is null)
            {
                throw new ArgumentNullException(nameof(interceptor));
            }

            _typeRegistry = typeRegistry;

            if (includeSystemTypes)
            {
                _unregistered.AddRange(
                    IntrospectionTypes.CreateReferences(context.TypeInspector));
                _unregistered.AddRange(
                    Directives.CreateReferences(context.TypeInspector));
            }

            _unregistered.AddRange(typeRegistry.GetTypeRefs());
            _unregistered.AddRange(initialTypes.Distinct());

            _typeRegistrar = new TypeRegistrar(context, typeRegistry, typeLookup, interceptor);

            _handlers = new ITypeRegistrarHandler[]
            {
                new SchemaTypeReferenceHandler(),
                new ExtendedTypeReferenceHandler(context.TypeInspector),
                new SyntaxTypeReferenceHandler(context.TypeInspector)
            };

            _typeInspector = context.TypeInspector;
        }
 public TypeReferenceResolver(
     ITypeInspector typeInspector,
     TypeRegistry typeRegistry,
     TypeLookup typeLookup)
 {
     _typeInspector = typeInspector ??
                      throw new ArgumentNullException(nameof(typeInspector));
     _typeRegistry = typeRegistry ??
                     throw new ArgumentNullException(nameof(typeRegistry));
     _typeLookup = typeLookup ??
                   throw new ArgumentNullException(nameof(typeLookup));
 }
Exemplo n.º 7
0
 public TypeRegistrar(
     IDescriptorContext context,
     TypeRegistry typeRegistry,
     TypeLookup typeLookup,
     ITypeInterceptor typeInterceptor)
 {
     _context = context ??
                throw new ArgumentNullException(nameof(context));
     _typeRegistry = typeRegistry ??
                     throw new ArgumentNullException(nameof(typeRegistry));
     _typeLookup = typeLookup ??
                   throw new ArgumentNullException(nameof(typeLookup));
     _interceptor = typeInterceptor ??
                    throw new ArgumentNullException(nameof(typeInterceptor));
     _serviceFactory.Services = context.Services;
 }