Skip to content

Commit bdf7763

Browse files
authored
Merge branch 'master' into specific_exceptions
2 parents b987c37 + 6dde12e commit bdf7763

File tree

4 files changed

+96
-8
lines changed

4 files changed

+96
-8
lines changed

CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/ @syrusakbary @ekampf @cito
1+
/ @syrusakbary @ekampf @cito @leszekhanusz @KingDarBoja

CONTRIBUTING.md

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,44 @@ And you ready to start development!
5757

5858
<!-- TODO: Provide environment.yml file for conda env -->
5959

60+
## Coding guidelines
61+
62+
Several tools are used to ensure a coherent coding style.
63+
You need to make sure that your code satisfy those requirements
64+
or the automated tests will fail.
65+
66+
- [black code formatter](https://github.com/psf/black)
67+
- [flake8 style enforcement](https://flake8.pycqa.org/en/latest/index.html)
68+
- [mypy static type checker](http://mypy-lang.org/)
69+
- [isort to sort imports alphabetically](https://isort.readthedocs.io/en/stable/)
70+
71+
On Linux or MacOS, you can fix and check your code style by running
72+
the Makefile command `make check` (this is also checked by running
73+
the automated tests with tox but it is much faster with make)
74+
75+
In addition to the above checks, it is asked that:
76+
77+
- [type hints are used](https://docs.python.org/3/library/typing.html)
78+
- tests are added to ensure complete code coverage
79+
6080
## Running tests
6181

6282
After developing, the full test suite can be evaluated by running:
6383

6484
```sh
65-
pytest tests --cov=gql -vv
85+
pytest tests --cov=gql --cov-report=term-missing -vv
6686
```
6787

68-
If you are using Linux or MacOS, you can make use of Makefile command
69-
`make tests`, which is a shortcut for the above python command.
88+
Please note that some tests which require external online resources are not
89+
done in the automated tests. You can run those tests by running:
90+
91+
```sh
92+
pytest tests --cov=gql --cov-report=term-missing --run-online -vv
93+
```
94+
95+
If you are using Linux or MacOS, you can make use of Makefile commands
96+
`make tests` and `make all_tests`, which are shortcuts for the above
97+
python commands.
7098

7199
You can also test on several python environments by using tox.
72100

@@ -91,7 +119,24 @@ conda install -c conda-forge tox-conda
91119

92120
This install tox underneath so no need to install it before.
93121

94-
Then uncomment the `requires = tox-conda` line on `tox.ini` file.
122+
Then add the line `requires = tox-conda` in the `tox.ini` file under `[tox]`.
95123

96124
Run `tox` and you will see all the environments being created
97125
and all passing tests. :rocket:
126+
127+
## How to create a good Pull Request
128+
129+
1. Make a fork of the master branch on github
130+
2. Clone your forked repo on your computer
131+
3. Create a feature branch `git checkout -b feature_my_awesome_feature`
132+
4. Modify the code
133+
5. Verify that the [Coding guidelines](#coding-guidelines) are respected
134+
6. Verify that the [automated tests](#running-tests) are passing
135+
7. Make a commit and push it to your fork
136+
8. From github, create the pull request. Automated tests from travis
137+
and coveralls will then automatically run the tests and check the code coverage
138+
9. If other modifications are needed, you are free to create more commits and
139+
push them on your branch. They'll get added to the PR automatically.
140+
141+
Once the Pull Request is accepted and merged, you can safely
142+
delete the branch (and the forked repo if no more development is needed).

gql/transport/aiohttp.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,15 @@ async def execute(
103103
"""
104104

105105
query_str = print_ast(document)
106-
payload = {
106+
payload: Dict[str, Any] = {
107107
"query": query_str,
108-
"variables": variable_values or {},
109-
"operationName": operation_name or "",
110108
}
111109

110+
if variable_values:
111+
payload["variables"] = variable_values
112+
if operation_name:
113+
payload["operationName"] = operation_name
114+
112115
post_args = {
113116
"json": payload,
114117
}

tests/test_aiohttp.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,43 @@ async def handler(request):
222222
africa = continents[0]
223223

224224
assert africa["code"] == "AF"
225+
226+
227+
query2_str = """
228+
query getEurope ($code: ID!) {
229+
continent (code: $code) {
230+
name
231+
}
232+
}
233+
"""
234+
235+
query2_server_answer = '{"data": {"continent": {"name": "Europe"}}}'
236+
237+
238+
@pytest.mark.asyncio
239+
async def test_aiohttp_query_variable_values(event_loop, aiohttp_server):
240+
async def handler(request):
241+
return web.Response(text=query2_server_answer, content_type="application/json")
242+
243+
app = web.Application()
244+
app.router.add_route("POST", "/", handler)
245+
server = await aiohttp_server(app)
246+
247+
url = server.make_url("/")
248+
249+
sample_transport = AIOHTTPTransport(url=url, timeout=10)
250+
251+
async with Client(transport=sample_transport,) as session:
252+
253+
params = {"code": "EU"}
254+
255+
query = gql(query2_str)
256+
257+
# Execute query asynchronously
258+
result = await session.execute(
259+
query, variable_values=params, operation_name="getEurope"
260+
)
261+
262+
continent = result["continent"]
263+
264+
assert continent["name"] == "Europe"

0 commit comments

Comments
 (0)