# Copyright 2020-present Kensho Technologies, LLC.
from typing import Union

from graphql import GraphQLList, GraphQLNonNull, GraphQLScalarType


# The below code is an import shim for TypedDict: we don't want to conditionally import it from
# every file that needs it. Instead, we conditionally import it here and then import from this file
# in every other location where this is needed.
#
# Hence, the "unused import" warnings on TypedDict here are false-positives.
try:
    from typing import TypedDict  # noqa  # pylint: disable=unused-import
except ImportError:  # TypedDict was only added to typing in Python 3.8
    from typing_extensions import TypedDict  # noqa  # pylint: disable=unused-import


# The compiler's supported GraphQL types for query arguments. The GraphQL type of a query argument
# is the type of the field that the argument references. Not to be confused with the GraphQLArgument
# class in the GraphQL core library.
QueryArgumentGraphQLType = Union[
    GraphQLScalarType,
    GraphQLList[GraphQLScalarType],
    GraphQLList[GraphQLNonNull[GraphQLScalarType]],
    GraphQLNonNull[GraphQLScalarType],
    GraphQLNonNull[GraphQLList[GraphQLScalarType]],
    GraphQLNonNull[GraphQLList[GraphQLNonNull[GraphQLScalarType]]],
]

# Copyright 2020-present Kensho Technologies, LLC.
import sys
from typing import Union

from graphql import GraphQLList, GraphQLNonNull, GraphQLScalarType


# The below code is an import shim for TypedDict and Literal: we don't want to conditionally import
# them from every file that needs them. Instead, we conditionally import them here and then import
# from this file in every other location where they are needed.
#
# We prefer the explicit sys.version_info check instead of the more common try-except ImportError
# approach, because at the moment mypy seems to have an easier time with the sys.version_info check:
# https://github.com/python/mypy/issues/1393
#
# Hence, the "unused import" warnings here are false-positives.
if sys.version_info[:2] >= (3, 8):
    # TypedDict and Literal were only added to typing in Python 3.8
    from typing import Literal, TypedDict  # noqa  # pylint: disable=unused-import
else:
    from typing_extensions import Literal, TypedDict  # noqa  # pylint: disable=unused-import


# The compiler's supported GraphQL types for query arguments. The GraphQL type of a query argument
# is the type of the field that the argument references. Not to be confused with the GraphQLArgument
# class in the GraphQL core library.
QueryArgumentGraphQLType = Union[
    GraphQLScalarType,
    GraphQLList[GraphQLScalarType],
    GraphQLList[GraphQLNonNull[GraphQLScalarType]],
    GraphQLNonNull[GraphQLScalarType],
    GraphQLNonNull[GraphQLList[GraphQLScalarType]],
    GraphQLNonNull[GraphQLList[GraphQLNonNull[GraphQLScalarType]]],
]

Add Literal to typing import shim, change to mypy-friendly approach. (#926)