Example #1
0
    private static bool IsValidImplementationFieldType(
        IOutputType fieldType,
        IOutputType implementedType)
    {
        if (fieldType.IsNonNullType())
        {
            fieldType = (IOutputType)fieldType.InnerType();

            if (implementedType.IsNonNullType())
            {
                implementedType = (IOutputType)implementedType.InnerType();
            }

            return(IsValidImplementationFieldType(fieldType, implementedType));
        }

        if (fieldType.IsListType() && implementedType.IsListType())
        {
            return(IsValidImplementationFieldType(
                       (IOutputType)fieldType.ElementType(),
                       (IOutputType)implementedType.ElementType()));
        }

        if (ReferenceEquals(fieldType, implementedType))
        {
            return(true);
        }

        if (fieldType is ObjectType objectType &&
            implementedType is UnionType unionType &&
            unionType.IsAssignableFrom(objectType))
        {
            return(true);
        }

        if (fieldType is IComplexOutputType complexType &&
            implementedType is InterfaceType interfaceType &&
            complexType.IsImplementing(interfaceType))
        {
            return(true);
        }

        return(false);
    }