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; } }
public void Register(TypeSystemObjectBase typeSystemObject, bool isInferred = false) { RegisteredType registeredType = InitializeType(typeSystemObject, isInferred); if (registeredType.References.Count > 0) { foreach (ITypeReference typeReference in registeredType.References) { _registered[typeReference] = registeredType; _unresolved.Remove(typeReference); } if (typeSystemObject is IHasClrType hasClrType && hasClrType.ClrType != typeof(object)) { var clrRef = new ClrTypeReference( hasClrType.ClrType, SchemaTypeReference.InferTypeContext(typeSystemObject)); _unresolved.Remove(clrRef); if (!_clrTypeReferences.ContainsKey(clrRef)) { _clrTypeReferences.Add(clrRef, registeredType.References[0]); } } } }
public void Register(TypeSystemObjectBase typeSystemObject, bool isInferred = false) { RegisteredType registeredType = InitializeType(typeSystemObject, isInferred); if (registeredType.References.Count > 0) { foreach (ITypeReference typeReference in registeredType.References) { _registered[typeReference] = registeredType; _unresolved.Remove(typeReference); } if (typeSystemObject is IHasClrType hasClrType && hasClrType.ClrType != typeof(object)) { var clrRef = new ClrTypeReference( hasClrType.ClrType, SchemaTypeReference.InferTypeContext(typeSystemObject)); _unresolved.Remove(clrRef); bool autoBind = true; if (typeSystemObject is ScalarType scalar && scalar.Bind == BindingBehavior.Explicit) { autoBind = false; } if (autoBind && !_clrTypeReferences.ContainsKey(clrRef)) { _clrTypeReferences.Add(clrRef, registeredType.References[0]); } } } }
private static bool IsMutationType( ITypeInspector typeInspector, TypeSystemObjectBase type, Dictionary <OperationType, ITypeReference> operations) { if (type is ObjectType objectType) { if (operations.TryGetValue(OperationType.Mutation, out ITypeReference? typeRef)) { if (typeRef is SchemaTypeReference sr) { return(sr.Type == objectType); } if (typeRef is ExtendedTypeReference cr) { return(cr.Type == typeInspector.GetType(objectType.GetType()) || cr.Type == typeInspector.GetType(objectType.RuntimeType)); } if (typeRef is SyntaxTypeReference str) { return(objectType.Name.Equals(str.Type.NamedType().Name.Value)); } } else { return(type.Name.Equals(WellKnownTypes.Mutation)); } } return(false); }
private bool IsQueryType(TypeSystemObjectBase type) { if (type is ObjectType objectType) { if (_operations.TryGetValue(OperationType.Query, out ITypeReference reference)) { if (reference is ISchemaTypeReference sr) { return(sr.Type == objectType); } if (reference is IClrTypeReference cr) { return(cr.Type == objectType.GetType() || cr.Type == objectType.ClrType); } if (reference is ISyntaxTypeReference str) { return(objectType.Name.Equals( str.Type.NamedType().Name.Value)); } } else { return(type is ObjectType && type.Name.Equals(WellKnownTypes.Query)); } } return(false); }
public RegisteredType( ITypeReference reference, TypeSystemObjectBase type, InitializationContext initializationContext, IReadOnlyList <TypeDependency> dependencies, bool isInferred) : this(new[] { reference }, type, initializationContext, dependencies, isInferred) { }
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); }
public RegisteredType( IReadOnlyList <ITypeReference> references, TypeSystemObjectBase type, IReadOnlyList <TypeDependency> dependencies) { References = references ?? throw new ArgumentNullException(nameof(references)); Type = type ?? throw new ArgumentNullException(nameof(type)); Dependencies = dependencies ?? throw new ArgumentNullException(nameof(dependencies)); }
public RegisteredType( IReadOnlyList <ITypeReference> references, TypeSystemObjectBase type, InitializationContext initializationContext, IReadOnlyList <TypeDependency> dependencies, bool isInferred) { References = references; Type = type; InitializationContext = initializationContext; Dependencies = dependencies; IsInferred = isInferred; }
private RegisteredType InitializeType( TypeSystemObjectBase typeSystemObject, bool isInferred) { try { var initializationContext = new InitializationContext( typeSystemObject, _serviceFactory.Services, _descriptorContext, _contextData, _interceptor); typeSystemObject.Initialize(initializationContext); var references = new List <ITypeReference>(); if (!isInferred) { references.Add(new SchemaTypeReference(typeSystemObject)); } if (!BaseTypes.IsNonGenericBaseType(typeSystemObject.GetType())) { references.Add(new ClrTypeReference( typeSystemObject.GetType(), SchemaTypeReference.InferTypeContext(typeSystemObject))); } if (typeSystemObject is IHasTypeIdentity hasTypeIdentity && hasTypeIdentity.TypeIdentity is { }) { var reference = new ClrTypeReference( hasTypeIdentity.TypeIdentity, SchemaTypeReference.InferTypeContext(typeSystemObject)); if (!references.Contains(reference)) { references.Add(reference); } } var registeredType = new RegisteredType( references, typeSystemObject, initializationContext, initializationContext.TypeDependencies, isInferred); return(registeredType); }
public RegisteredType( ITypeReference reference, TypeSystemObjectBase type, IReadOnlyList <TypeDependency> dependencies) { if (reference == null) { throw new ArgumentNullException(nameof(reference)); } References = new[] { reference }; Type = type ?? throw new ArgumentNullException(nameof(type)); Dependencies = dependencies ?? throw new ArgumentNullException(nameof(dependencies)); }
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; }
private static RootTypeKind GetOperationKind( TypeSystemObjectBase type, ITypeInspector typeInspector, Dictionary <OperationType, ITypeReference> operations) { if (type is ObjectType objectType) { if (IsOperationType( objectType, OperationType.Query, typeInspector, operations)) { return(RootTypeKind.Query); } if (IsOperationType( objectType, OperationType.Mutation, typeInspector, operations)) { return(RootTypeKind.Mutation); } if (IsOperationType( objectType, OperationType.Subscription, typeInspector, operations)) { return(RootTypeKind.Subscription); } } return(RootTypeKind.None); }
public void Register( TypeSystemObjectBase typeSystemObject, string?scope, bool isInferred = false) { RegisteredType registeredType = InitializeType( typeSystemObject, scope, isInferred); if (registeredType.References.Count > 0) { ResolveReferences(registeredType); if (typeSystemObject is IHasRuntimeType hasClrType && hasClrType.RuntimeType != typeof(object)) { var clrRef = TypeReference.Create( hasClrType.RuntimeType, SchemaTypeReference.InferTypeContext(typeSystemObject), scope: scope); var explicitBind = typeSystemObject is ScalarType scalar && scalar.Bind == BindingBehavior.Explicit; if (!explicitBind) { MarkResolved(clrRef); if (!_clrTypeReferences.ContainsKey(clrRef)) { _clrTypeReferences.Add(clrRef, registeredType.References[0]); } } } } }
private void Visit(TypeSystemObjectBase type) { if (_touched.Add(type)) { switch (type) { case ScalarType s: VisitScalar(s); break; case EnumType e: VisitEnum(e); break; case ObjectType o: VisitObject(o); break; case UnionType u: VisitUnion(u); break; case InterfaceType i: VisitInterface(i); break; case DirectiveType d: VisitDirective(d); break; case InputObjectType i: VisitInput(i); break; } } }
public void Register( TypeSystemObjectBase typeSystemObject, string?scope, bool isInferred = false) { if (typeSystemObject is null) { throw new ArgumentNullException(nameof(typeSystemObject)); } RegisteredType registeredType = InitializeType(typeSystemObject, scope, isInferred); if (registeredType.References.Count > 0) { ResolveReferences(registeredType); if (typeSystemObject is IHasRuntimeType hasRuntimeType && hasRuntimeType.RuntimeType != typeof(object)) { ExtendedTypeReference runtimeTypeRef = _context.TypeInspector.GetTypeRef( hasRuntimeType.RuntimeType, SchemaTypeReference.InferTypeContext(typeSystemObject), scope: scope); var explicitBind = typeSystemObject is ScalarType scalar && scalar.Bind == BindingBehavior.Explicit; if (!explicitBind) { MarkResolved(runtimeTypeRef); _typeRegistry.TryRegister(runtimeTypeRef, registeredType.References[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()); } }