Esempio n. 1
0
        private RegisteredType InitializeType(
            TypeSystemObjectBase typeSystemObject,
            string?scope,
            bool isInferred)
        {
            try
            {
                var discoveryContext = new TypeDiscoveryContext(
                    typeSystemObject,
                    scope,
                    _serviceFactory.Services,
                    _descriptorContext,
                    _interceptor);

                typeSystemObject.Initialize(discoveryContext);

                var references = new List <ITypeReference>();

                if (!isInferred)
                {
                    references.Add(TypeReference.Create(
                                       typeSystemObject,
                                       scope: scope));
                }

                if (!BaseTypes.IsNonGenericBaseType(typeSystemObject.GetType()))
                {
                    references.Add(TypeReference.Create(
                                       typeSystemObject.GetType(),
                                       SchemaTypeReference.InferTypeContext(typeSystemObject),
                                       scope: scope));
                }

                if (typeSystemObject is IHasTypeIdentity hasTypeIdentity &&
                    hasTypeIdentity.TypeIdentity is { })
                {
                    var reference = TypeReference.Create(
                        hasTypeIdentity.TypeIdentity,
                        SchemaTypeReference.InferTypeContext(typeSystemObject),
                        scope: scope);

                    if (!references.Contains(reference))
                    {
                        references.Add(reference);
                    }
                }

                var registeredType = new RegisteredType(
                    references,
                    typeSystemObject,
                    discoveryContext,
                    CollectDependencies(discoveryContext),
                    isInferred);

                return(registeredType);
            }
Esempio n. 2
0
 public RegisteredType(
     IReadOnlyList <ITypeReference> references,
     TypeSystemObjectBase type,
     TypeDiscoveryContext discoveryContext,
     IReadOnlyList <TypeDependency> dependencies,
     bool isInferred)
 {
     References       = references;
     Type             = type;
     DiscoveryContext = discoveryContext;
     Dependencies     = dependencies;
     IsInferred       = isInferred;
     IsExtension      = Type is INamedTypeExtensionMerger;
     IsNamedType      = Type is INamedType;
     IsDirectiveType  = Type is DirectiveType;
 }
Esempio n. 3
0
        public TypeCompletionContext(
            TypeDiscoveryContext initializationContext,
            TypeInitializer typeInitializer,
            IsOfTypeFallback isOfType,
            Func <ISchema> schemaResolver)
        {
            _initializationContext = initializationContext
                                     ?? throw new ArgumentNullException(nameof(initializationContext));
            _typeInitializer = typeInitializer
                               ?? throw new ArgumentNullException(nameof(typeInitializer));
            IsOfType        = isOfType;
            _schemaResolver = schemaResolver
                              ?? throw new ArgumentNullException(nameof(schemaResolver));
            GlobalComponents = new ReadOnlyCollection <FieldMiddleware>(
                _typeInitializer.GlobalComponents);

            _alternateNames.Add(_initializationContext.InternalName);
        }
 public TypeCompletionContext(
     TypeDiscoveryContext initializationContext,
     TypeReferenceResolver typeReferenceResolver,
     IList <FieldMiddleware> globalComponents,
     IDictionary <FieldReference, RegisteredResolver> resolvers,
     IsOfTypeFallback isOfType,
     Func <ISchema> schemaResolver)
 {
     _initializationContext = initializationContext ??
                              throw new ArgumentNullException(nameof(initializationContext));
     _typeReferenceResolver = typeReferenceResolver ??
                              throw new ArgumentNullException(nameof(typeReferenceResolver));
     _resolvers = resolvers ??
                  throw new ArgumentNullException(nameof(resolvers));
     IsOfType        = isOfType;
     _schemaResolver = schemaResolver ??
                       throw new ArgumentNullException(nameof(schemaResolver));
     GlobalComponents = new ReadOnlyCollection <FieldMiddleware>(globalComponents);
     _alternateNames.Add(_initializationContext.InternalName);
 }
Esempio n. 5
0
        private void MergeTypeExtension(
            IEnumerable <RegisteredType> extensions,
            RegisteredType registeredType,
            INamedType namedType)
        {
            foreach (RegisteredType extension in extensions)
            {
                if (extension.Type is INamedTypeExtensionMerger m)
                {
                    if (m.Kind != namedType.Kind)
                    {
                        throw new SchemaException(SchemaErrorBuilder.New()
                                                  .SetMessage(string.Format(
                                                                  CultureInfo.InvariantCulture,
                                                                  TypeInitializer_Merge_KindDoesNotMatch,
                                                                  namedType.Name))
                                                  .SetTypeSystemObject((ITypeSystemObject)namedType)
                                                  .Build());
                    }

                    TypeDiscoveryContext initContext = extension.DiscoveryContext;
                    foreach (FieldReference reference in initContext.Resolvers.Keys)
                    {
                        _resolvers[reference]
                            = initContext.Resolvers[reference].WithSourceType(registeredType.RuntimeType);
                    }

                    // merge
                    TypeCompletionContext context = extension.CompletionContext;
                    context.Status = TypeStatus.Named;
                    m.Merge(context, namedType);

                    // update dependencies
                    context = registeredType.CompletionContext;
                    registeredType.AddDependencies(extension.Dependencies);
                    _typeRegistry.Register(registeredType);
                    CopyAlternateNames(extension.CompletionContext, context);
                }
            }
        }
Esempio n. 6
0
        private RegisteredType InitializeType(
            TypeSystemObjectBase typeSystemObject,
            string?scope,
            bool isInferred)
        {
            try
            {
                var discoveryContext = new TypeDiscoveryContext(
                    typeSystemObject,
                    _typeRegistry,
                    _typeLookup,
                    _context,
                    _interceptor,
                    scope);

                typeSystemObject.Initialize(discoveryContext);

                var references = new List <ITypeReference>();

                if (!isInferred)
                {
                    references.Add(TypeReference.Create(typeSystemObject, scope));
                }

                if (!ExtendedType.Tools.IsNonGenericBaseType(typeSystemObject.GetType()))
                {
                    references.Add(_context.TypeInspector.GetTypeRef(
                                       typeSystemObject.GetType(),
                                       SchemaTypeReference.InferTypeContext(typeSystemObject),
                                       scope));
                }

                if (typeSystemObject is IHasTypeIdentity hasTypeIdentity &&
                    hasTypeIdentity.TypeIdentity is not null)
                {
                    ExtendedTypeReference reference =
                        _context.TypeInspector.GetTypeRef(
                            hasTypeIdentity.TypeIdentity,
                            SchemaTypeReference.InferTypeContext(typeSystemObject),
                            scope);

                    if (!references.Contains(reference))
                    {
                        references.Add(reference);
                    }
                }

                var registeredType = new RegisteredType(
                    typeSystemObject,
                    references,
                    CollectDependencies(discoveryContext),
                    discoveryContext,
                    isInferred);

                return(registeredType);
            }
            catch (Exception ex)
            {
                throw new SchemaException(
                          SchemaErrorBuilder.New()
                          .SetMessage(ex.Message)
                          .SetException(ex)
                          .SetTypeSystemObject(typeSystemObject)
                          .Build());
            }
        }