@@ -13,6 +13,7 @@ def __init__(
1313 * ,
1414 variable_values : Optional [Dict [str , Any ]] = None ,
1515 operation_name : Optional [str ] = None ,
16+ extensions : Optional [Dict [str , Any ]] = None ,
1617 ):
1718 """Initialize a GraphQL request.
1819
@@ -21,6 +22,9 @@ def __init__(
2122 :param variable_values: Dictionary of input parameters (Default: None).
2223 :param operation_name: Name of the operation that shall be executed.
2324 Only required in multi-operation documents (Default: None).
25+ :param extensions: Dictionary of protocol extensions (Default: None).
26+ This is passed as the top-level "extensions" key in the request
27+ payload, as defined in the GraphQL over HTTP spec.
2428 :return: a :class:`GraphQLRequest <gql.GraphQLRequest>`
2529 which can be later executed or subscribed by a
2630 :class:`Client <gql.client.Client>`, by an
@@ -42,9 +46,12 @@ def __init__(
4246 variable_values = request .variable_values
4347 if operation_name is None :
4448 operation_name = request .operation_name
49+ if extensions is None :
50+ extensions = request .extensions
4551
4652 self .variable_values : Optional [Dict [str , Any ]] = variable_values
4753 self .operation_name : Optional [str ] = operation_name
54+ self .extensions : Optional [Dict [str , Any ]] = extensions
4855
4956 def serialize_variable_values (self , schema : GraphQLSchema ) -> "GraphQLRequest" :
5057
@@ -61,6 +68,7 @@ def serialize_variable_values(self, schema: GraphQLSchema) -> "GraphQLRequest":
6168 operation_name = self .operation_name ,
6269 ),
6370 operation_name = self .operation_name ,
71+ extensions = self .extensions ,
6472 )
6573
6674 @property
@@ -74,6 +82,9 @@ def payload(self) -> Dict[str, Any]:
7482 if self .variable_values :
7583 payload ["variables" ] = self .variable_values
7684
85+ if self .extensions :
86+ payload ["extensions" ] = self .extensions
87+
7788 return payload
7889
7990 def __str__ (self ):
0 commit comments