Skip to content

Commit 8d6947a

Browse files
committed
chore: Update Schemathesis usage instructions
1 parent 65eddec commit 8d6947a

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

src/content/code/tools/schemathesis.md

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,38 @@ url: https://github.com/schemathesis/schemathesis
55
github: schemathesis/schemathesis
66
---
77

8-
Install Schemathesis via `pip`:
8+
Run Schemathesis via Docker against your GraphQL endpoint:
99

1010
```bash
11-
pip install schemathesis
11+
docker run schemathesis/schemathesis \
12+
run https://your.app.com/graphql
1213
```
1314

14-
Then, create a file `test_api.py` with the content below and replace the `URL` value with your own GraphQL endpoint URL:
15+
Schemathesis will generate queries matching your GraphQL schema and catch server crashes automatically.
16+
Generated queries have arbitrary depth and may contain any subset of GraphQL types defined in the input schema.
17+
They expose edge cases in your code that are unlikely to be found otherwise.
1518

16-
```python
17-
from hypothesis import settings
18-
import schemathesis
19+
Note that you can write your app in any programming language; the tool will communicate with it over HTTP.
1920

20-
URL = "https://your.app.com/graphql"
21-
schema = schemathesis.graphql.from_url(http://github.com/%3Cspan%20class=%22pl-c1%22%3EURL%3C/span%3E)
21+
For example, running the command above against `https://bahnql.herokuapp.com/graphql` uncovers that running the `{ search(searchTerm: "") { stations { name } } }` query leads to a server error:
2222

23-
@schema.parametrize()
24-
@settings(deadline=None)
25-
def test_api(case):
26-
response = case.call()
27-
case.validate_response(response)
2823
```
29-
30-
Then run `pytest test_api.py`. Note that you can write your app in any programming language; the tool will communicate with it over HTTP.
31-
32-
Schemathesis will generate valid queries automatically based on the schema and will minimize failing cases.
33-
For example, running the code above against `https://bahnql.herokuapp.com/graphql` uncovers that running the `{ search(searchTerm: "") { stations { name } } }` query leads to a server error:
34-
35-
```
36-
{"errors":[{"message":"Cannot read property \'city\' of undefined","locations":[{"line":1,"column":28}],"path":["search","stations"]}],"data":null}
24+
{
25+
"errors": [
26+
{
27+
"message": "Cannot read property 'city' of undefined",
28+
"locations": [
29+
{
30+
"line": 1,
31+
"column": 28
32+
}
33+
],
34+
"path": [
35+
"search",
36+
"stations"
37+
]
38+
}
39+
],
40+
"data": null
41+
}
3742
```

0 commit comments

Comments
 (0)