1414 ) # noqa: F401
1515 from ..language .source import Source # noqa: F401
1616
17- __all__ = ["GraphQLError" , "GraphQLFormattedError" ]
17+ __all__ = ["GraphQLError" , "GraphQLErrorExtensions" , "GraphQLFormattedError" ]
18+
19+
20+ # Custom extensions
21+ GraphQLErrorExtensions = Dict [str , Any ]
22+ # Use a unique identifier name for your extension, for example the name of
23+ # your library or project. Do not use a shortened identifier as this increases
24+ # the risk of conflicts. We recommend you add at most one extension key,
25+ # a dictionary which can contain all the values you need.
1826
1927
2028class GraphQLFormattedError (TypedDict , total = False ):
@@ -33,7 +41,7 @@ class GraphQLFormattedError(TypedDict, total=False):
3341 path : List [Union [str , int ]]
3442 # Reserved for implementors to extend the protocol however they see fit,
3543 # and hence there are no additional restrictions on its contents.
36- extensions : Dict [ str , Any ]
44+ extensions : GraphQLErrorExtensions
3745
3846
3947class GraphQLError (Exception ):
@@ -91,7 +99,7 @@ class GraphQLError(Exception):
9199 original_error : Optional [Exception ]
92100 """The original error thrown from a field resolver during execution"""
93101
94- extensions : Optional [Dict [ str , Any ] ]
102+ extensions : Optional [GraphQLErrorExtensions ]
95103 """Extension fields to add to the formatted error"""
96104
97105 __slots__ = (
@@ -115,7 +123,7 @@ def __init__(
115123 positions : Optional [Collection [int ]] = None ,
116124 path : Optional [Collection [Union [str , int ]]] = None ,
117125 original_error : Optional [Exception ] = None ,
118- extensions : Optional [Dict [ str , Any ] ] = None ,
126+ extensions : Optional [GraphQLErrorExtensions ] = None ,
119127 ) -> None :
120128 super ().__init__ (message )
121129 self .message = message
0 commit comments