graphene-django icon indicating copy to clipboard operation
graphene-django copied to clipboard

Updated deprecated variable name from format_error to GraphQLFormattedError

Open qe opened this issue 2 years ago • 2 comments

While using graphene-django, I ran into the following ImportError:

ImportError: cannot import name 'format_error' from 'graphql.error'

Looking into graphql.error, here is an excerpt of graphql-core's /error/__init__.py file:

__all__ = [
    "GraphQLError",
    "GraphQLErrorExtensions",
    "GraphQLFormattedError",
    "GraphQLSyntaxError",
    "located_error",
]

I believe graphene_django/views.py's format_error variable name is most likely deprecated, so locally, I replaced format_error with GraphQLFormattedError from the excerpt above, and it is now working locally.

Here is graphql-core's commit that deprecated the format_error variable name

qe avatar Apr 09 '22 13:04 qe

It might make sense to restrict the graphql-core dependency to the minor version as they have mentioned that the minor versions are not compatible with another.

Note that for various reasons, GraphQL-core does not use SemVer like GraphQL.js. Increases in the major version of GraphQL.js are reflected in the minor version of GraphQL-core instead. This means there can be breaking changes in the API when the minor version changes, and only patch releases are fully backward compatible. Therefore, we recommend something like =~ 3.2.0 as version specifier when including GraphQL-core as a dependency.

moritz89 avatar Jun 01 '22 14:06 moritz89

I honestly don't understand why they removed it from the init because the format_error method still exists... they only changed the returned type to be more specific than a dict that could basically have any keys before! so I guess the real fix is to change the import from

from graphql.error import format_error as format_graphql_error

to

from graphql.error.graphql_error import format_error as format_graphql_error

tcleonard avatar Jun 14 '22 20:06 tcleonard

Fixed in #1327

erikwrede avatar Aug 15 '22 09:08 erikwrede