diff --git a/docs/code_examples/aiohttp_async.py b/docs/code_examples/aiohttp_async.py index b8cc05a1..0c1d10dd 100644 --- a/docs/code_examples/aiohttp_async.py +++ b/docs/code_examples/aiohttp_async.py @@ -11,7 +11,8 @@ async def main(): # Using `async with` on the client will start a connection on the transport # and provide a `session` variable to execute queries on this connection async with Client( - transport=transport, fetch_schema_from_transport=True, + transport=transport, + fetch_schema_from_transport=True, ) as session: # Execute single query diff --git a/docs/code_examples/appsync/mutation_api_key.py b/docs/code_examples/appsync/mutation_api_key.py index 052da850..634e2439 100644 --- a/docs/code_examples/appsync/mutation_api_key.py +++ b/docs/code_examples/appsync/mutation_api_key.py @@ -31,7 +31,8 @@ async def main(): transport = AIOHTTPTransport(url=url, auth=auth) async with Client( - transport=transport, fetch_schema_from_transport=False, + transport=transport, + fetch_schema_from_transport=False, ) as session: query = gql( diff --git a/docs/code_examples/appsync/mutation_iam.py b/docs/code_examples/appsync/mutation_iam.py index 327e0d91..3cc04a5a 100644 --- a/docs/code_examples/appsync/mutation_iam.py +++ b/docs/code_examples/appsync/mutation_iam.py @@ -30,7 +30,8 @@ async def main(): transport = AIOHTTPTransport(url=url, auth=auth) async with Client( - transport=transport, fetch_schema_from_transport=False, + transport=transport, + fetch_schema_from_transport=False, ) as session: query = gql( diff --git a/docs/code_examples/requests_sync.py b/docs/code_examples/requests_sync.py index 53b1e2a7..2184f286 100644 --- a/docs/code_examples/requests_sync.py +++ b/docs/code_examples/requests_sync.py @@ -2,7 +2,9 @@ from gql.transport.requests import RequestsHTTPTransport transport = RequestsHTTPTransport( - url="https://countries.trevorblades.com/", verify=True, retries=3, + url="https://countries.trevorblades.com/", + verify=True, + retries=3, ) client = Client(transport=transport, fetch_schema_from_transport=True) diff --git a/docs/code_examples/requests_sync_dsl.py b/docs/code_examples/requests_sync_dsl.py index 925b9aa2..e16ded92 100644 --- a/docs/code_examples/requests_sync_dsl.py +++ b/docs/code_examples/requests_sync_dsl.py @@ -3,7 +3,9 @@ from gql.transport.requests import RequestsHTTPTransport transport = RequestsHTTPTransport( - url="https://countries.trevorblades.com/", verify=True, retries=3, + url="https://countries.trevorblades.com/", + verify=True, + retries=3, ) client = Client(transport=transport, fetch_schema_from_transport=True) diff --git a/docs/code_examples/websockets_async.py b/docs/code_examples/websockets_async.py index e5e83021..e645a7ef 100644 --- a/docs/code_examples/websockets_async.py +++ b/docs/code_examples/websockets_async.py @@ -14,7 +14,8 @@ async def main(): # Using `async with` on the client will start a connection on the transport # and provide a `session` variable to execute queries on this connection async with Client( - transport=transport, fetch_schema_from_transport=True, + transport=transport, + fetch_schema_from_transport=True, ) as session: # Execute single query diff --git a/gql/cli.py b/gql/cli.py index 1e248081..78d82551 100644 --- a/gql/cli.py +++ b/gql/cli.py @@ -132,11 +132,15 @@ def get_parser(with_examples: bool = False) -> ArgumentParser: appsync_auth_group = appsync_group.add_mutually_exclusive_group() appsync_auth_group.add_argument( - "--api-key", help="Provide an API key for authentication", dest="api_key", + "--api-key", + help="Provide an API key for authentication", + dest="api_key", ) appsync_auth_group.add_argument( - "--jwt", help="Provide an JSON Web token for authentication", dest="jwt", + "--jwt", + help="Provide an JSON Web token for authentication", + dest="jwt", ) return parser diff --git a/gql/dsl.py b/gql/dsl.py index 6a2e0718..634c10cb 100644 --- a/gql/dsl.py +++ b/gql/dsl.py @@ -311,7 +311,9 @@ class DSLSelector(ABC): selection_set: SelectionSetNode def __init__( - self, *fields: "DSLSelectable", **fields_with_alias: "DSLSelectableWithAlias", + self, + *fields: "DSLSelectable", + **fields_with_alias: "DSLSelectableWithAlias", ): """:meta private:""" self.selection_set = SelectionSetNode(selections=()) @@ -326,7 +328,9 @@ def is_valid_field(self, field: "DSLSelectable") -> bool: ) # pragma: no cover def select( - self, *fields: "DSLSelectable", **fields_with_alias: "DSLSelectableWithAlias", + self, + *fields: "DSLSelectable", + **fields_with_alias: "DSLSelectableWithAlias", ): r"""Select the fields which should be added. @@ -387,7 +391,9 @@ def executable_ast(self): ) # pragma: no cover def __init__( - self, *fields: "DSLSelectable", **fields_with_alias: "DSLSelectableWithAlias", + self, + *fields: "DSLSelectable", + **fields_with_alias: "DSLSelectableWithAlias", ): r"""Given arguments of type :class:`DSLSelectable` containing GraphQL requests, generate an operation which can be converted to a Document @@ -552,7 +558,9 @@ def get_ast_definitions(self) -> Tuple[VariableDefinitionNode, ...]: """ return tuple( VariableDefinitionNode( - type=var.type, variable=var.ast_variable, default_value=None, + type=var.type, + variable=var.ast_variable, + default_value=None, ) for var in self.variables.values() if var.type is not None # only variables used @@ -889,7 +897,9 @@ class DSLInlineFragment(DSLSelectable, DSLFragmentSelector): ast_field: InlineFragmentNode def __init__( - self, *fields: "DSLSelectable", **fields_with_alias: "DSLSelectableWithAlias", + self, + *fields: "DSLSelectable", + **fields_with_alias: "DSLSelectableWithAlias", ): r"""Initialize the DSLInlineFragment. @@ -944,7 +954,8 @@ class DSLFragment(DSLSelectable, DSLFragmentSelector, DSLExecutable): name: str def __init__( - self, name: str, + self, + name: str, ): r"""Initialize the DSLFragment. diff --git a/gql/transport/aiohttp.py b/gql/transport/aiohttp.py index 7df60417..de9ab953 100644 --- a/gql/transport/aiohttp.py +++ b/gql/transport/aiohttp.py @@ -222,7 +222,8 @@ async def execute( # If we upload files, we will extract the files present in the # variable_values dict and replace them by null values nulled_variable_values, files = extract_files( - variables=variable_values, file_classes=self.file_classes, + variables=variable_values, + file_classes=self.file_classes, ) # Save the nulled variable values in the payload @@ -275,7 +276,8 @@ async def execute( # Add headers for AppSync if requested if isinstance(self.auth, AppSyncAuthentication): post_args["headers"] = self.auth.get_headers( - json.dumps(payload), {"content-type": "application/json"}, + json.dumps(payload), + {"content-type": "application/json"}, ) if self.session is None: diff --git a/gql/transport/appsync_websockets.py b/gql/transport/appsync_websockets.py index c7e05a09..66091747 100644 --- a/gql/transport/appsync_websockets.py +++ b/gql/transport/appsync_websockets.py @@ -172,7 +172,12 @@ async def _send_query( "authorization": self.auth.get_headers(serialized_data) } - await self._send(json.dumps(message, separators=(",", ":"),)) + await self._send( + json.dumps( + message, + separators=(",", ":"), + ) + ) return query_id diff --git a/gql/transport/async_transport.py b/gql/transport/async_transport.py index 7de24015..18f6df79 100644 --- a/gql/transport/async_transport.py +++ b/gql/transport/async_transport.py @@ -7,16 +7,14 @@ class AsyncTransport: @abc.abstractmethod async def connect(self): - """Coroutine used to create a connection to the specified address - """ + """Coroutine used to create a connection to the specified address""" raise NotImplementedError( "Any AsyncTransport subclass must implement connect method" ) # pragma: no cover @abc.abstractmethod async def close(self): - """Coroutine used to Close an established connection - """ + """Coroutine used to Close an established connection""" raise NotImplementedError( "Any AsyncTransport subclass must implement close method" ) # pragma: no cover @@ -28,8 +26,8 @@ async def execute( variable_values: Optional[Dict[str, Any]] = None, operation_name: Optional[str] = None, ) -> ExecutionResult: - """Execute the provided document AST for either a remote or local GraphQL Schema. - """ + """Execute the provided document AST for either a remote or local GraphQL + Schema.""" raise NotImplementedError( "Any AsyncTransport subclass must implement execute method" ) # pragma: no cover diff --git a/gql/transport/local_schema.py b/gql/transport/local_schema.py index 18cd2982..87395b19 100644 --- a/gql/transport/local_schema.py +++ b/gql/transport/local_schema.py @@ -10,7 +10,8 @@ class LocalSchemaTransport(AsyncTransport): """A transport for executing GraphQL queries against a local schema.""" def __init__( - self, schema: GraphQLSchema, + self, + schema: GraphQLSchema, ): """Initialize the transport with the given local schema. @@ -19,20 +20,20 @@ def __init__( self.schema = schema async def connect(self): - """No connection needed on local transport - """ + """No connection needed on local transport""" pass async def close(self): - """No close needed on local transport - """ + """No close needed on local transport""" pass async def execute( - self, document: DocumentNode, *args, **kwargs, + self, + document: DocumentNode, + *args, + **kwargs, ) -> ExecutionResult: - """Execute the provided document AST for on a local GraphQL Schema. - """ + """Execute the provided document AST for on a local GraphQL Schema.""" result_or_awaitable = execute(self.schema, document, *args, **kwargs) @@ -48,7 +49,10 @@ async def execute( return execution_result async def subscribe( - self, document: DocumentNode, *args, **kwargs, + self, + document: DocumentNode, + *args, + **kwargs, ) -> AsyncGenerator[ExecutionResult, None]: """Send a subscription and receive the results using an async generator diff --git a/gql/transport/requests.py b/gql/transport/requests.py index a34e7542..690615b4 100644 --- a/gql/transport/requests.py +++ b/gql/transport/requests.py @@ -155,7 +155,8 @@ def execute( # type: ignore # If we upload files, we will extract the files present in the # variable_values dict and replace them by null values nulled_variable_values, files = extract_files( - variables=variable_values, file_classes=self.file_classes, + variables=variable_values, + file_classes=self.file_classes, ) # Save the nulled variable values in the payload diff --git a/gql/transport/transport.py b/gql/transport/transport.py index 56d882f4..a21502f0 100644 --- a/gql/transport/transport.py +++ b/gql/transport/transport.py @@ -18,8 +18,7 @@ def execute(self, document: DocumentNode, *args, **kwargs) -> ExecutionResult: ) # pragma: no cover def connect(self): - """Establish a session with the transport. - """ + """Establish a session with the transport.""" pass # pragma: no cover def close(self): diff --git a/gql/transport/websockets.py b/gql/transport/websockets.py index 1650624e..9e111551 100644 --- a/gql/transport/websockets.py +++ b/gql/transport/websockets.py @@ -152,8 +152,7 @@ async def _initialize(self): await self._send_init_message_and_wait_ack() async def send_ping(self, payload: Optional[Any] = None) -> None: - """Send a ping message for the graphql-ws protocol - """ + """Send a ping message for the graphql-ws protocol""" ping_message = {"type": "ping"} @@ -163,8 +162,7 @@ async def send_ping(self, payload: Optional[Any] = None) -> None: await self._send(json.dumps(ping_message)) async def send_pong(self, payload: Optional[Any] = None) -> None: - """Send a pong message for the graphql-ws protocol - """ + """Send a pong message for the graphql-ws protocol""" pong_message = {"type": "pong"} diff --git a/gql/transport/websockets_base.py b/gql/transport/websockets_base.py index 7a83c47f..45c96d3e 100644 --- a/gql/transport/websockets_base.py +++ b/gql/transport/websockets_base.py @@ -196,8 +196,7 @@ async def _after_initialize(self): pass # pragma: no cover async def _close_hook(self): - """Hook to add custom code for subclasses for the connection close - """ + """Hook to add custom code for subclasses for the connection close""" pass # pragma: no cover async def _connection_terminate(self): diff --git a/gql/utilities/get_introspection_query_ast.py b/gql/utilities/get_introspection_query_ast.py index d053c1c0..d35a2a75 100644 --- a/gql/utilities/get_introspection_query_ast.py +++ b/gql/utilities/get_introspection_query_ast.py @@ -48,13 +48,15 @@ def get_introspection_query_ast( if directive_is_repeatable: directives.select(ds.__Directive.isRepeatable) directives.select( - ds.__Directive.locations, ds.__Directive.args.select(fragment_InputValue), + ds.__Directive.locations, + ds.__Directive.args.select(fragment_InputValue), ) schema.select(directives) fragment_FullType.select( - ds.__Type.kind, ds.__Type.name, + ds.__Type.kind, + ds.__Type.name, ) if descriptions: fragment_FullType.select(ds.__Type.description) @@ -81,7 +83,8 @@ def get_introspection_query_ast( enum_values.select(ds.__EnumValue.description) enum_values.select( - ds.__EnumValue.isDeprecated, ds.__EnumValue.deprecationReason, + ds.__EnumValue.isDeprecated, + ds.__EnumValue.deprecationReason, ) fragment_FullType.select( @@ -98,11 +101,13 @@ def get_introspection_query_ast( fragment_InputValue.select(ds.__InputValue.description) fragment_InputValue.select( - ds.__InputValue.type.select(fragment_TypeRef), ds.__InputValue.defaultValue, + ds.__InputValue.type.select(fragment_TypeRef), + ds.__InputValue.defaultValue, ) fragment_TypeRef.select( - ds.__Type.kind, ds.__Type.name, + ds.__Type.kind, + ds.__Type.name, ) if type_recursion_level >= 1: diff --git a/setup.py b/setup.py index 07bab00e..1a46c4db 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ ] dev_requires = [ - "black==19.10b0", + "black==22.3.0", "check-manifest>=0.42,<1", "flake8==3.8.1", "isort==4.3.21", diff --git a/tests/conftest.py b/tests/conftest.py index 8d0b95ba..518d0d3a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -469,7 +469,8 @@ async def client_and_graphqlws_server(graphqlws_server): path = "/graphql" url = f"ws://{graphqlws_server.hostname}:{graphqlws_server.port}{path}" sample_transport = WebsocketsTransport( - url=url, subprotocols=[WebsocketsTransport.GRAPHQLWS_SUBPROTOCOL], + url=url, + subprotocols=[WebsocketsTransport.GRAPHQLWS_SUBPROTOCOL], ) async with Client(transport=sample_transport) as session: diff --git a/tests/custom_scalars/test_enum_colors.py b/tests/custom_scalars/test_enum_colors.py index 2c7b887c..2f15a8ca 100644 --- a/tests/custom_scalars/test_enum_colors.py +++ b/tests/custom_scalars/test_enum_colors.py @@ -71,7 +71,10 @@ def resolve_list(_root, _info): queryType = GraphQLObjectType( name="RootQueryType", fields={ - "all": GraphQLField(GraphQLList(ColorType), resolve=resolve_all,), + "all": GraphQLField( + GraphQLList(ColorType), + resolve=resolve_all, + ), "opposite": GraphQLField( ColorType, args={"color": GraphQLArgument(ColorType)}, @@ -90,7 +93,8 @@ def resolve_list(_root, _info): resolve=resolve_list_of_list, ), "list": GraphQLField( - GraphQLNonNull(GraphQLList(ColorType)), resolve=resolve_list, + GraphQLNonNull(GraphQLList(ColorType)), + resolve=resolve_list, ), }, ) diff --git a/tests/custom_scalars/test_json.py b/tests/custom_scalars/test_json.py index 9659d0a5..4c4da588 100644 --- a/tests/custom_scalars/test_json.py +++ b/tests/custom_scalars/test_json.py @@ -68,7 +68,8 @@ def resolve_players(root, _info): queryType = GraphQLObjectType( - name="Query", fields={"players": GraphQLField(JsonScalar, resolve=resolve_players)}, + name="Query", + fields={"players": GraphQLField(JsonScalar, resolve=resolve_players)}, ) diff --git a/tests/custom_scalars/test_money.py b/tests/custom_scalars/test_money.py index 23dc281d..e67a0bcd 100644 --- a/tests/custom_scalars/test_money.py +++ b/tests/custom_scalars/test_money.py @@ -155,7 +155,8 @@ def resolve_to_euros(_root, _info, money): GraphQLList(MoneyScalar), resolve=resolve_friends_balance ), "countries_balance": GraphQLField( - GraphQLNonNull(countriesBalance), resolve=resolve_countries_balance, + GraphQLNonNull(countriesBalance), + resolve=resolve_countries_balance, ), }, ) @@ -184,7 +185,10 @@ async def subscribe_spend_all(_root, _info, money): }, ) -schema = GraphQLSchema(query=queryType, subscription=subscriptionType,) +schema = GraphQLSchema( + query=queryType, + subscription=subscriptionType, +) def test_custom_scalar_in_output(): @@ -470,7 +474,9 @@ async def test_custom_scalar_in_output_with_transport(event_loop, aiohttp_server transport = await make_money_transport(aiohttp_server) - async with Client(transport=transport,) as session: + async with Client( + transport=transport, + ) as session: query = gql("{balance}") @@ -486,7 +492,9 @@ async def test_custom_scalar_in_input_query_with_transport(event_loop, aiohttp_s transport = await make_money_transport(aiohttp_server) - async with Client(transport=transport,) as session: + async with Client( + transport=transport, + ) as session: query = gql('{toEuros(money: {amount: 10, currency: "DM"})}') @@ -508,7 +516,9 @@ async def test_custom_scalar_in_input_variable_values_with_transport( transport = await make_money_transport(aiohttp_server) - async with Client(transport=transport,) as session: + async with Client( + transport=transport, + ) as session: query = gql("query myquery($money: Money) {toEuros(money: $money)}") @@ -530,7 +540,9 @@ async def test_custom_scalar_in_input_variable_values_split_with_transport( transport = await make_money_transport(aiohttp_server) - async with Client(transport=transport,) as session: + async with Client( + transport=transport, + ) as session: query = gql( """ @@ -552,7 +564,10 @@ async def test_custom_scalar_serialize_variables(event_loop, aiohttp_server): transport = await make_money_transport(aiohttp_server) - async with Client(schema=schema, transport=transport,) as session: + async with Client( + schema=schema, + transport=transport, + ) as session: query = gql("query myquery($money: Money) {toEuros(money: $money)}") @@ -571,7 +586,9 @@ async def test_custom_scalar_serialize_variables_no_schema(event_loop, aiohttp_s transport = await make_money_transport(aiohttp_server) - async with Client(transport=transport,) as session: + async with Client( + transport=transport, + ) as session: query = gql("query myquery($money: Money) {toEuros(money: $money)}") @@ -670,7 +687,9 @@ def test_update_schema_scalars_invalid_scalar_argument(): def test_update_schema_scalars_scalar_not_found_in_schema(): - NotFoundScalar = GraphQLScalarType(name="abcd",) + NotFoundScalar = GraphQLScalarType( + name="abcd", + ) with pytest.raises(KeyError) as exc_info: update_schema_scalars(schema, [MoneyScalar, NotFoundScalar]) diff --git a/tests/nested_input/schema.py b/tests/nested_input/schema.py index bd5a0507..ccdebb4a 100644 --- a/tests/nested_input/schema.py +++ b/tests/nested_input/schema.py @@ -30,4 +30,7 @@ }, ) -NestedInputSchema = GraphQLSchema(query=queryType, types=[nestedInput],) +NestedInputSchema = GraphQLSchema( + query=queryType, + types=[nestedInput], +) diff --git a/tests/starwars/fixtures.py b/tests/starwars/fixtures.py index 36232147..efbb1b0e 100644 --- a/tests/starwars/fixtures.py +++ b/tests/starwars/fixtures.py @@ -66,7 +66,11 @@ def __init__(self, id, name, friends, appearsIn, primaryFunction): ) tarkin = Human( - id="1004", name="Wilhuff Tarkin", friends=["1001"], appearsIn=[4], homePlanet=None, + id="1004", + name="Wilhuff Tarkin", + friends=["1001"], + appearsIn=[4], + homePlanet=None, ) humanData = { diff --git a/tests/starwars/schema.py b/tests/starwars/schema.py index 50e2420f..c3db0a3d 100644 --- a/tests/starwars/schema.py +++ b/tests/starwars/schema.py @@ -32,9 +32,18 @@ episode_enum = GraphQLEnumType( "Episode", { - "NEWHOPE": GraphQLEnumValue(4, description="Released in 1977.",), - "EMPIRE": GraphQLEnumValue(5, description="Released in 1980.",), - "JEDI": GraphQLEnumValue(6, description="Released in 1983.",), + "NEWHOPE": GraphQLEnumValue( + 4, + description="Released in 1977.", + ), + "EMPIRE": GraphQLEnumValue( + 5, + description="Released in 1980.", + ), + "JEDI": GraphQLEnumValue( + 6, + description="Released in 1983.", + ), }, description="One of the films in the Star Wars Trilogy", ) @@ -70,16 +79,21 @@ "Human", lambda: { "id": GraphQLField( - GraphQLNonNull(GraphQLString), description="The id of the human.", + GraphQLNonNull(GraphQLString), + description="The id of the human.", + ), + "name": GraphQLField( + GraphQLString, + description="The name of the human.", ), - "name": GraphQLField(GraphQLString, description="The name of the human.",), "friends": GraphQLField( GraphQLList(character_interface), description="The friends of the human, or an empty list if they have none.", resolve=lambda human, _info: get_friends(human), ), "appearsIn": GraphQLField( - GraphQLList(episode_enum), description="Which movies they appear in.", + GraphQLList(episode_enum), + description="Which movies they appear in.", ), "homePlanet": GraphQLField( GraphQLString, @@ -94,19 +108,25 @@ "Droid", lambda: { "id": GraphQLField( - GraphQLNonNull(GraphQLString), description="The id of the droid.", + GraphQLNonNull(GraphQLString), + description="The id of the droid.", + ), + "name": GraphQLField( + GraphQLString, + description="The name of the droid.", ), - "name": GraphQLField(GraphQLString, description="The name of the droid.",), "friends": GraphQLField( GraphQLList(character_interface), description="The friends of the droid, or an empty list if they have none.", resolve=lambda droid, _info: get_friends(droid), ), "appearsIn": GraphQLField( - GraphQLList(episode_enum), description="Which movies they appear in.", + GraphQLList(episode_enum), + description="Which movies they appear in.", ), "primaryFunction": GraphQLField( - GraphQLString, description="The primary function of the droid.", + GraphQLString, + description="The primary function of the droid.", ), }, interfaces=[character_interface], @@ -157,7 +177,8 @@ human_type, args={ "id": GraphQLArgument( - description="id of the human", type_=GraphQLNonNull(GraphQLString), + description="id of the human", + type_=GraphQLNonNull(GraphQLString), ) }, resolve=lambda _souce, _info, id: get_human(id), @@ -166,7 +187,8 @@ droid_type, args={ "id": GraphQLArgument( - description="id of the droid", type_=GraphQLNonNull(GraphQLString), + description="id of the droid", + type_=GraphQLNonNull(GraphQLString), ) }, resolve=lambda _source, _info, id: get_droid(id), @@ -175,7 +197,8 @@ GraphQLList(character_interface), args={ "ids": GraphQLArgument( - GraphQLList(GraphQLString), description="list of character ids", + GraphQLList(GraphQLString), + description="list of character ids", ) }, resolve=lambda _source, _info, ids=None: get_characters(ids), @@ -190,10 +213,12 @@ review_type, args={ "episode": GraphQLArgument( - episode_enum, description="Episode to create review", + episode_enum, + description="Episode to create review", ), "review": GraphQLArgument( - description="set alive status", type_=review_input_type, + description="set alive status", + type_=review_input_type, ), }, resolve=lambda _source, _info, episode=None, review=None: create_review( @@ -222,7 +247,8 @@ async def resolve_review(review, _info, **_args): review_type, args={ "episode": GraphQLArgument( - episode_enum, description="Episode to review", + episode_enum, + description="Episode to review", ) }, subscribe=subscribe_reviews, diff --git a/tests/starwars/test_dsl.py b/tests/starwars/test_dsl.py index 6adc84a9..50f5449c 100644 --- a/tests/starwars/test_dsl.py +++ b/tests/starwars/test_dsl.py @@ -217,7 +217,9 @@ def test_hero_name_and_friends_query(ds): query_dsl = ds.Query.hero.select( ds.Character.id, ds.Character.name, - ds.Character.friends.select(ds.Character.name,), + ds.Character.friends.select( + ds.Character.name, + ), ) assert query == str(query_dsl) @@ -225,7 +227,11 @@ def test_hero_name_and_friends_query(ds): query_dsl = ( ds.Query.hero.select(ds.Character.id) .select(ds.Character.name) - .select(ds.Character.friends.select(ds.Character.name,),) + .select( + ds.Character.friends.select( + ds.Character.name, + ), + ) ) assert query == str(query_dsl) @@ -272,7 +278,9 @@ def test_fetch_luke_query(ds): name } """.strip() - query_dsl = ds.Query.human(id="1000").select(ds.Human.name,) + query_dsl = ds.Query.human(id="1000").select( + ds.Human.name, + ) assert query == str(query_dsl) @@ -283,11 +291,23 @@ def test_fetch_luke_aliased(ds): name } """.strip() - query_dsl = ds.Query.human.args(id=1000).alias("luke").select(ds.Character.name,) + query_dsl = ( + ds.Query.human.args(id=1000) + .alias("luke") + .select( + ds.Character.name, + ) + ) assert query == str(query_dsl) # Should also work with select before alias - query_dsl = ds.Query.human.args(id=1000).select(ds.Character.name,).alias("luke") + query_dsl = ( + ds.Query.human.args(id=1000) + .select( + ds.Character.name, + ) + .alias("luke") + ) assert query == str(query_dsl) @@ -308,7 +328,9 @@ def test_fetch_name_aliased_as_kwargs(ds: DSLSchema): my_name: name } """.strip() - query_dsl = ds.Query.human.args(id=1000).select(my_name=ds.Character.name,) + query_dsl = ds.Query.human.args(id=1000).select( + my_name=ds.Character.name, + ) assert query == str(query_dsl) @@ -322,7 +344,9 @@ def test_hero_name_query_result(ds, client): def test_arg_serializer_list(ds, client): query = dsl_gql( DSLQuery( - ds.Query.characters.args(ids=[1000, 1001, 1003]).select(ds.Character.name,) + ds.Query.characters.args(ids=[1000, 1001, 1003]).select( + ds.Character.name, + ) ) ) result = client.execute(query) @@ -433,7 +457,11 @@ def test_root_fields_aliased(ds, client): def test_operation_name(ds): - query = dsl_gql(GetHeroName=DSLQuery(ds.Query.hero.select(ds.Character.name),)) + query = dsl_gql( + GetHeroName=DSLQuery( + ds.Query.hero.select(ds.Character.name), + ) + ) assert ( print_ast(query) @@ -574,7 +602,8 @@ def test_inline_fragment_in_dsl_gql(ds): query = DSLQuery() with pytest.raises( - GraphQLError, match=r"Invalid field for : ", + GraphQLError, + match=r"Invalid field for : ", ): query.select(inline_fragment) diff --git a/tests/test_appsync_auth.py b/tests/test_appsync_auth.py index 546e0e6f..cb279ae5 100644 --- a/tests/test_appsync_auth.py +++ b/tests/test_appsync_auth.py @@ -27,7 +27,8 @@ def test_appsync_init_with_no_credentials(caplog, fake_session_factory): with pytest.raises(botocore.exceptions.NoCredentialsError): sample_transport = AppSyncWebsocketsTransport( - url=mock_transport_url, session=fake_session_factory(credentials=None), + url=mock_transport_url, + session=fake_session_factory(credentials=None), ) assert sample_transport.auth is None @@ -75,7 +76,8 @@ def test_appsync_init_with_iam_auth_without_creds(fake_session_factory): from gql.transport.appsync_websockets import AppSyncWebsocketsTransport auth = AppSyncIAMAuthentication( - host=mock_transport_host, session=fake_session_factory(credentials=None), + host=mock_transport_host, + session=fake_session_factory(credentials=None), ) with pytest.raises(botocore.exceptions.NoCredentialsError): AppSyncWebsocketsTransport(url=mock_transport_url, auth=auth) @@ -105,7 +107,7 @@ def test_appsync_init_with_iam_auth_and_no_region( - you have a default region set in ~/.aws/config - you have the AWS_DEFAULT_REGION environment variable set - """ + """ from gql.transport.appsync_websockets import AppSyncWebsocketsTransport from botocore.exceptions import NoRegionError import logging diff --git a/tests/test_appsync_http.py b/tests/test_appsync_http.py index 1f787a68..ca3a3fcb 100644 --- a/tests/test_appsync_http.py +++ b/tests/test_appsync_http.py @@ -44,7 +44,9 @@ async def handler(request): host = str(urlparse(url).netloc) auth = AppSyncIAMAuthentication( - host=host, credentials=fake_credentials_factory(), region_name="us-east-1", + host=host, + credentials=fake_credentials_factory(), + region_name="us-east-1", ) sample_transport = AIOHTTPTransport(url=url, auth=auth) diff --git a/tests/test_appsync_websockets.py b/tests/test_appsync_websockets.py index f510d4a7..62816cc9 100644 --- a/tests/test_appsync_websockets.py +++ b/tests/test_appsync_websockets.py @@ -450,7 +450,8 @@ async def test_appsync_subscription_iam_without_token(event_loop, server): url = f"ws://{server.hostname}:{server.port}{path}" dummy_credentials = Credentials( - access_key=DUMMY_ACCESS_KEY_ID, secret_key=DUMMY_SECRET_ACCESS_KEY, + access_key=DUMMY_ACCESS_KEY_ID, + secret_key=DUMMY_SECRET_ACCESS_KEY, ) auth = AppSyncIAMAuthentication( @@ -475,7 +476,8 @@ async def test_appsync_execute_method_not_allowed(event_loop, server): url = f"ws://{server.hostname}:{server.port}{path}" dummy_credentials = Credentials( - access_key=DUMMY_ACCESS_KEY_ID, secret_key=DUMMY_SECRET_ACCESS_KEY, + access_key=DUMMY_ACCESS_KEY_ID, + secret_key=DUMMY_SECRET_ACCESS_KEY, ) auth = AppSyncIAMAuthentication( @@ -518,7 +520,8 @@ async def test_appsync_fetch_schema_from_transport_not_allowed(event_loop): from botocore.credentials import Credentials dummy_credentials = Credentials( - access_key=DUMMY_ACCESS_KEY_ID, secret_key=DUMMY_SECRET_ACCESS_KEY, + access_key=DUMMY_ACCESS_KEY_ID, + secret_key=DUMMY_SECRET_ACCESS_KEY, ) auth = AppSyncIAMAuthentication( diff --git a/tests/test_async_client_validation.py b/tests/test_async_client_validation.py index b588e6ba..d39019e8 100644 --- a/tests/test_async_client_validation.py +++ b/tests/test_async_client_validation.py @@ -266,7 +266,8 @@ async def test_async_client_validation_fetch_schema_from_server_with_client_argu sample_transport = WebsocketsTransport(url=url) async with Client( - transport=sample_transport, fetch_schema_from_transport=True, + transport=sample_transport, + fetch_schema_from_transport=True, ) as session: query = gql( diff --git a/tests/test_cli.py b/tests/test_cli.py index 8df47a63..ec268422 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -155,7 +155,8 @@ def test_cli_parse_variable_value_invalid_param(parser, param): @pytest.mark.aiohttp @pytest.mark.parametrize( - "url", ["http://your_server.com", "https://your_server.com"], + "url", + ["http://your_server.com", "https://your_server.com"], ) def test_cli_get_transport_aiohttp(parser, url): @@ -170,7 +171,8 @@ def test_cli_get_transport_aiohttp(parser, url): @pytest.mark.websockets @pytest.mark.parametrize( - "url", ["ws://your_server.com", "wss://your_server.com"], + "url", + ["ws://your_server.com", "wss://your_server.com"], ) def test_cli_get_transport_websockets(parser, url): @@ -185,7 +187,8 @@ def test_cli_get_transport_websockets(parser, url): @pytest.mark.websockets @pytest.mark.parametrize( - "url", ["ws://your_server.com", "wss://your_server.com"], + "url", + ["ws://your_server.com", "wss://your_server.com"], ) def test_cli_get_transport_phoenix(parser, url): @@ -224,7 +227,8 @@ def test_cli_get_transport_appsync_websockets_iam(parser, url): @pytest.mark.websockets @pytest.mark.botocore @pytest.mark.parametrize( - "url", ["wss://XXXXXX.appsync-api.eu-west-3.amazonaws.com/graphql"], + "url", + ["wss://XXXXXX.appsync-api.eu-west-3.amazonaws.com/graphql"], ) async def test_cli_main_appsync_websockets_iam(parser, url): @@ -240,7 +244,8 @@ async def test_cli_main_appsync_websockets_iam(parser, url): @pytest.mark.websockets @pytest.mark.parametrize( - "url", ["wss://XXXXXX.appsync-api.eu-west-3.amazonaws.com/graphql"], + "url", + ["wss://XXXXXX.appsync-api.eu-west-3.amazonaws.com/graphql"], ) def test_cli_get_transport_appsync_websockets_api_key(parser, url): @@ -260,7 +265,8 @@ def test_cli_get_transport_appsync_websockets_api_key(parser, url): @pytest.mark.websockets @pytest.mark.parametrize( - "url", ["wss://XXXXXX.appsync-api.eu-west-3.amazonaws.com/graphql"], + "url", + ["wss://XXXXXX.appsync-api.eu-west-3.amazonaws.com/graphql"], ) def test_cli_get_transport_appsync_websockets_jwt(parser, url): @@ -281,7 +287,8 @@ def test_cli_get_transport_appsync_websockets_jwt(parser, url): @pytest.mark.aiohttp @pytest.mark.botocore @pytest.mark.parametrize( - "url", ["https://XXXXXX.appsync-api.eu-west-3.amazonaws.com/graphql"], + "url", + ["https://XXXXXX.appsync-api.eu-west-3.amazonaws.com/graphql"], ) def test_cli_get_transport_appsync_http_iam(parser, url): @@ -296,7 +303,8 @@ def test_cli_get_transport_appsync_http_iam(parser, url): @pytest.mark.aiohttp @pytest.mark.parametrize( - "url", ["https://XXXXXX.appsync-api.eu-west-3.amazonaws.com/graphql"], + "url", + ["https://XXXXXX.appsync-api.eu-west-3.amazonaws.com/graphql"], ) def test_cli_get_transport_appsync_http_api_key(parser, url): @@ -316,7 +324,8 @@ def test_cli_get_transport_appsync_http_api_key(parser, url): @pytest.mark.aiohttp @pytest.mark.parametrize( - "url", ["https://XXXXXX.appsync-api.eu-west-3.amazonaws.com/graphql"], + "url", + ["https://XXXXXX.appsync-api.eu-west-3.amazonaws.com/graphql"], ) def test_cli_get_transport_appsync_http_jwt(parser, url): diff --git a/tests/test_client.py b/tests/test_client.py index fecdf43d..8b6575d7 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -52,7 +52,8 @@ def test_retries_on_transport(execute_mock): "Should be HTTPConnection", "Fake connection error" ) transport = RequestsHTTPTransport( - url="http://127.0.0.1:8000/graphql", retries=expected_retries, + url="http://127.0.0.1:8000/graphql", + retries=expected_retries, ) client = Client(transport=transport) @@ -136,7 +137,8 @@ def test_http_transport_verify_error(http_transport_query): with Client( transport=RequestsHTTPTransport( - url="https://countries.trevorblades.com/", verify=False, + url="https://countries.trevorblades.com/", + verify=False, ) ) as client: with pytest.warns(Warning) as record: @@ -152,7 +154,8 @@ def test_http_transport_specify_method_valid(http_transport_query): with Client( transport=RequestsHTTPTransport( - url="https://countries.trevorblades.com/", method="POST", + url="https://countries.trevorblades.com/", + method="POST", ) ) as client: result = client.execute(http_transport_query) @@ -166,7 +169,8 @@ def test_http_transport_specify_method_invalid(http_transport_query): with Client( transport=RequestsHTTPTransport( - url="https://countries.trevorblades.com/", method="GET", + url="https://countries.trevorblades.com/", + method="GET", ) ) as client: with pytest.raises(Exception) as exc_info: diff --git a/tests/test_graphqlws_subscription.py b/tests/test_graphqlws_subscription.py index 7826aca1..ade21911 100644 --- a/tests/test_graphqlws_subscription.py +++ b/tests/test_graphqlws_subscription.py @@ -533,7 +533,9 @@ async def test_graphqlws_subscription_with_ping_interval_ok( path = "/graphql" url = f"ws://{graphqlws_server.hostname}:{graphqlws_server.port}{path}" transport = WebsocketsTransport( - url=url, ping_interval=(5 * COUNTING_DELAY), pong_timeout=(4 * COUNTING_DELAY), + url=url, + ping_interval=(5 * COUNTING_DELAY), + pong_timeout=(4 * COUNTING_DELAY), ) client = Client(transport=transport) @@ -709,7 +711,7 @@ def test_graphqlws_subscription_sync(graphqlws_server, subscription_str): def test_graphqlws_subscription_sync_graceful_shutdown( graphqlws_server, subscription_str ): - """ Note: this test will simulate a control-C happening while a sync subscription + """Note: this test will simulate a control-C happening while a sync subscription is in progress. To do that we will throw a KeyboardInterrupt exception inside the subscription async generator. diff --git a/tests/test_phoenix_channel_exceptions.py b/tests/test_phoenix_channel_exceptions.py index 1711d25a..e2bf0091 100644 --- a/tests/test_phoenix_channel_exceptions.py +++ b/tests/test_phoenix_channel_exceptions.py @@ -434,7 +434,9 @@ async def test_phoenix_channel_subscription_protocol_error( @pytest.mark.asyncio @pytest.mark.parametrize( - "server", [query_server(server_error_server_answer)], indirect=True, + "server", + [query_server(server_error_server_answer)], + indirect=True, ) @pytest.mark.parametrize("query_str", [query1_str]) async def test_phoenix_channel_server_error(event_loop, server, query_str): diff --git a/tests/test_websocket_exceptions.py b/tests/test_websocket_exceptions.py index 8cccf33b..72db8a87 100644 --- a/tests/test_websocket_exceptions.py +++ b/tests/test_websocket_exceptions.py @@ -172,7 +172,10 @@ async def test_websocket_sending_invalid_payload( # Monkey patching the _send_query method to send an invalid payload async def monkey_patch_send_query( - self, document, variable_values=None, operation_name=None, + self, + document, + variable_values=None, + operation_name=None, ) -> int: query_id = self.next_query_id self.next_query_id += 1 diff --git a/tests/test_websocket_query.py b/tests/test_websocket_query.py index 2382f157..f39409f5 100644 --- a/tests/test_websocket_query.py +++ b/tests/test_websocket_query.py @@ -492,7 +492,7 @@ async def test_websocket_add_extra_parameters_to_connect(event_loop, server): url = f"ws://{server.hostname}:{server.port}/graphql" # Increase max payload size to avoid websockets.exceptions.PayloadTooBig exceptions - transport = WebsocketsTransport(url=url, connect_args={"max_size": 2 ** 21}) + transport = WebsocketsTransport(url=url, connect_args={"max_size": 2**21}) query = gql(query1_str) diff --git a/tests/test_websocket_subscription.py b/tests/test_websocket_subscription.py index 14ffe0a2..f1d72dc8 100644 --- a/tests/test_websocket_subscription.py +++ b/tests/test_websocket_subscription.py @@ -498,7 +498,7 @@ def test_websocket_subscription_sync(server, subscription_str): @pytest.mark.parametrize("server", [server_countdown], indirect=True) @pytest.mark.parametrize("subscription_str", [countdown_subscription_str]) def test_websocket_subscription_sync_graceful_shutdown(server, subscription_str): - """ Note: this test will simulate a control-C happening while a sync subscription + """Note: this test will simulate a control-C happening while a sync subscription is in progress. To do that we will throw a KeyboardInterrupt exception inside the subscription async generator.