from typing import Mapping


def to_obj_map(obj):
    """Convert an object to dict by iterating its attributes.

    Internally it will call vars() if the argument is not a dict,
    vars() will return the object's __dict__.

    In the implementation of graphql-js, toObjMap() uses Object.entries(),
    which returns an array of a given object's own enumerable string-keyed property.

    Enumerable properties are usually created via simple assignment or via a property initializer,
    as for Python, these operations are reflected by __dict__.

    References:

    https://docs.python.org/3/library/functions.html?#vars

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties
    """

    if isinstance(obj, Mapping):
        return obj
    else:
        return dict(vars(obj).items())