예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        public void InferEnumType(TypeContext context)
        {
            // arrange
            ExtendedTypeReference typeReference = TypeReference.Create(TypeOf <Foo>(), context);

            // act
            var success = SchemaTypeResolver.TryInferSchemaType(
                _typeInspector,
                typeReference,
                out ExtendedTypeReference schemaType);

            // assert
            Assert.True(success);
            Assert.Equal(TypeContext.None, schemaType.Context);
            Assert.Equal(typeof(EnumType <Foo>), schemaType.Type.Source);
        }
예제 #6
0
        public void InferInputObjectType()
        {
            // arrange
            ExtendedTypeReference typeReference = TypeReference.Create(TypeOf <Bar>(), TypeContext.Input);

            // act
            var success = SchemaTypeResolver.TryInferSchemaType(
                _typeInspector,
                typeReference,
                out ExtendedTypeReference schemaType);

            // assert
            Assert.True(success);
            Assert.Equal(TypeContext.Input, schemaType.Context);
            Assert.Equal(typeof(InputObjectType <Bar>), schemaType.Type.Source);
        }