diff --git a/docs/code_examples/aiohttp_async.py b/docs/code_examples/aiohttp_async.py index bc615fa8..6406b089 100644 --- a/docs/code_examples/aiohttp_async.py +++ b/docs/code_examples/aiohttp_async.py @@ -13,16 +13,14 @@ async def main(): client = Client(transport=transport) # Provide a GraphQL query - query = gql( - """ + query = gql(""" query getContinents { continents { code name } } - """ - ) + """) # Using `async with` on the client will start a connection on the transport # and provide a `session` variable to execute queries on this connection diff --git a/docs/code_examples/aiohttp_multipart_subscription.py b/docs/code_examples/aiohttp_multipart_subscription.py index bb09a35c..020ee0e4 100644 --- a/docs/code_examples/aiohttp_multipart_subscription.py +++ b/docs/code_examples/aiohttp_multipart_subscription.py @@ -18,16 +18,14 @@ async def main(): ) as session: # Request subscription - subscription = gql( - """ + subscription = gql(""" subscription { book { title author } } - """ - ) + """) # Subscribe and receive streaming updates async for result in session.subscribe(subscription): diff --git a/docs/code_examples/aiohttp_sync.py b/docs/code_examples/aiohttp_sync.py index 18dab8ae..c42e4d04 100644 --- a/docs/code_examples/aiohttp_sync.py +++ b/docs/code_examples/aiohttp_sync.py @@ -8,16 +8,14 @@ client = Client(transport=transport) # Provide a GraphQL query -query = gql( - """ +query = gql(""" query getContinents { continents { code name } } -""" -) +""") # Execute the query on the transport result = client.execute(query) diff --git a/docs/code_examples/aiohttp_websockets_async.py b/docs/code_examples/aiohttp_websockets_async.py index 69520053..e64a1002 100644 --- a/docs/code_examples/aiohttp_websockets_async.py +++ b/docs/code_examples/aiohttp_websockets_async.py @@ -20,29 +20,25 @@ async def main(): ) as session: # Execute single query - query = gql( - """ + query = gql(""" query getContinents { continents { code name } } - """ - ) + """) result = await session.execute(query) print(result) # Request subscription - subscription = gql( - """ + subscription = gql(""" subscription { somethingChanged { id } } - """ - ) + """) async for result in session.subscribe(subscription): print(result) diff --git a/docs/code_examples/appsync/mutation_api_key.py b/docs/code_examples/appsync/mutation_api_key.py index 47067aca..3d7c3958 100644 --- a/docs/code_examples/appsync/mutation_api_key.py +++ b/docs/code_examples/appsync/mutation_api_key.py @@ -35,16 +35,14 @@ async def main(): fetch_schema_from_transport=False, ) as session: - query = gql( - """ + query = gql(""" mutation createMessage($message: String!) { createMessage(input: {message: $message}) { id message createdAt } -}""" - ) +}""") query.variable_values = {"message": "Hello world!"} diff --git a/docs/code_examples/appsync/mutation_iam.py b/docs/code_examples/appsync/mutation_iam.py index efe9889b..a6a04d40 100644 --- a/docs/code_examples/appsync/mutation_iam.py +++ b/docs/code_examples/appsync/mutation_iam.py @@ -34,16 +34,14 @@ async def main(): fetch_schema_from_transport=False, ) as session: - query = gql( - """ + query = gql(""" mutation createMessage($message: String!) { createMessage(input: {message: $message}) { id message createdAt } -}""" - ) +}""") query.variable_values = {"message": "Hello world!"} diff --git a/docs/code_examples/appsync/subscription_api_key.py b/docs/code_examples/appsync/subscription_api_key.py index 87bb3611..e89898a5 100644 --- a/docs/code_examples/appsync/subscription_api_key.py +++ b/docs/code_examples/appsync/subscription_api_key.py @@ -34,15 +34,13 @@ async def main(): async with Client(transport=transport) as session: - subscription = gql( - """ + subscription = gql(""" subscription onCreateMessage { onCreateMessage { message } } -""" - ) +""") print("Waiting for messages...") diff --git a/docs/code_examples/appsync/subscription_iam.py b/docs/code_examples/appsync/subscription_iam.py index 1bb540d0..bdab546b 100644 --- a/docs/code_examples/appsync/subscription_iam.py +++ b/docs/code_examples/appsync/subscription_iam.py @@ -25,15 +25,13 @@ async def main(): async with Client(transport=transport) as session: - subscription = gql( - """ + subscription = gql(""" subscription onCreateMessage { onCreateMessage { message } } -""" - ) +""") print("Waiting for messages...") diff --git a/docs/code_examples/fastapi_async.py b/docs/code_examples/fastapi_async.py index 0b174fe5..2ef2016a 100644 --- a/docs/code_examples/fastapi_async.py +++ b/docs/code_examples/fastapi_async.py @@ -22,8 +22,7 @@ client = Client(transport=transport) -query = gql( - """ +query = gql(""" query getContinentInfo($code: ID!) { continent(code:$code) { name @@ -34,8 +33,7 @@ } } } -""" -) +""") app = FastAPI() diff --git a/docs/code_examples/httpx_async.py b/docs/code_examples/httpx_async.py index 9a01232d..87278c5a 100644 --- a/docs/code_examples/httpx_async.py +++ b/docs/code_examples/httpx_async.py @@ -16,16 +16,14 @@ async def main(): ) as session: # Execute single query - query = gql( - """ + query = gql(""" query getContinents { continents { code name } } - """ - ) + """) result = await session.execute(query) print(result) diff --git a/docs/code_examples/httpx_async_trio.py b/docs/code_examples/httpx_async_trio.py index 058b952b..9dba88c2 100644 --- a/docs/code_examples/httpx_async_trio.py +++ b/docs/code_examples/httpx_async_trio.py @@ -16,16 +16,14 @@ async def main(): ) as session: # Execute single query - query = gql( - """ + query = gql(""" query getContinents { continents { code name } } - """ - ) + """) result = await session.execute(query) print(result) diff --git a/docs/code_examples/httpx_sync.py b/docs/code_examples/httpx_sync.py index bd26f658..eea8f4ed 100644 --- a/docs/code_examples/httpx_sync.py +++ b/docs/code_examples/httpx_sync.py @@ -5,16 +5,14 @@ client = Client(transport=transport, fetch_schema_from_transport=True) -query = gql( - """ +query = gql(""" query getContinents { continents { code name } } -""" -) +""") result = client.execute(query) print(result) diff --git a/docs/code_examples/phoenix_channel_async.py b/docs/code_examples/phoenix_channel_async.py index 1fdc2566..f79714e4 100644 --- a/docs/code_examples/phoenix_channel_async.py +++ b/docs/code_examples/phoenix_channel_async.py @@ -15,13 +15,11 @@ async def main(): async with Client(transport=transport) as session: # Execute single query - query = gql( - """ + query = gql(""" query yourQuery { ... } - """ - ) + """) result = await session.execute(query) print(result) diff --git a/docs/code_examples/requests_sync.py b/docs/code_examples/requests_sync.py index 2184f286..a84acc54 100644 --- a/docs/code_examples/requests_sync.py +++ b/docs/code_examples/requests_sync.py @@ -9,16 +9,14 @@ client = Client(transport=transport, fetch_schema_from_transport=True) -query = gql( - """ +query = gql(""" query getContinents { continents { code name } } -""" -) +""") result = client.execute(query) print(result) diff --git a/docs/code_examples/websockets_async.py b/docs/code_examples/websockets_async.py index e645a7ef..c674abcd 100644 --- a/docs/code_examples/websockets_async.py +++ b/docs/code_examples/websockets_async.py @@ -19,29 +19,25 @@ async def main(): ) as session: # Execute single query - query = gql( - """ + query = gql(""" query getContinents { continents { code name } } - """ - ) + """) result = await session.execute(query) print(result) # Request subscription - subscription = gql( - """ + subscription = gql(""" subscription { somethingChanged { id } } - """ - ) + """) async for result in session.subscribe(subscription): print(result) diff --git a/pyproject.toml b/pyproject.toml index f5eb5c8d..dce3a360 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "gql" readme = "README.md" -requires-python = ">=3.8.1" +requires-python = ">=3.10" dynamic = ["authors", "classifiers", "dependencies", "description", "entry-points", "keywords", "license", "optional-dependencies", "scripts", "version"] [build-system] @@ -20,3 +20,6 @@ asyncio_default_fixture_loop_scope = "function" ignore_missing_imports = true check_untyped_defs = true disallow_incomplete_defs = true + +[tool.black] +target-version = ["py310"] diff --git a/setup.py b/setup.py index e0e417c7..c64a6dd9 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ ] dev_requires = [ - "black==25.1.0", + "black==26.5.1", "check-manifest>=0.42,<1", "flake8==7.1.2", "isort==6.0.1", diff --git a/tests/custom_scalars/test_datetime.py b/tests/custom_scalars/test_datetime.py index 4d9589f1..61aef7cb 100644 --- a/tests/custom_scalars/test_datetime.py +++ b/tests/custom_scalars/test_datetime.py @@ -132,11 +132,9 @@ def test_shift_days_serialized_manually_in_query(): client = Client(schema=schema) - query = gql( - """{ + query = gql("""{ shiftDays(time: "2021-11-12T11:58:13.461161", days: 5) - }""" - ) + }""") result = client.execute(query, parse_result=True) diff --git a/tests/custom_scalars/test_enum_colors.py b/tests/custom_scalars/test_enum_colors.py index ff893571..e8ae4799 100644 --- a/tests/custom_scalars/test_enum_colors.py +++ b/tests/custom_scalars/test_enum_colors.py @@ -158,12 +158,10 @@ def test_opposite_color_variable_serialized_manually(): client = Client(schema=schema, parse_results=True) - query = gql( - """ + query = gql(""" query GetOppositeColor($color: Color) { opposite(color:$color) - }""" - ) + }""") query.variable_values = { "color": "RED", @@ -183,12 +181,10 @@ def test_opposite_color_variable_serialized_by_gql(): client = Client(schema=schema, parse_results=True) - query = gql( - """ + query = gql(""" query GetOppositeColor($color: Color) { opposite(color:$color) - }""" - ) + }""") query.variable_values = { "color": RED, @@ -306,8 +302,7 @@ def test_parse_results_with_operation_type(): client = Client(schema=schema, parse_results=True) - query = gql( - """ + query = gql(""" query GetAll { all } @@ -323,8 +318,7 @@ def test_parse_results_with_operation_type(): query GetListOfListOfList { list_of_list_of_list } - """ - ) + """) query.variable_values = { "color": "RED", diff --git a/tests/custom_scalars/test_json.py b/tests/custom_scalars/test_json.py index 903dfa6d..a709b1a9 100644 --- a/tests/custom_scalars/test_json.py +++ b/tests/custom_scalars/test_json.py @@ -112,8 +112,7 @@ def test_json_value_input_in_ast(): client = Client(schema=schema) - query = gql( - """ + query = gql(""" mutation adding_player { addPlayer(player: { name: "Tom", @@ -124,8 +123,7 @@ def test_json_value_input_in_ast(): "John" ] }) -}""" - ) +}""") result = client.execute(query, root_value=root_value) @@ -147,8 +145,7 @@ def test_json_value_input_in_ast_with_variables(): schema.type_map["Int"] = GraphQLInt schema.type_map["Float"] = GraphQLFloat - query = gql( - """ + query = gql(""" mutation adding_player( $name: String!, $level: Int!, @@ -163,8 +160,7 @@ def test_json_value_input_in_ast_with_variables(): score: $score, friends: $friends, }) -}""" - ) +}""") query.variable_values = { "name": "Barbara", @@ -200,12 +196,9 @@ def test_json_value_input_in_dsl_argument(): print(str(query)) - assert ( - strip_braces_spaces(str(query)) - == """addPlayer( + assert strip_braces_spaces(str(query)) == """addPlayer( player: {name: "Tim", level: 0, is_connected: false, score: 5, friends: ["Lea"]} )""" - ) def test_none_json_value_input_in_dsl_argument(): @@ -234,9 +227,6 @@ def test_json_value_input_with_none_list_in_dsl_argument(): print(str(query)) - assert ( - strip_braces_spaces(str(query)) - == """addPlayer( + assert strip_braces_spaces(str(query)) == """addPlayer( player: {name: "Bob", level: 9001, is_connected: true, score: 666.66, friends: null} )""" - ) diff --git a/tests/custom_scalars/test_money.py b/tests/custom_scalars/test_money.py index 55a6577a..3621bad8 100644 --- a/tests/custom_scalars/test_money.py +++ b/tests/custom_scalars/test_money.py @@ -208,8 +208,7 @@ def test_custom_scalar_in_output_embedded_fragments(): client = Client(schema=schema, parse_results=True) - query = gql( - """ + query = gql(""" fragment LuxMoneyInternal on CountriesBalance { ... on CountriesBalance { Luxembourg @@ -224,8 +223,7 @@ def test_custom_scalar_in_output_embedded_fragments(): fragment LuxMoney on CountriesBalance { ...LuxMoneyInternal } - """ - ) + """) result = client.execute(query, root_value=root_value) @@ -325,16 +323,14 @@ def test_serialize_variable_values_exception_multiple_ops_without_operation_name client = Client(schema=schema) - query = gql( - """ + query = gql(""" query myconversion($money: Money) { toEuros(money: $money) } query mybalance { balance - }""" - ) + }""") money_value = Money(10, "DM") @@ -359,13 +355,11 @@ def test_serialize_variable_values_exception_operation_name_not_found(): client = Client(schema=schema) - query = gql( - """ + query = gql(""" query myconversion($money: Money) { toEuros(money: $money) } -""" - ) +""") money_value = Money(10, "DM") @@ -556,12 +550,10 @@ async def test_custom_scalar_in_input_variable_values_split_with_transport( transport=transport, ) as session: - query = gql( - """ + query = gql(""" query myquery($amount: Float, $currency: String) { toEuros(money: {amount: $amount, currency: $currency}) -}""" - ) +}""") query.variable_values = {"amount": 10, "currency": "DM"} @@ -845,11 +837,8 @@ async def test_gql_cli_print_schema(aiohttp_server, capsys): captured_out = str(captured.out).strip() print(captured_out) - assert ( - """ + assert """ type Subscription { spend(money: Money): Money } -""".strip() - in captured_out - ) +""".strip() in captured_out diff --git a/tests/custom_scalars/test_parse_results.py b/tests/custom_scalars/test_parse_results.py index 32812818..cbf912a2 100644 --- a/tests/custom_scalars/test_parse_results.py +++ b/tests/custom_scalars/test_parse_results.py @@ -78,8 +78,7 @@ def test_parse_results_null_mapping(): """ client = Client(schema=schema, parse_results=True) - query = gql( - """query testQ($count: Int) {test(count: $count){ + query = gql("""query testQ($count: Int) {test(count: $count){ edges { node { from { @@ -90,8 +89,7 @@ def test_parse_results_null_mapping(): } } } - } }""" - ) + } }""") query.variable_values = {"count": 2} assert client.execute(query) == {"test": static_result} diff --git a/tests/starwars/test_dsl.py b/tests/starwars/test_dsl.py index cf5cbe36..301d5cb9 100644 --- a/tests/starwars/test_dsl.py +++ b/tests/starwars/test_dsl.py @@ -155,9 +155,7 @@ def test_use_variable_definition_multiple_times(ds): op.variable_definitions = var query = dsl_gql(op) - assert ( - print_ast(query.document) - == """mutation \ + assert print_ast(query.document) == """mutation \ ($badReview: ReviewInput, $episode: Episode, $goodReview: ReviewInput) { badReview: createReview(review: $badReview, episode: $episode) { stars @@ -168,7 +166,6 @@ def test_use_variable_definition_multiple_times(ds): commentary } }""" - ) assert node_tree(query.document) == node_tree( gql(print_ast(query.document)).document @@ -232,16 +229,13 @@ def test_add_variable_definitions_with_default_value_input_object(ds): op.variable_definitions = var query = dsl_gql(op) - assert ( - strip_braces_spaces(print_ast(query.document)) - == """ + assert strip_braces_spaces(print_ast(query.document)) == """ mutation ($review: ReviewInput = {stars: 5, commentary: "Wow!"}, $episode: Episode) { createReview(review: $review, episode: $episode) { stars commentary } }""".strip() - ) assert node_tree(query.document) == node_tree( gql(print_ast(query.document)).document @@ -500,15 +494,12 @@ def test_subscription(ds): ) ) ) - assert ( - print_ast(query.document) - == """subscription { + assert print_ast(query.document) == """subscription { reviewAdded(episode: JEDI) { stars commentary } }""" - ) assert node_tree(query.document) == node_tree( gql(print_ast(query.document)).document @@ -583,14 +574,11 @@ def test_operation_name(ds): ) ) - assert ( - print_ast(query.document) - == """query GetHeroName { + assert print_ast(query.document) == """query GetHeroName { hero { name } }""" - ) assert node_tree(query.document) == node_tree( gql(print_ast(query.document)).document @@ -607,9 +595,7 @@ def test_multiple_operations(ds): ), ) - assert ( - strip_braces_spaces(print_ast(query.document)) - == """query GetHeroName { + assert strip_braces_spaces(print_ast(query.document)) == """query GetHeroName { hero { name } @@ -624,7 +610,6 @@ def test_multiple_operations(ds): commentary } }""" - ) assert node_tree(query.document) == node_tree( gql(print_ast(query.document)).document diff --git a/tests/starwars/test_parse_results.py b/tests/starwars/test_parse_results.py index 2ae94ea8..fb335bf4 100644 --- a/tests/starwars/test_parse_results.py +++ b/tests/starwars/test_parse_results.py @@ -9,8 +9,7 @@ def test_hero_name_and_friends_query(): - query = gql( - """ + query = gql(""" query HeroNameAndFriendsQuery { hero { id @@ -20,8 +19,7 @@ def test_hero_name_and_friends_query(): name } } - """ - ) + """) result = { "hero": { @@ -43,8 +41,7 @@ def test_hero_name_and_friends_query(): def test_hero_name_and_friends_query_with_fragment(): """Testing for issue #445""" - query = gql( - """ + query = gql(""" query HeroNameAndFriendsQuery { hero { ...HeroSummary @@ -57,8 +54,7 @@ def test_hero_name_and_friends_query_with_fragment(): id name } - """ - ) + """) result = { "hero": { @@ -79,15 +75,13 @@ def test_hero_name_and_friends_query_with_fragment(): def test_key_not_found_in_result(): - query = gql( - """ + query = gql(""" { hero { id } } - """ - ) + """) # Backend returned an invalid result without the hero key # Should be impossible. In that case, we ignore the missing key @@ -100,15 +94,13 @@ def test_key_not_found_in_result(): def test_invalid_result_raise_error(): - query = gql( - """ + query = gql(""" { hero { id } } - """ - ) + """) result = {"hero": 5} @@ -121,8 +113,7 @@ def test_invalid_result_raise_error(): def test_fragment(): - query = gql( - """ + query = gql(""" query UseFragment { luke: human(id: "1000") { ...HumanFragment @@ -135,8 +126,7 @@ def test_fragment(): name homePlanet } - """ - ) + """) result = { "luke": {"name": "Luke Skywalker", "homePlanet": "Tatooine"}, @@ -150,15 +140,13 @@ def test_fragment(): def test_fragment_not_found(): - query = gql( - """ + query = gql(""" query UseFragment { luke: human(id: "1000") { ...HumanFragment } } - """ - ) + """) result = { "luke": {"name": "Luke Skywalker", "homePlanet": "Tatooine"}, @@ -173,15 +161,13 @@ def test_fragment_not_found(): def test_return_none_if_result_is_none(): - query = gql( - """ + query = gql(""" query { hero { id } } - """ - ) + """) result = None @@ -190,15 +176,13 @@ def test_return_none_if_result_is_none(): def test_null_result_is_allowed(): - query = gql( - """ + query = gql(""" query { hero { id } } - """ - ) + """) result = {"hero": None} @@ -209,8 +193,7 @@ def test_null_result_is_allowed(): def test_inline_fragment(): - query = gql( - """ + query = gql(""" query UseFragment { luke: human(id: "1000") { ... on Human { @@ -219,8 +202,7 @@ def test_inline_fragment(): } } } - """ - ) + """) result = { "luke": {"name": "Luke Skywalker", "homePlanet": "Tatooine"}, diff --git a/tests/starwars/test_query.py b/tests/starwars/test_query.py index ff2af7d7..ca81b12b 100644 --- a/tests/starwars/test_query.py +++ b/tests/starwars/test_query.py @@ -11,23 +11,20 @@ def client(): def test_hero_name_query(client): - query = gql( - """ + query = gql(""" query HeroNameQuery { hero { name } } - """ - ) + """) expected = {"hero": {"name": "R2-D2"}} result = client.execute(query) assert result == expected def test_hero_name_and_friends_query(client): - query = gql( - """ + query = gql(""" query HeroNameAndFriendsQuery { hero { id @@ -37,8 +34,7 @@ def test_hero_name_and_friends_query(client): } } } - """ - ) + """) expected = { "hero": { "id": "2001", @@ -55,8 +51,7 @@ def test_hero_name_and_friends_query(client): def test_nested_query(client): - query = gql( - """ + query = gql(""" query NestedQuery { hero { name @@ -69,8 +64,7 @@ def test_nested_query(client): } } } - """ - ) + """) expected = { "hero": { "name": "R2-D2", @@ -112,30 +106,26 @@ def test_nested_query(client): def test_fetch_luke_query(client): - query = gql( - """ + query = gql(""" query FetchLukeQuery { human(id: "1000") { name } } - """ - ) + """) expected = {"human": {"name": "Luke Skywalker"}} result = client.execute(query) assert result == expected def test_fetch_some_id_query(client): - query = gql( - """ + query = gql(""" query FetchSomeIDQuery($someId: String!) { human(id: $someId) { name } } - """ - ) + """) query.variable_values = { "someId": "1000", } @@ -145,15 +135,13 @@ def test_fetch_some_id_query(client): def test_fetch_some_id_query2(client): - query = gql( - """ + query = gql(""" query FetchSomeIDQuery($someId: String!) { human(id: $someId) { name } } - """ - ) + """) query.variable_values = { "someId": "1002", } @@ -163,15 +151,13 @@ def test_fetch_some_id_query2(client): def test_invalid_id_query(client): - query = gql( - """ + query = gql(""" query humanQuery($id: String!) { human(id: $id) { name } } - """ - ) + """) query.variable_values = { "id": "not a valid id", } @@ -181,23 +167,20 @@ def test_invalid_id_query(client): def test_fetch_luke_aliased(client): - query = gql( - """ + query = gql(""" query FetchLukeAliased { luke: human(id: "1000") { name } } - """ - ) + """) expected = {"luke": {"name": "Luke Skywalker"}} result = client.execute(query) assert result == expected def test_fetch_luke_and_leia_aliased(client): - query = gql( - """ + query = gql(""" query FetchLukeAndLeiaAliased { luke: human(id: "1000") { name @@ -206,16 +189,14 @@ def test_fetch_luke_and_leia_aliased(client): name } } - """ - ) + """) expected = {"luke": {"name": "Luke Skywalker"}, "leia": {"name": "Leia Organa"}} result = client.execute(query) assert result == expected def test_duplicate_fields(client): - query = gql( - """ + query = gql(""" query DuplicateFields { luke: human(id: "1000") { name @@ -226,8 +207,7 @@ def test_duplicate_fields(client): homePlanet } } - """ - ) + """) expected = { "luke": {"name": "Luke Skywalker", "homePlanet": "Tatooine"}, "leia": {"name": "Leia Organa", "homePlanet": "Alderaan"}, @@ -237,8 +217,7 @@ def test_duplicate_fields(client): def test_use_fragment(client): - query = gql( - """ + query = gql(""" query UseFragment { luke: human(id: "1000") { ...HumanFragment @@ -251,8 +230,7 @@ def test_use_fragment(client): name homePlanet } - """ - ) + """) expected = { "luke": {"name": "Luke Skywalker", "homePlanet": "Tatooine"}, "leia": {"name": "Leia Organa", "homePlanet": "Alderaan"}, @@ -262,32 +240,28 @@ def test_use_fragment(client): def test_check_type_of_r2(client): - query = gql( - """ + query = gql(""" query CheckTypeOfR2 { hero { __typename name } } - """ - ) + """) expected = {"hero": {"__typename": "Droid", "name": "R2-D2"}} result = client.execute(query) assert result == expected def test_check_type_of_luke(client): - query = gql( - """ + query = gql(""" query CheckTypeOfLuke { hero(episode: EMPIRE) { __typename name } } - """ - ) + """) expected = {"hero": {"__typename": "Human", "name": "Luke Skywalker"}} result = client.execute(query) assert result == expected @@ -295,27 +269,23 @@ def test_check_type_of_luke(client): def test_parse_error(client): with pytest.raises(Exception) as exc_info: - gql( - """ + gql(""" qeury - """ - ) + """) error = exc_info.value assert isinstance(error, GraphQLError) assert "Syntax Error: Unexpected Name 'qeury'." in str(error) def test_mutation_result(client): - query = gql( - """ + query = gql(""" mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) { createReview(episode: $ep, review: $review) { stars commentary } } - """ - ) + """) query.variable_values = { "ep": "JEDI", "review": {"stars": 5, "commentary": "This is a great movie!"}, diff --git a/tests/starwars/test_validation.py b/tests/starwars/test_validation.py index 75ce4162..129e8856 100644 --- a/tests/starwars/test_validation.py +++ b/tests/starwars/test_validation.py @@ -14,8 +14,7 @@ def local_schema(): @pytest.fixture def typedef_schema(): - return Client( - schema=""" + return Client(schema=""" schema { query: Query } @@ -53,8 +52,7 @@ def typedef_schema(): droid(id: String!): Droid hero(episode: Episode): Character human(id: String!): Human -}""" - ) +}""") @pytest.fixture diff --git a/tests/test_aiohttp_online.py b/tests/test_aiohttp_online.py index a4f2480c..556037f0 100644 --- a/tests/test_aiohttp_online.py +++ b/tests/test_aiohttp_online.py @@ -24,16 +24,14 @@ async def test_aiohttp_simple_query(): # Instanciate client async with Client(transport=transport) as session: - query = gql( - """ + query = gql(""" query getContinents { continents { code name } } - """ - ) + """) # Fetch schema await session.fetch_schema() @@ -64,16 +62,14 @@ async def test_aiohttp_invalid_query(): async with Client(transport=transport) as session: - query = gql( - """ + query = gql(""" query getContinents { continents { code bloh } } - """ - ) + """) with pytest.raises(TransportQueryError): await session.execute(query) @@ -94,25 +90,21 @@ async def test_aiohttp_two_queries_in_parallel_using_two_tasks(): # Instanciate client async with Client(transport=transport) as session: - query1 = gql( - """ + query1 = gql(""" query getContinents { continents { code } } - """ - ) + """) - query2 = gql( - """ + query2 = gql(""" query getContinents { continents { name } } - """ - ) + """) async def query_task1(): result = await session.execute(query1) diff --git a/tests/test_appsync_http.py b/tests/test_appsync_http.py index 168924bc..c080da46 100644 --- a/tests/test_appsync_http.py +++ b/tests/test_appsync_http.py @@ -53,16 +53,14 @@ async def handler(request): async with Client(transport=transport) as session: - query = gql( - """ + query = gql(""" mutation createMessage($message: String!) { createMessage(input: {message: $message}) { id message createdAt } -}""" - ) +}""") # Execute query asynchronously execution_result = await session.execute(query, get_execution_result=True) diff --git a/tests/test_appsync_websockets.py b/tests/test_appsync_websockets.py index b2299960..b92da159 100644 --- a/tests/test_appsync_websockets.py +++ b/tests/test_appsync_websockets.py @@ -503,16 +503,14 @@ async def test_appsync_execute_method_not_allowed(server): client = Client(transport=transport) async with client as session: - query = gql( - """ + query = gql(""" mutation createMessage($message: String!) { createMessage(input: {message: $message}) { id message createdAt } -}""" - ) +}""") query.variable_values = {"message": "Hello world!"} diff --git a/tests/test_async_client_validation.py b/tests/test_async_client_validation.py index ec73593e..e80e91ee 100644 --- a/tests/test_async_client_validation.py +++ b/tests/test_async_client_validation.py @@ -202,15 +202,13 @@ async def test_async_client_validation_fetch_schema_from_server_valid_query( assert client.introspection == StarWarsIntrospection assert client.schema is not None - query = gql( - """ + query = gql(""" query HeroNameQuery { hero { name } } - """ - ) + """) result = await session.execute(query) @@ -231,16 +229,14 @@ async def test_async_client_validation_fetch_schema_from_server_invalid_query( # Fetch schema from server await session.fetch_schema() - query = gql( - """ + query = gql(""" query HeroNameQuery { hero { name sldkfjqlmsdkjfqlskjfmlqkjsfmkjqsdf } } - """ - ) + """) with pytest.raises(graphql.error.GraphQLError): await session.execute(query) @@ -264,16 +260,14 @@ async def test_async_client_validation_fetch_schema_from_server_with_client_argu fetch_schema_from_transport=True, ) as session: - query = gql( - """ + query = gql(""" query HeroNameQuery { hero { name sldkfjqlmsdkjfqlskjfmlqkjsfmkjqsdf } } - """ - ) + """) with pytest.raises(graphql.error.GraphQLError): await session.execute(query) diff --git a/tests/test_client.py b/tests/test_client.py index 4e2e9bca..97118cae 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -16,16 +16,14 @@ @pytest.fixture def http_transport_query(): - return gql( - """ + return gql(""" query getContinents { continents { code name } } - """ - ) + """) def test_request_transport_not_implemented(http_transport_query): @@ -74,8 +72,7 @@ def test_retries_on_transport(execute_mock): ) client = Client(transport=transport) - query = gql( - """ + query = gql(""" { myFavoriteFilm: film(id:"RmlsbToz") { id @@ -83,8 +80,7 @@ def test_retries_on_transport(execute_mock): episodeId } } - """ - ) + """) with client as session: # We're using the client as context manager with pytest.raises(Exception): session.execute(query) @@ -123,8 +119,7 @@ def test_execute_result_error(): transport=RequestsHTTPTransport(url="https://countries.trevorblades.com/"), ) - failing_query = gql( - """ + failing_query = gql(""" query getContinents { continents { code @@ -132,8 +127,7 @@ def test_execute_result_error(): id } } - """ - ) + """) with pytest.raises(TransportQueryError) as exc_info: client.execute(failing_query) @@ -214,16 +208,14 @@ def test_gql(): schema = build_ast_schema(document) - query = gql( - """ + query = gql(""" query getUser { user(id: "1000") { id username } } - """ - ) + """) client = Client(schema=schema) result = client.execute(query) diff --git a/tests/test_http_async_sync.py b/tests/test_http_async_sync.py index 61dc1809..c8bcd147 100644 --- a/tests/test_http_async_sync.py +++ b/tests/test_http_async_sync.py @@ -23,16 +23,14 @@ async def test_async_client_async_transport(fetch_schema_from_transport): fetch_schema_from_transport=fetch_schema_from_transport, ) as session: - query = gql( - """ + query = gql(""" query getContinents { continents { code name } } - """ - ) + """) # Execute query result = await session.execute(query) @@ -90,16 +88,14 @@ def test_sync_client_async_transport(fetch_schema_from_transport): fetch_schema_from_transport=fetch_schema_from_transport, ) - query = gql( - """ + query = gql(""" query getContinents { continents { code name } } - """ - ) + """) # Execute query synchronously result = client.execute(query) @@ -133,16 +129,14 @@ def test_sync_client_sync_transport(fetch_schema_from_transport): fetch_schema_from_transport=fetch_schema_from_transport, ) - query = gql( - """ + query = gql(""" query getContinents { continents { code name } } - """ - ) + """) # Execute query synchronously result = client.execute(query) diff --git a/tests/test_httpx_online.py b/tests/test_httpx_online.py index c6e84368..25bb25fe 100644 --- a/tests/test_httpx_online.py +++ b/tests/test_httpx_online.py @@ -24,16 +24,14 @@ async def test_httpx_simple_query(): # Instanciate client async with Client(transport=transport) as session: - query = gql( - """ + query = gql(""" query getContinents { continents { code name } } - """ - ) + """) # Fetch schema await session.fetch_schema() @@ -64,16 +62,14 @@ async def test_httpx_invalid_query(): async with Client(transport=transport) as session: - query = gql( - """ + query = gql(""" query getContinents { continents { code bloh } } - """ - ) + """) with pytest.raises(TransportQueryError): await session.execute(query) @@ -94,25 +90,21 @@ async def test_httpx_two_queries_in_parallel_using_two_tasks(): # Instanciate client async with Client(transport=transport) as session: - query1 = gql( - """ + query1 = gql(""" query getContinents { continents { code } } - """ - ) + """) - query2 = gql( - """ + query2 = gql(""" query getContinents { continents { name } } - """ - ) + """) async def query_task1(): result = await session.execute(query1) diff --git a/tests/test_requests_batch.py b/tests/test_requests_batch.py index b9732639..93264824 100644 --- a/tests/test_requests_batch.py +++ b/tests/test_requests_batch.py @@ -597,15 +597,13 @@ def test_requests_sync_batch_auto(): batch_max=3, ) - query = gql( - """ + query = gql(""" query getContinentName($continent_code: ID!) { continent(code: $continent_code) { name } } - """ - ) + """) def get_continent_name(session, continent_code): variables = { diff --git a/tests/test_transport.py b/tests/test_transport.py index 132fa11f..da1a48c9 100644 --- a/tests/test_transport.py +++ b/tests/test_transport.py @@ -77,8 +77,7 @@ def client(): def test_hero_name_query(client): - query = gql( - """ + query = gql(""" { myFavoriteFilm: film(id:"RmlsbToz") { id @@ -93,8 +92,7 @@ def test_hero_name_query(client): } } } - """ - ) + """) expected = { "myFavoriteFilm": { "id": "RmlsbToz", @@ -117,16 +115,14 @@ def test_hero_name_query(client): def test_query_with_variable(client): - query = gql( - """ + query = gql(""" query Planet($id: ID!) { planet(id: $id) { id name } } - """ - ) + """) query.variable_values = {"id": "UGxhbmV0OjEw"} expected = {"planet": {"id": "UGxhbmV0OjEw", "name": "Kamino"}} with use_cassette("queries"): @@ -135,8 +131,7 @@ def test_query_with_variable(client): def test_named_query(client): - query = gql( - """ + query = gql(""" query Planet1 { planet(id: "UGxhbmV0OjEw") { id @@ -149,8 +144,7 @@ def test_named_query(client): name } } - """ - ) + """) query.operation_name = "Planet2" expected = {"planet": {"id": "UGxhbmV0OjEx", "name": "Geonosis"}} with use_cassette("queries"): @@ -159,16 +153,14 @@ def test_named_query(client): def test_header_query(client): - query = gql( - """ + query = gql(""" query Planet($id: ID!) { planet(id: $id) { id name } } - """ - ) + """) expected = {"planet": {"id": "UGxhbmV0OjEx", "name": "Geonosis"}} with use_cassette("queries"): result = client.execute( diff --git a/tests/test_transport_batch.py b/tests/test_transport_batch.py index b0edf015..c3b49d5c 100644 --- a/tests/test_transport_batch.py +++ b/tests/test_transport_batch.py @@ -77,8 +77,7 @@ def client(): def test_hero_name_query(client): - query = gql( - """ + query = gql(""" { myFavoriteFilm: film(id:"RmlsbToz") { id @@ -93,8 +92,7 @@ def test_hero_name_query(client): } } } - """ - ) + """) expected = [ { "myFavoriteFilm": { @@ -119,16 +117,14 @@ def test_hero_name_query(client): def test_query_with_variable(client): - query = gql( - """ + query = gql(""" query Planet($id: ID!) { planet(id: $id) { id name } } - """ - ) + """) query.variable_values = {"id": "UGxhbmV0OjEw"} expected = [{"planet": {"id": "UGxhbmV0OjEw", "name": "Kamino"}}] with use_cassette("queries_batch"): @@ -137,8 +133,7 @@ def test_query_with_variable(client): def test_named_query(client): - query = gql( - """ + query = gql(""" query Planet1 { planet(id: "UGxhbmV0OjEw") { id @@ -151,8 +146,7 @@ def test_named_query(client): name } } - """ - ) + """) query.operation_name = "Planet2" expected = [{"planet": {"id": "UGxhbmV0OjEx", "name": "Geonosis"}}] with use_cassette("queries_batch"): @@ -161,16 +155,14 @@ def test_named_query(client): def test_header_query(client): - query = gql( - """ + query = gql(""" query Planet($id: ID!) { planet(id: $id) { id name } } - """ - ) + """) expected = [{"planet": {"id": "UGxhbmV0OjEx", "name": "Geonosis"}}] with use_cassette("queries_batch"): results = client.execute_batch( diff --git a/tests/test_websocket_online.py b/tests/test_websocket_online.py index c53be5f4..32b131c9 100644 --- a/tests/test_websocket_online.py +++ b/tests/test_websocket_online.py @@ -32,16 +32,14 @@ async def test_websocket_simple_query(): # Instanciate client async with Client(transport=transport) as session: - query = gql( - """ + query = gql(""" query getContinents { continents { code name } } - """ - ) + """) # Fetch schema await session.fetch_schema() @@ -73,16 +71,14 @@ async def test_websocket_invalid_query(): # Instanciate client async with Client(transport=transport) as session: - query = gql( - """ + query = gql(""" query getContinents { continents { code bloh } } - """ - ) + """) # Execute query with pytest.raises(TransportQueryError): @@ -103,15 +99,13 @@ async def test_websocket_sending_invalid_data(): # Instanciate client async with Client(transport=transport) as session: - query = gql( - """ + query = gql(""" query getContinents { continents { code } } - """ - ) + """) # Execute query result = await session.execute(query) @@ -163,15 +157,13 @@ async def test_websocket_sending_invalid_data_while_other_query_is_running(): # Instanciate client async with Client(transport=transport) as session: - query = gql( - """ + query = gql(""" query getContinents { continents { code } } - """ - ) + """) async def query_task1(): await asyncio.sleep(2 * MS) @@ -215,25 +207,21 @@ async def test_websocket_two_queries_in_parallel_using_two_tasks(): # Instanciate client async with Client(transport=transport) as session: - query1 = gql( - """ + query1 = gql(""" query getContinents { continents { code } } - """ - ) + """) - query2 = gql( - """ + query2 = gql(""" query getContinents { continents { name } } - """ - ) + """) async def query_task1(): result = await session.execute(query1)