A simple GraphQL API that returns a list of people and their details.
- Clone the repository.
- Change into the repository directory:-
$ cd people-api
- Create and activate a virtualenv with Python 3.8 or higher.
- Install the required dependencies:-
(venv) $ pip install -r requirements.txt
Run pytest to run all available tests:-
(venv) $ pytest
By default the server will listen on port 8000.
The API server can be run with uvicorn.
(venv) $ uvicorn people_api.main:app
Alternatively, the built-in strawberry server can be used:-
(venv) $ strawberry server people_api.graphql:schema
This will also expose a web-based GraphQL client and API explorer at http://localhost:8000/.
The GraphQL endpoint is exposed at /graphql
.
To perform a query using curl:-
$ curl -X POST \
-H "Content-type: application/json" \
-d '{"query": "query { people { email name address { number street city state } } }"}' \
localhost:8000/graphql
To perform a query using HTTPie:-
$ http POST :8000/graphql query="query { people { email name address { number street city state } } }"
Alternatively, use your favourite GraphQL client and point it to http://localhost:8000/graphql.
Sample query:-
query {
people {
email
name
address {
number
street
city
state
}
}
}