private bool InferSchemaTypesFromUnresolved() { bool resolved = false; foreach (IClrTypeReference unresolvedType in Unresolved.ToList()) { if (Scalars.TryGetScalar(unresolvedType.Type, out IClrTypeReference schemaType)) { resolved = true; _unregistered.Add(schemaType); Unresolved.Remove(unresolvedType); if (!ClrTypes.ContainsKey(unresolvedType)) { ClrTypes.Add(unresolvedType, schemaType); } } else if (SchemaTypeResolver.TryInferSchemaType(unresolvedType, out schemaType)) { resolved = true; _unregistered.Add(schemaType); Unresolved.Remove(unresolvedType); } } return(resolved); }
private bool TryInferTypes() { bool inferred = false; foreach (IClrTypeReference unresolvedType in _typeRegistrar.GetUnresolved()) { if (Scalars.TryGetScalar(unresolvedType.Type, out IClrTypeReference schemaType)) { inferred = true; _unregistered.Add(schemaType); _typeRegistrar.MarkResolved(unresolvedType); if (!_clrTypeReferences.ContainsKey(unresolvedType)) { _clrTypeReferences.Add(unresolvedType, schemaType); } } else if (SchemaTypeResolver.TryInferSchemaType(unresolvedType, out schemaType)) { inferred = true; _unregistered.Add(schemaType); _typeRegistrar.MarkResolved(unresolvedType); } } return(inferred); }
private bool TryInferTypes() { var inferred = false; foreach (ExtendedTypeReference unresolvedType in _typeRegistrar.GetUnresolved().OfType <ExtendedTypeReference>()) { if (Scalars.TryGetScalar(unresolvedType.Type.Type, out Type? scalarType)) { inferred = true; ExtendedTypeReference typeReference = _typeInspector.GetTypeRef(scalarType); _unregistered.Add(typeReference); _typeRegistrar.MarkResolved(unresolvedType); _typeRegistry.TryRegister(unresolvedType, typeReference); } else if (SchemaTypeResolver.TryInferSchemaType( _typeInspector, unresolvedType, out ExtendedTypeReference schemaType)) { inferred = true; _unregistered.Add(schemaType); _typeRegistrar.MarkResolved(unresolvedType); } } return(inferred); }
public static bool TryInferSchemaTypeKind( ExtendedTypeReference unresolvedType, out TypeKind kind) { if (unresolvedType == null) { throw new ArgumentNullException(nameof(unresolvedType)); } var typeInfo = new TypeInfo(unresolvedType); if (IsObjectTypeExtension(typeInfo)) { kind = TypeKind.Object; return(true); } if (IsUnionType(typeInfo)) { kind = TypeKind.Union; return(true); } if (IsInterfaceType(typeInfo)) { kind = TypeKind.Interface; return(true); } if (IsObjectType(typeInfo)) { kind = TypeKind.Object; return(true); } if (IsInputObjectType(typeInfo)) { kind = TypeKind.InputObject; return(true); } if (IsEnumType(typeInfo)) { kind = TypeKind.Enum; return(true); } if (Scalars.TryGetScalar(unresolvedType.Type.Type, out _)) { kind = TypeKind.Scalar; return(true); } kind = default; return(false); }
public bool TryPredictTypeKind(ITypeReference typeRef, out TypeKind kind) { if (_typeLookup.TryNormalizeReference(typeRef, out ITypeReference namedTypeRef) && _typeRegistry.TryGetType(namedTypeRef, out RegisteredType registeredType)) { switch (registeredType.Type) { case INamedType namedType: kind = namedType.Kind; return(true); case DirectiveType: kind = TypeKind.Directive; return(true); default: kind = default; return(false); } } namedTypeRef ??= typeRef; switch (namedTypeRef) { case ExtendedTypeReference r: if (Scalars.TryGetScalar(r.Type.Type, out _)) { kind = TypeKind.Scalar; return(true); } if (r.Type.IsSchemaType) { kind = GetTypeKindFromSchemaType(r.Type); return(true); } return(SchemaTypeResolver.TryInferSchemaTypeKind(r, out kind)); case SchemaTypeReference r: kind = GetTypeKindFromSchemaType(TypeInspector.GetType(r.Type.GetType())); return(true); default: kind = default; return(false); } }
public void Register( ITypeRegistrar typeRegistrar, IEnumerable <ITypeReference> typeReferences) { foreach (ISyntaxTypeReference typeReference in typeReferences.OfType <ISyntaxTypeReference>()) { if (Scalars.TryGetScalar( typeReference.Type.NamedType().Name.Value, out IClrTypeReference namedTypeReference)) { if (!typeRegistrar.IsResolved(namedTypeReference)) { typeRegistrar.Register(typeRegistrar.CreateInstance(namedTypeReference.Type)); } } } }
public void Register( ITypeRegistrar typeRegistrar, IEnumerable <ITypeReference> typeReferences) { foreach (SyntaxTypeReference typeReference in typeReferences.OfType <SyntaxTypeReference>()) { if (Scalars.TryGetScalar( typeReference.Type.NamedType().Name.Value, out Type? scalarType)) { ExtendedTypeReference namedTypeReference = _typeInspector.GetTypeRef(scalarType); if (!typeRegistrar.IsResolved(namedTypeReference)) { typeRegistrar.Register( typeRegistrar.CreateInstance(namedTypeReference.Type.Type), typeReference.Scope); } } } }
public static bool TryInferSchemaType( ITypeInspector typeInspector, ExtendedTypeReference unresolvedType, out ExtendedTypeReference schemaType) { if (typeInspector is null) { throw new ArgumentNullException(nameof(typeInspector)); } if (unresolvedType is null) { throw new ArgumentNullException(nameof(unresolvedType)); } if (IsObjectTypeExtension(unresolvedType)) { schemaType = unresolvedType.With( type: typeInspector.GetType( typeof(ObjectTypeExtension <>).MakeGenericType(unresolvedType.Type.Type))); } else if (IsUnionType(unresolvedType)) { schemaType = unresolvedType.With( type: typeInspector.GetType( typeof(UnionType <>).MakeGenericType(unresolvedType.Type.Type))); } else if (IsInterfaceType(unresolvedType)) { schemaType = unresolvedType.With( type: typeInspector.GetType( typeof(InterfaceType <>).MakeGenericType(unresolvedType.Type.Type))); } else if (IsObjectType(unresolvedType)) { schemaType = unresolvedType.With( type: typeInspector.GetType( typeof(ObjectType <>).MakeGenericType(unresolvedType.Type.Type))); } else if (IsInputObjectType(unresolvedType)) { schemaType = unresolvedType.With( type: typeInspector.GetType( typeof(InputObjectType <>).MakeGenericType(unresolvedType.Type.Type))); } else if (IsEnumType(unresolvedType)) { schemaType = unresolvedType.With( type: typeInspector.GetType( typeof(EnumType <>).MakeGenericType(unresolvedType.Type.Type))); } else if (Scalars.TryGetScalar(unresolvedType.Type.Type, out Type scalarType)) { schemaType = unresolvedType.With( type: typeInspector.GetType(scalarType)); } else { schemaType = null; } return(schemaType != null); }