public ISchemaBuilder BindClrType(Type clrType, Type schemaType) { if (clrType == null) { throw new ArgumentNullException(nameof(clrType)); } if (schemaType == null) { throw new ArgumentNullException(nameof(schemaType)); } if (!BaseTypes.IsSchemaType(schemaType)) { // TODO : resources throw new ArgumentException( TypeResources.SchemaBuilder_MustBeSchemaType, nameof(schemaType)); } TypeContext context = SchemaTypeReference.InferTypeContext(schemaType); _clrTypes[new ClrTypeReference(clrType, context)] = new ClrTypeReference(schemaType, context); return(this); }
protected override void VisitDirectiveDefinition( DirectiveDefinitionNode node, object context) { _types.Add(SchemaTypeReference.Create( _directiveTypeFactory.Create(_bindingLookup, node))); }
public void Register( ITypeRegistrar typeRegistrar, IEnumerable <ITypeReference> typeReferences) { foreach (IClrTypeReference typeReference in typeReferences.OfType <IClrTypeReference>()) { if (!BaseTypes.IsNonGenericBaseType(typeReference.Type) && _typeInspector.TryCreate(typeReference.Type, out TypeInfo typeInfo)) { Type type = typeInfo.ClrType; if (IsTypeSystemObject(type)) { var namedTypeReference = new ClrTypeReference( type, SchemaTypeReference.InferTypeContext(type)); if (!typeRegistrar.IsResolved(namedTypeReference)) { typeRegistrar.Register( typeRegistrar.CreateInstance(type), BaseTypes.IsGenericBaseType(type)); } } else { TryMapToExistingRegistration( typeRegistrar, typeInfo, typeReference.Context); } } } }
private void OnBeforeCompleteName( ITypeCompletionContext completionContext, SortInputTypeDefinition definition) { ISortConvention convention = GetConvention( completionContext.DescriptorContext, definition.Scope); var descriptor = SortInputTypeDescriptor.New( completionContext.DescriptorContext, definition.EntityType, definition.Scope); SchemaTypeReference typeReference = TypeReference.Create( completionContext.Type, definition.Scope); convention.ApplyConfigurations(typeReference, descriptor); DataTypeExtensionHelper.MergeSortInputTypeDefinitions( completionContext, descriptor.CreateDefinition(), definition); if (definition is { Name : {} } &&
protected override void VisitInputObjectTypeDefinition( InputObjectTypeDefinitionNode node, object context) { _types.Add(SchemaTypeReference.Create( _inputObjectTypeFactory.Create(_bindingLookup, node))); }
protected override void VisitInterfaceTypeExtension( InterfaceTypeExtensionNode node, object context) { _types.Add(SchemaTypeReference.Create( _interfaceTypeExtensionFactory.Create(_bindingLookup, node))); }
public override void OnBeforeCompleteName( ITypeCompletionContext completionContext, DefinitionBase?definition, IDictionary <string, object?> contextData) { if (definition is FilterInputTypeDefinition def) { IFilterConvention convention = GetConvention( completionContext.DescriptorContext, def.Scope); var descriptor = FilterInputTypeDescriptor.New( completionContext.DescriptorContext, def.EntityType, def.Scope); SchemaTypeReference typeReference = TypeReference.Create( completionContext.Type, def.Scope); convention.ApplyConfigurations(typeReference, descriptor); DataTypeExtensionHelper.MergeFilterInputTypeDefinitions( completionContext, descriptor.CreateDefinition(), def); if (def.Scope is not null) { definition.Name = completionContext.Scope + "_" + definition.Name; } } }
public override void OnBeforeRegisterDependencies( ITypeDiscoveryContext discoveryContext, DefinitionBase?definition, IDictionary <string, object?> contextData) { if (definition is FilterInputTypeDefinition def) { IFilterConvention convention = GetConvention( discoveryContext.DescriptorContext, def.Scope); SchemaTypeReference typeReference = TypeReference.Create( discoveryContext.Type, def.Scope); var descriptor = FilterInputTypeDescriptor.New( discoveryContext.DescriptorContext, def.EntityType, def.Scope); convention.ApplyConfigurations(typeReference, descriptor); FilterInputTypeDefinition extensionDefinition = descriptor.CreateDefinition(); discoveryContext.RegisterDependencies(extensionDefinition); } }
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]); } } } }
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]); } } } }
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 IObjectFilterOperationDescriptor <TObject> AllowObject( Action <IFilterInputTypeDescriptor <TObject> > descriptor) { ObjectFilterOperationDescriptor <TObject> field = GetOrCreateOperation(FilterOperationKind.Object); var type = new FilterInputType <TObject>(descriptor); var typeReference = new SchemaTypeReference(type); field.Type(typeReference); return(field); }
public IArrayFilterOperationDescriptor <TArray> AllowAll( Action <IFilterInputTypeDescriptor <TArray> > descriptor) { var type = new FilterInputType <TArray>(descriptor); var typeReference = new SchemaTypeReference(type); ArrayFilterOperationDescriptor <TArray> field = GetOrCreateOperation(FilterOperationKind.ArrayAll); field.Type(typeReference); Filters.Add(field); return(field); }
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 ISchemaBuilder AddRootType( ObjectType type, OperationType operation) { if (type == null) { throw new ArgumentNullException(nameof(type)); } var reference = new SchemaTypeReference((ITypeSystemObject)type); _operations.Add(operation, reference); _types.Add(reference); return(this); }
private void ConfigureSortInputType( ITypeDiscoveryContext discoveryContext, SortInputTypeDefinition definition) { ISortConvention convention = GetConvention( discoveryContext.DescriptorContext, definition.Scope); var descriptor = SortInputTypeDescriptor.From( discoveryContext.DescriptorContext, definition, definition.Scope); SchemaTypeReference typeReference = TypeReference.Create( discoveryContext.Type, definition.Scope); convention.ApplyConfigurations(typeReference, descriptor); foreach (InputFieldDefinition field in definition.Fields) { if (field is SortFieldDefinition sortFieldDefinition) { if (discoveryContext.TryPredictTypeKind( sortFieldDefinition.Type, out TypeKind kind) && kind != TypeKind.Enum) { field.Type = field.Type.With(scope: discoveryContext.Scope); } if (convention.TryGetFieldHandler( discoveryContext, definition, sortFieldDefinition, out ISortFieldHandler? handler)) { sortFieldDefinition.Handler = handler; } else { throw ThrowHelper.SortInterceptor_NoFieldHandlerFoundForField( definition, sortFieldDefinition); } } } }
public ISchemaBuilder AddType(Type type) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (type.IsDefined(typeof(GraphQLResolverOfAttribute), true)) { AddResolverType(type); } else { _types.Add(new ClrTypeReference( type, SchemaTypeReference.InferTypeContext(type))); } return(this); }
public static TypeDependency FromSchemaType( Type type, TypeDependencyKind kind) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (BaseTypes.IsSchemaType(type)) { TypeContext context = SchemaTypeReference.InferTypeContext(type); var reference = new ClrTypeReference(type, context); return(new TypeDependency(reference, kind)); } throw new ArgumentException( TypeResources.TypeDependency_MustBeSchemaType, nameof(type)); }
private void AddResolverType(Type type) { GraphQLResolverOfAttribute attribute = type.GetCustomAttribute <GraphQLResolverOfAttribute>(true); _resolverTypes.Add(type); if (attribute.Types != null) { foreach (Type schemaType in attribute.Types) { if (typeof(ObjectType).IsAssignableFrom(schemaType) && !BaseTypes.IsNonGenericBaseType(schemaType)) { _types.Add(new ClrTypeReference( schemaType, SchemaTypeReference.InferTypeContext(schemaType))); } } } }
private void ConfigureSortEnumType( ITypeDiscoveryContext discoveryContext, SortEnumTypeDefinition definition) { ISortConvention convention = GetConvention( discoveryContext.DescriptorContext, discoveryContext.Scope); ISortEnumTypeDescriptor descriptor = SortEnumTypeDescriptor.From( discoveryContext.DescriptorContext, definition); SchemaTypeReference typeReference = TypeReference.Create( discoveryContext.Type, discoveryContext.Scope); convention.ApplyConfigurations(typeReference, descriptor); foreach (var enumValue in definition.Values) { if (enumValue is SortEnumValueDefinition sortEnumValueDefinition) { if (convention.TryGetOperationHandler( discoveryContext, definition, sortEnumValueDefinition, out ISortOperationHandler? handler)) { sortEnumValueDefinition.Handler = handler; } else { throw ThrowHelper.SortInterceptor_NoOperationHandlerFoundForValue( definition, sortEnumValueDefinition); } } } }
private bool TryNormalizeClrReference( IClrTypeReference typeReference, out ITypeReference normalized) { if (!BaseTypes.IsNonGenericBaseType(typeReference.Type) && _typeInspector.TryCreate(typeReference.Type, out Utilities.TypeInfo typeInfo)) { if (IsTypeSystemObject(typeInfo.ClrType)) { normalized = new ClrTypeReference( typeInfo.ClrType, SchemaTypeReference.InferTypeContext(typeInfo.ClrType)); return(true); } else { for (int i = 0; i < typeInfo.Components.Count; i++) { var n = new ClrTypeReference( typeInfo.Components[i], typeReference.Context); if ((ClrTypes.TryGetValue( n, out ITypeReference r) || ClrTypes.TryGetValue( n.WithoutContext(), out r))) { normalized = r; return(true); } } } } normalized = null; return(false); }
private void OnBeforeRegisteringDependencies( ITypeDiscoveryContext discoveryContext, SortEnumTypeDefinition definition) { ISortConvention convention = GetConvention( discoveryContext.DescriptorContext, definition.Scope); var descriptor = SortEnumTypeDescriptor.New( discoveryContext.DescriptorContext, definition.EntityType, definition.Scope); SchemaTypeReference typeReference = TypeReference.Create( discoveryContext.Type, definition.Scope); convention.ApplyConfigurations(typeReference, descriptor); SortEnumTypeDefinition extensionDefinition = descriptor.CreateDefinition(); discoveryContext.RegisterDependencies(extensionDefinition); }
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 bool TryNormalizeClrReference( IClrTypeReference typeReference, out IClrTypeReference normalized) { if (!BaseTypes.IsNonGenericBaseType(typeReference.Type) && _typeInspector.TryCreate(typeReference.Type, out Utilities.TypeInfo typeInfo)) { if (IsTypeSystemObject(typeInfo.ClrType)) { normalized = new ClrTypeReference( typeInfo.ClrType, SchemaTypeReference.InferTypeContext(typeInfo.ClrType)); return(true); } else { normalized = new ClrTypeReference( typeInfo.ClrType, typeReference.Context); if ((_clrTypes.TryGetValue( normalized, out ITypeReference r) || _clrTypes.TryGetValue( normalized.WithoutContext(), out r)) && r is IClrTypeReference cr) { normalized = cr; return(true); } } } normalized = null; return(false); }
private void InitializeTypes() { foreach (ITypeReference typeReference in _unregistered.ToList()) { if (typeReference is IClrTypeReference ctr) { RegisterClrType(ctr); } else if (typeReference is ISchemaTypeReference str && str.Type is TypeSystemObjectBase tso) { if (BaseTypes.IsNonGenericBaseType(tso.GetType())) { RegisterTypeSystemObject(tso, str); } else { var secondaryRef = new ClrTypeReference( tso.GetType(), SchemaTypeReference.InferTypeContext(tso)); RegisterTypeSystemObject(tso, str, secondaryRef); } }
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 static bool CompareSchemaAndExtendedTypeRef( SchemaTypeReference schemaTypeReference, ExtendedTypeReference extendedTypeReference) => schemaTypeReference.Type.GetType() == extendedTypeReference.Type.Source;
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()); } }