https://github.com/gabrielfu/graphqlpython
Example GraphQL server with PostgreSQL db
https://github.com/gabrielfu/graphqlpython
fastapi graphene graphql postgresql python
Last synced: 3 months ago
JSON representation
Example GraphQL server with PostgreSQL db
- Host: GitHub
- URL: https://github.com/gabrielfu/graphqlpython
- Owner: gabrielfu
- Created: 2023-02-15T08:43:14.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-02-16T07:30:24.000Z (over 3 years ago)
- Last Synced: 2025-05-25T14:46:37.891Z (about 1 year ago)
- Topics: fastapi, graphene, graphql, postgresql, python
- Language: Python
- Homepage:
- Size: 90.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GraphQL Server
This is a toy example of GraphQL FastAPI server for a modified version of
[IMDB dataset](https://www.imdb.com/interfaces/), retrieved on 15 Feb 2023.
The backend database is a PostgreSQL db.
## Usage
Run server:
```shell
docker-compose up --build -d
```
Example Query:
```python
import requests
url = "http://localhost:8000/graphql"
body = """
{
actor (primaryName: "Chris Hemsworth") {
primaryName,
birthYear,
movies {
edges {
node {
primaryTitle,
region,
startYear,
runtimeMinutes,
averageRating,
numVotes
}
}
}
}
}
"""
r = requests.post(url=url, json={"query": body})
r.raise_for_status()
r.json()
# output:
# {'data': {'actor': {'primaryName': 'Chris Hemsworth',
# 'birthYear': 1983,
# 'movies': {'edges': [{'node': {'primaryTitle': 'Thor: Ragnarok',
# 'region': 'US',
# 'startYear': 2017,
# 'runtimeMinutes': 130,
# 'averageRating': 7.9,
# 'numVotes': 761413}},
# {'node': {'primaryTitle': 'The Cabin in the Woods',
# 'region': 'US',
# 'startYear': 2011,
# 'runtimeMinutes': 95,
# 'averageRating': 7.0,
# 'numVotes': 425020}},
# {'node': {'primaryTitle': 'Avengers: Infinity War',
# 'region': 'US',
# 'startYear': 2018,
# 'runtimeMinutes': 149,
# 'averageRating': 8.4,
# 'numVotes': 1094492}},
# {'node': {'primaryTitle': 'Avengers: Endgame',
# 'region': 'US',
# 'startYear': 2019,
# 'runtimeMinutes': 181,
# 'averageRating': 8.4,
# 'numVotes': 1147208}}]}}}}
```