graphql-http 2.0.0__tar.gz → 2.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- graphql_http-2.1.2/.coverage +0 -0
- graphql_http-2.1.2/.github/workflows/pages.yml +77 -0
- graphql_http-2.1.2/.github/workflows/python-package.yml +78 -0
- graphql_http-2.1.2/.gitignore +24 -0
- graphql_http-2.1.2/.gitmodules +3 -0
- {graphql_http-2.0.0 → graphql_http-2.1.2}/PKG-INFO +72 -28
- graphql_http-2.0.0/graphql_http.egg-info/PKG-INFO → graphql_http-2.1.2/README.md +56 -40
- graphql_http-2.1.2/VERSION +1 -0
- graphql_http-2.1.2/docs/.gitmodules +3 -0
- graphql_http-2.1.2/docs/content/_index.md +91 -0
- graphql_http-2.1.2/docs/content/docs/_index.md +30 -0
- graphql_http-2.1.2/docs/content/docs/api-reference.md +447 -0
- graphql_http-2.1.2/docs/content/docs/authentication.md +388 -0
- graphql_http-2.1.2/docs/content/docs/configuration.md +291 -0
- graphql_http-2.1.2/docs/content/docs/examples.md +612 -0
- graphql_http-2.1.2/docs/content/docs/getting-started.md +189 -0
- graphql_http-2.1.2/docs/content/docs/testing.md +464 -0
- graphql_http-2.1.2/docs/hugo.toml +87 -0
- graphql_http-2.1.2/docs/index.md +3 -0
- graphql_http-2.1.2/example.graphql +6 -0
- graphql_http-2.1.2/examples/README.md +288 -0
- graphql_http-2.1.2/examples/__init__.py +1 -0
- graphql_http-2.1.2/examples/advanced_server.py +418 -0
- graphql_http-2.1.2/examples/auth_server.py +237 -0
- graphql_http-2.1.2/examples/basic_server.py +143 -0
- graphql_http-2.1.2/examples/graphql_api_server.py +329 -0
- {graphql_http-2.0.0 → graphql_http-2.1.2}/graphql_http/error.py +7 -3
- {graphql_http-2.0.0 → graphql_http-2.1.2}/graphql_http/helpers.py +9 -5
- graphql_http-2.1.2/graphql_http/introspection.py +219 -0
- {graphql_http-2.0.0 → graphql_http-2.1.2}/graphql_http/server.py +126 -47
- graphql_http-2.0.0/README.md → graphql_http-2.1.2/graphql_http.egg-info/PKG-INFO +84 -3
- graphql_http-2.1.2/graphql_http.egg-info/SOURCES.txt +56 -0
- graphql_http-2.1.2/graphql_http.egg-info/requires.txt +9 -0
- {graphql_http-2.0.0 → graphql_http-2.1.2}/graphql_http.egg-info/top_level.txt +0 -1
- graphql_http-2.1.2/pyproject.toml +77 -0
- graphql_http-2.1.2/setup.cfg +4 -0
- graphql_http-2.1.2/test_auto_discovery.py +29 -0
- graphql_http-2.1.2/test_cwd_issue.py +68 -0
- graphql_http-2.1.2/test_html_output.py +72 -0
- graphql_http-2.1.2/test_logging.py +49 -0
- graphql_http-2.1.2/test_server.py +41 -0
- {graphql_http-2.0.0 → graphql_http-2.1.2}/tests/app.py +35 -14
- {graphql_http-2.0.0 → graphql_http-2.1.2}/tests/app_federation.py +1 -1
- {graphql_http-2.0.0 → graphql_http-2.1.2}/tests/conftest.py +2 -1
- {graphql_http-2.0.0 → graphql_http-2.1.2}/tests/test_auth.py +97 -49
- {graphql_http-2.0.0 → graphql_http-2.1.2}/tests/test_cors.py +38 -38
- graphql_http-2.1.2/tests/test_examples.py +570 -0
- {graphql_http-2.0.0 → graphql_http-2.1.2}/tests/test_graphql_api.py +6 -3
- graphql_http-2.1.2/tests/test_introspection.py +335 -0
- graphql_http-2.1.2/tests/test_linting.py +120 -0
- {graphql_http-2.0.0 → graphql_http-2.1.2}/tests/test_server.py +189 -22
- graphql_http-2.1.2/uv.lock +969 -0
- graphql_http-2.0.0/MANIFEST.in +0 -4
- graphql_http-2.0.0/VERSION +0 -1
- graphql_http-2.0.0/graphql_http.egg-info/SOURCES.txt +0 -25
- graphql_http-2.0.0/graphql_http.egg-info/requires.txt +0 -7
- graphql_http-2.0.0/setup.cfg +0 -12
- graphql_http-2.0.0/setup.py +0 -44
- {graphql_http-2.0.0 → graphql_http-2.1.2}/LICENSE +0 -0
- {graphql_http-2.0.0 → graphql_http-2.1.2}/graphql_http/__init__.py +0 -0
- {graphql_http-2.0.0 → graphql_http-2.1.2}/graphql_http/graphiql/index.html +0 -0
- {graphql_http-2.0.0 → graphql_http-2.1.2}/graphql_http.egg-info/dependency_links.txt +0 -0
- {graphql_http-2.0.0 → graphql_http-2.1.2}/tests/__init__.py +0 -0
- {graphql_http-2.0.0 → graphql_http-2.1.2}/tests/test_federation.py +0 -0
|
Binary file
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
name: Deploy Hugo site to GitHub Pages
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main ]
|
|
6
|
+
paths: [ 'docs/**' ]
|
|
7
|
+
pull_request:
|
|
8
|
+
branches: [ main ]
|
|
9
|
+
paths: [ 'docs/**' ]
|
|
10
|
+
workflow_dispatch:
|
|
11
|
+
|
|
12
|
+
permissions:
|
|
13
|
+
contents: read
|
|
14
|
+
pages: write
|
|
15
|
+
id-token: write
|
|
16
|
+
|
|
17
|
+
concurrency:
|
|
18
|
+
group: "pages"
|
|
19
|
+
cancel-in-progress: false
|
|
20
|
+
|
|
21
|
+
jobs:
|
|
22
|
+
build:
|
|
23
|
+
runs-on: ubuntu-latest
|
|
24
|
+
env:
|
|
25
|
+
HUGO_VERSION: 0.146.0
|
|
26
|
+
steps:
|
|
27
|
+
- name: Checkout
|
|
28
|
+
uses: actions/checkout@v4
|
|
29
|
+
with:
|
|
30
|
+
submodules: recursive
|
|
31
|
+
fetch-depth: 0
|
|
32
|
+
- name: Install Hugo CLI
|
|
33
|
+
run: |
|
|
34
|
+
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
|
|
35
|
+
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb
|
|
36
|
+
- name: Install Dart Sass
|
|
37
|
+
run: sudo snap install dart-sass
|
|
38
|
+
- name: Setup Pages
|
|
39
|
+
id: pages
|
|
40
|
+
uses: actions/configure-pages@v4
|
|
41
|
+
with:
|
|
42
|
+
enablement: true
|
|
43
|
+
- name: Install Node.js dependencies
|
|
44
|
+
working-directory: ./docs
|
|
45
|
+
run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"
|
|
46
|
+
- name: Setup Hugo Book theme
|
|
47
|
+
working-directory: ./docs
|
|
48
|
+
run: |
|
|
49
|
+
if [ ! -d "themes/hugo-book" ]; then
|
|
50
|
+
git clone --depth 1 https://github.com/alex-shpak/hugo-book.git themes/hugo-book
|
|
51
|
+
fi
|
|
52
|
+
- name: Build with Hugo
|
|
53
|
+
env:
|
|
54
|
+
HUGO_ENVIRONMENT: production
|
|
55
|
+
HUGO_ENV: production
|
|
56
|
+
working-directory: ./docs
|
|
57
|
+
run: |
|
|
58
|
+
hugo \
|
|
59
|
+
--gc \
|
|
60
|
+
--minify \
|
|
61
|
+
--baseURL "${{ steps.pages.outputs.base_url }}/"
|
|
62
|
+
- name: Upload artifact
|
|
63
|
+
uses: actions/upload-pages-artifact@v3
|
|
64
|
+
with:
|
|
65
|
+
path: ./docs/public
|
|
66
|
+
|
|
67
|
+
deploy:
|
|
68
|
+
environment:
|
|
69
|
+
name: github-pages
|
|
70
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
71
|
+
runs-on: ubuntu-latest
|
|
72
|
+
needs: build
|
|
73
|
+
if: github.ref == 'refs/heads/main'
|
|
74
|
+
steps:
|
|
75
|
+
- name: Deploy to GitHub Pages
|
|
76
|
+
id: deployment
|
|
77
|
+
uses: actions/deploy-pages@v4
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
name: Python Package CI/CD
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main # Or your default branch
|
|
7
|
+
tags:
|
|
8
|
+
- '*.*.*' # For publishing to PyPI
|
|
9
|
+
pull_request:
|
|
10
|
+
branches:
|
|
11
|
+
- main # Or your default branch
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
build_and_test:
|
|
15
|
+
name: Build and Test (Python ${{ matrix.python-version }})
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
strategy:
|
|
18
|
+
fail-fast: false
|
|
19
|
+
matrix:
|
|
20
|
+
python-version: ["3.11", "3.12"] # graphql-api requires Python 3.11+
|
|
21
|
+
|
|
22
|
+
steps:
|
|
23
|
+
- name: Checkout repository
|
|
24
|
+
uses: actions/checkout@v4
|
|
25
|
+
|
|
26
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
27
|
+
uses: actions/setup-python@v5
|
|
28
|
+
with:
|
|
29
|
+
python-version: ${{ matrix.python-version }}
|
|
30
|
+
|
|
31
|
+
- name: Install UV
|
|
32
|
+
uses: astral-sh/setup-uv@v3
|
|
33
|
+
|
|
34
|
+
- name: Install dependencies
|
|
35
|
+
run: uv sync --dev
|
|
36
|
+
|
|
37
|
+
- name: Lint with Flake8
|
|
38
|
+
run: uv run flake8 graphql_http tests
|
|
39
|
+
|
|
40
|
+
- name: Test with Pytest
|
|
41
|
+
run: uv run pytest
|
|
42
|
+
|
|
43
|
+
publish:
|
|
44
|
+
name: Publish to PyPI
|
|
45
|
+
needs: build_and_test # Ensure tests pass before publishing
|
|
46
|
+
runs-on: ubuntu-latest
|
|
47
|
+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
|
48
|
+
permissions:
|
|
49
|
+
id-token: write
|
|
50
|
+
|
|
51
|
+
steps:
|
|
52
|
+
- name: Validate tag format (e.g., 1.0.0)
|
|
53
|
+
run: |
|
|
54
|
+
TAG_NAME="${{ github.ref_name }}"
|
|
55
|
+
if ! [[ "$TAG_NAME" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
|
56
|
+
echo "Error: Tag '$TAG_NAME' is not in the required X.Y.Z numeric format (e.g., 1.0.0)."
|
|
57
|
+
exit 1
|
|
58
|
+
fi
|
|
59
|
+
echo "Tag '$TAG_NAME' is valid."
|
|
60
|
+
shell: bash
|
|
61
|
+
|
|
62
|
+
- name: Checkout repository
|
|
63
|
+
uses: actions/checkout@v4
|
|
64
|
+
|
|
65
|
+
- name: Set up Python
|
|
66
|
+
uses: actions/setup-python@v5
|
|
67
|
+
with:
|
|
68
|
+
python-version: '3.12' # Use compatible Python version for publishing
|
|
69
|
+
|
|
70
|
+
- name: Install UV
|
|
71
|
+
uses: astral-sh/setup-uv@v3
|
|
72
|
+
|
|
73
|
+
- name: Update VERSION file
|
|
74
|
+
run: echo "${{ github.ref_name }}" > VERSION
|
|
75
|
+
shell: bash
|
|
76
|
+
|
|
77
|
+
- name: Build and publish package to PyPI
|
|
78
|
+
run: uv build && uv publish
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
*.pyc
|
|
2
|
+
.DS_Store
|
|
3
|
+
Pipfile.lock
|
|
4
|
+
|
|
5
|
+
# Build artifacts
|
|
6
|
+
build/
|
|
7
|
+
dist/
|
|
8
|
+
*.egg-info/
|
|
9
|
+
|
|
10
|
+
# Virtual environments
|
|
11
|
+
.venv/
|
|
12
|
+
venv/
|
|
13
|
+
env/
|
|
14
|
+
|
|
15
|
+
# IDE
|
|
16
|
+
.vscode/
|
|
17
|
+
.idea/
|
|
18
|
+
*.swp
|
|
19
|
+
*.swo
|
|
20
|
+
|
|
21
|
+
# Testing
|
|
22
|
+
.pytest_cache/
|
|
23
|
+
.coverage
|
|
24
|
+
htmlcov/
|
|
@@ -1,41 +1,32 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
|
-
Name:
|
|
3
|
-
Version: 2.
|
|
2
|
+
Name: graphql-http
|
|
3
|
+
Version: 2.1.2
|
|
4
4
|
Summary: HTTP Server for GraphQL.
|
|
5
|
-
|
|
6
|
-
Download-URL: https://gitlab.com/parob/graphql-http/-/archive/master/graphql-http-v2.0.0.zip
|
|
7
|
-
Author: Robert Parker
|
|
8
|
-
Author-email: rob@parob.com
|
|
5
|
+
Author-email: Robert Parker <rob@parob.com>
|
|
9
6
|
License: MIT
|
|
10
|
-
|
|
7
|
+
Project-URL: Homepage, https://gitlab.com/parob/graphql-http
|
|
8
|
+
Project-URL: Repository, https://gitlab.com/parob/graphql-http
|
|
9
|
+
Keywords: GraphQL,HTTP,Server,starlette
|
|
11
10
|
Classifier: Development Status :: 3 - Alpha
|
|
12
11
|
Classifier: Intended Audience :: Developers
|
|
13
12
|
Classifier: Programming Language :: Python :: 3
|
|
14
13
|
Classifier: License :: OSI Approved :: MIT License
|
|
15
14
|
Classifier: Operating System :: OS Independent
|
|
15
|
+
Requires-Python: <3.13,>=3.11
|
|
16
16
|
Description-Content-Type: text/markdown
|
|
17
17
|
License-File: LICENSE
|
|
18
|
-
Requires-Dist: graphql-core
|
|
19
|
-
Requires-Dist: graphql-api
|
|
20
|
-
Requires-Dist:
|
|
21
|
-
Requires-Dist:
|
|
22
|
-
Requires-Dist:
|
|
23
|
-
Requires-Dist:
|
|
24
|
-
Requires-Dist:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
Dynamic: classifier
|
|
28
|
-
Dynamic: description
|
|
29
|
-
Dynamic: description-content-type
|
|
30
|
-
Dynamic: download-url
|
|
31
|
-
Dynamic: home-page
|
|
32
|
-
Dynamic: keywords
|
|
33
|
-
Dynamic: license
|
|
18
|
+
Requires-Dist: graphql-core
|
|
19
|
+
Requires-Dist: graphql-api
|
|
20
|
+
Requires-Dist: packaging
|
|
21
|
+
Requires-Dist: graphql-schema-diff
|
|
22
|
+
Requires-Dist: pyjwt[crypto]
|
|
23
|
+
Requires-Dist: starlette
|
|
24
|
+
Requires-Dist: uvicorn
|
|
25
|
+
Requires-Dist: python-multipart
|
|
26
|
+
Requires-Dist: httpx
|
|
34
27
|
Dynamic: license-file
|
|
35
|
-
Dynamic: requires-dist
|
|
36
|
-
Dynamic: summary
|
|
37
28
|
|
|
38
|
-
# GraphQL HTTP
|
|
29
|
+
# GraphQL HTTP
|
|
39
30
|
|
|
40
31
|
A lightweight, production-ready HTTP server for GraphQL APIs built on top of Starlette/FastAPI. This server provides a simple yet powerful way to serve GraphQL schemas over HTTP with built-in support for authentication, CORS, GraphiQL integration, and more.
|
|
41
32
|
|
|
@@ -52,6 +43,11 @@ A lightweight, production-ready HTTP server for GraphQL APIs built on top of Sta
|
|
|
52
43
|
|
|
53
44
|
## Installation
|
|
54
45
|
|
|
46
|
+
```bash
|
|
47
|
+
uv add graphql_http
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Or with pip:
|
|
55
51
|
```bash
|
|
56
52
|
pip install graphql_http
|
|
57
53
|
```
|
|
@@ -114,7 +110,7 @@ server.run()
|
|
|
114
110
|
app = GraphQLHTTP(
|
|
115
111
|
schema=schema,
|
|
116
112
|
serve_graphiql=True, # Enable GraphiQL interface
|
|
117
|
-
|
|
113
|
+
graphiql_example_query="{ hello }", # Example query in GraphiQL
|
|
118
114
|
allow_cors=True, # Enable CORS
|
|
119
115
|
health_path="/health" # Health check endpoint
|
|
120
116
|
)
|
|
@@ -151,6 +147,47 @@ app = GraphQLHTTP(
|
|
|
151
147
|
)
|
|
152
148
|
```
|
|
153
149
|
|
|
150
|
+
## GraphiQL Example Queries
|
|
151
|
+
|
|
152
|
+
You can provide an example query for GraphiQL to show users how your API works. There are 3 ways to do this:
|
|
153
|
+
|
|
154
|
+
**1. Pass a string directly:**
|
|
155
|
+
```python
|
|
156
|
+
app = GraphQLHTTP(
|
|
157
|
+
schema=schema,
|
|
158
|
+
graphiql_example_query="{ users { id name } }"
|
|
159
|
+
)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
**2. Load from a file:**
|
|
163
|
+
```python
|
|
164
|
+
app = GraphQLHTTP(
|
|
165
|
+
schema=schema,
|
|
166
|
+
graphiql_example_query_path="./queries/example.graphql"
|
|
167
|
+
)
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
**3. Auto-discovery (no config needed):**
|
|
171
|
+
|
|
172
|
+
Just create a `graphiql_example.graphql` or `example.graphql` file in the directory where you run your application and the server will automatically find and use it.
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
# Create the file in your project directory
|
|
176
|
+
echo "query Example { hello }" > example.graphql
|
|
177
|
+
|
|
178
|
+
# Run your app from the same directory
|
|
179
|
+
python my_server.py
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**Note:** The file must be in your current working directory when the server starts, not necessarily where your Python script is located. If auto-discovery isn't working, enable debug logging to see where it's looking:
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
import logging
|
|
186
|
+
logging.basicConfig(level=logging.DEBUG)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
If you provide multiple sources, the string parameter takes priority, then the file path, then auto-discovery.
|
|
190
|
+
|
|
154
191
|
## API Reference
|
|
155
192
|
|
|
156
193
|
### GraphQLHTTP Class
|
|
@@ -162,7 +199,8 @@ app = GraphQLHTTP(
|
|
|
162
199
|
- `middleware` (List[Callable], optional): List of middleware functions
|
|
163
200
|
- `context_value` (Any, optional): Context passed to resolvers
|
|
164
201
|
- `serve_graphiql` (bool, default: True): Whether to serve GraphiQL interface
|
|
165
|
-
- `
|
|
202
|
+
- `graphiql_example_query` (str, optional): Example query for GraphiQL interface
|
|
203
|
+
- `graphiql_example_query_path` (str, optional): Path to file containing example query for GraphiQL
|
|
166
204
|
- `allow_cors` (bool, default: False): Enable CORS middleware
|
|
167
205
|
- `health_path` (str, optional): Path for health check endpoint
|
|
168
206
|
- `execution_context_class` (Type[ExecutionContext], optional): Custom execution context
|
|
@@ -251,6 +289,12 @@ The server provides comprehensive error handling:
|
|
|
251
289
|
|
|
252
290
|
### Running Tests
|
|
253
291
|
|
|
292
|
+
With UV:
|
|
293
|
+
```bash
|
|
294
|
+
uv run pytest tests/ -v
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
Or with Python directly:
|
|
254
298
|
```bash
|
|
255
299
|
python -m pytest tests/ -v
|
|
256
300
|
```
|
|
@@ -1,41 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Name: graphql_http
|
|
3
|
-
Version: 2.0.0
|
|
4
|
-
Summary: HTTP Server for GraphQL.
|
|
5
|
-
Home-page: https://gitlab.com/parob/graphql-http
|
|
6
|
-
Download-URL: https://gitlab.com/parob/graphql-http/-/archive/master/graphql-http-v2.0.0.zip
|
|
7
|
-
Author: Robert Parker
|
|
8
|
-
Author-email: rob@parob.com
|
|
9
|
-
License: MIT
|
|
10
|
-
Keywords: GraphQL,HTTP,Server,werkzeug
|
|
11
|
-
Classifier: Development Status :: 3 - Alpha
|
|
12
|
-
Classifier: Intended Audience :: Developers
|
|
13
|
-
Classifier: Programming Language :: Python :: 3
|
|
14
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
-
Classifier: Operating System :: OS Independent
|
|
16
|
-
Description-Content-Type: text/markdown
|
|
17
|
-
License-File: LICENSE
|
|
18
|
-
Requires-Dist: graphql-core>=3.2.0
|
|
19
|
-
Requires-Dist: graphql-api>=1.3.0
|
|
20
|
-
Requires-Dist: werkzeug>=2.2.2
|
|
21
|
-
Requires-Dist: context-helper>=1.0.2
|
|
22
|
-
Requires-Dist: packaging>=21.3
|
|
23
|
-
Requires-Dist: graphql-schema-diff>=1.2.4
|
|
24
|
-
Requires-Dist: pyjwt[crypto]==2.7.0
|
|
25
|
-
Dynamic: author
|
|
26
|
-
Dynamic: author-email
|
|
27
|
-
Dynamic: classifier
|
|
28
|
-
Dynamic: description
|
|
29
|
-
Dynamic: description-content-type
|
|
30
|
-
Dynamic: download-url
|
|
31
|
-
Dynamic: home-page
|
|
32
|
-
Dynamic: keywords
|
|
33
|
-
Dynamic: license
|
|
34
|
-
Dynamic: license-file
|
|
35
|
-
Dynamic: requires-dist
|
|
36
|
-
Dynamic: summary
|
|
37
|
-
|
|
38
|
-
# GraphQL HTTP Server
|
|
1
|
+
# GraphQL HTTP
|
|
39
2
|
|
|
40
3
|
A lightweight, production-ready HTTP server for GraphQL APIs built on top of Starlette/FastAPI. This server provides a simple yet powerful way to serve GraphQL schemas over HTTP with built-in support for authentication, CORS, GraphiQL integration, and more.
|
|
41
4
|
|
|
@@ -52,6 +15,11 @@ A lightweight, production-ready HTTP server for GraphQL APIs built on top of Sta
|
|
|
52
15
|
|
|
53
16
|
## Installation
|
|
54
17
|
|
|
18
|
+
```bash
|
|
19
|
+
uv add graphql_http
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or with pip:
|
|
55
23
|
```bash
|
|
56
24
|
pip install graphql_http
|
|
57
25
|
```
|
|
@@ -114,7 +82,7 @@ server.run()
|
|
|
114
82
|
app = GraphQLHTTP(
|
|
115
83
|
schema=schema,
|
|
116
84
|
serve_graphiql=True, # Enable GraphiQL interface
|
|
117
|
-
|
|
85
|
+
graphiql_example_query="{ hello }", # Example query in GraphiQL
|
|
118
86
|
allow_cors=True, # Enable CORS
|
|
119
87
|
health_path="/health" # Health check endpoint
|
|
120
88
|
)
|
|
@@ -151,6 +119,47 @@ app = GraphQLHTTP(
|
|
|
151
119
|
)
|
|
152
120
|
```
|
|
153
121
|
|
|
122
|
+
## GraphiQL Example Queries
|
|
123
|
+
|
|
124
|
+
You can provide an example query for GraphiQL to show users how your API works. There are 3 ways to do this:
|
|
125
|
+
|
|
126
|
+
**1. Pass a string directly:**
|
|
127
|
+
```python
|
|
128
|
+
app = GraphQLHTTP(
|
|
129
|
+
schema=schema,
|
|
130
|
+
graphiql_example_query="{ users { id name } }"
|
|
131
|
+
)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
**2. Load from a file:**
|
|
135
|
+
```python
|
|
136
|
+
app = GraphQLHTTP(
|
|
137
|
+
schema=schema,
|
|
138
|
+
graphiql_example_query_path="./queries/example.graphql"
|
|
139
|
+
)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**3. Auto-discovery (no config needed):**
|
|
143
|
+
|
|
144
|
+
Just create a `graphiql_example.graphql` or `example.graphql` file in the directory where you run your application and the server will automatically find and use it.
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
# Create the file in your project directory
|
|
148
|
+
echo "query Example { hello }" > example.graphql
|
|
149
|
+
|
|
150
|
+
# Run your app from the same directory
|
|
151
|
+
python my_server.py
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**Note:** The file must be in your current working directory when the server starts, not necessarily where your Python script is located. If auto-discovery isn't working, enable debug logging to see where it's looking:
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
import logging
|
|
158
|
+
logging.basicConfig(level=logging.DEBUG)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
If you provide multiple sources, the string parameter takes priority, then the file path, then auto-discovery.
|
|
162
|
+
|
|
154
163
|
## API Reference
|
|
155
164
|
|
|
156
165
|
### GraphQLHTTP Class
|
|
@@ -162,7 +171,8 @@ app = GraphQLHTTP(
|
|
|
162
171
|
- `middleware` (List[Callable], optional): List of middleware functions
|
|
163
172
|
- `context_value` (Any, optional): Context passed to resolvers
|
|
164
173
|
- `serve_graphiql` (bool, default: True): Whether to serve GraphiQL interface
|
|
165
|
-
- `
|
|
174
|
+
- `graphiql_example_query` (str, optional): Example query for GraphiQL interface
|
|
175
|
+
- `graphiql_example_query_path` (str, optional): Path to file containing example query for GraphiQL
|
|
166
176
|
- `allow_cors` (bool, default: False): Enable CORS middleware
|
|
167
177
|
- `health_path` (str, optional): Path for health check endpoint
|
|
168
178
|
- `execution_context_class` (Type[ExecutionContext], optional): Custom execution context
|
|
@@ -251,6 +261,12 @@ The server provides comprehensive error handling:
|
|
|
251
261
|
|
|
252
262
|
### Running Tests
|
|
253
263
|
|
|
264
|
+
With UV:
|
|
265
|
+
```bash
|
|
266
|
+
uv run pytest tests/ -v
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
Or with Python directly:
|
|
254
270
|
```bash
|
|
255
271
|
python -m pytest tests/ -v
|
|
256
272
|
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.1.2
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "GraphQL HTTP for Python"
|
|
3
|
+
type: docs
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
> **A high-performance Python HTTP server for GraphQL APIs with built-in authentication, CORS, and GraphiQL integration.**
|
|
7
|
+
|
|
8
|
+
# GraphQL HTTP for Python
|
|
9
|
+
|
|
10
|
+
[](https://badge.fury.io/py/graphql-http)
|
|
11
|
+
[](https://pypi.org/project/graphql-http/)
|
|
12
|
+
[](https://opensource.org/licenses/MIT)
|
|
13
|
+
|
|
14
|
+
## Why GraphQL HTTP?
|
|
15
|
+
|
|
16
|
+
`graphql-http` provides a production-ready HTTP server for your GraphQL APIs, built on Starlette/ASGI for excellent async performance. It handles authentication, CORS, health checks, and includes an integrated GraphiQL interface for development.
|
|
17
|
+
|
|
18
|
+
## Key Features
|
|
19
|
+
|
|
20
|
+
| Feature | Description |
|
|
21
|
+
|---------|-------------|
|
|
22
|
+
| 🚀 **High Performance** | Built on Starlette/ASGI for excellent async performance, handling thousands of concurrent requests. |
|
|
23
|
+
| 🔐 **JWT Authentication** | Built-in JWT authentication with JWKS support for secure GraphQL APIs in production. |
|
|
24
|
+
| 🌐 **CORS Support** | Configurable CORS middleware for seamless cross-origin requests. |
|
|
25
|
+
| 🎨 **GraphiQL Integration** | Interactive GraphQL IDE included for easy development and testing. |
|
|
26
|
+
| 📊 **Health Checks** | Built-in health check endpoints for monitoring and orchestration. |
|
|
27
|
+
| 🔄 **Batch Queries** | Support for batched GraphQL operations to optimize network usage. |
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
### Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install graphql-http
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Basic Usage
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from graphql import GraphQLSchema, GraphQLObjectType, GraphQLField, GraphQLString
|
|
41
|
+
from graphql_http import GraphQLHTTP
|
|
42
|
+
|
|
43
|
+
# Define your GraphQL schema
|
|
44
|
+
schema = GraphQLSchema(
|
|
45
|
+
query=GraphQLObjectType(
|
|
46
|
+
name="Query",
|
|
47
|
+
fields={
|
|
48
|
+
"hello": GraphQLField(
|
|
49
|
+
GraphQLString,
|
|
50
|
+
resolve=lambda obj, info: "Hello, World!"
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
)
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
# Create the HTTP server
|
|
57
|
+
app = GraphQLHTTP(schema=schema)
|
|
58
|
+
|
|
59
|
+
# Run the server
|
|
60
|
+
if __name__ == "__main__":
|
|
61
|
+
app.run(host="0.0.0.0", port=8000)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Visit [http://localhost:8000/graphql](http://localhost:8000/graphql) to access the GraphiQL interface.
|
|
65
|
+
|
|
66
|
+
## Integration with GraphQL-API
|
|
67
|
+
|
|
68
|
+
For advanced schema definition with automatic type inference:
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from graphql_api import GraphQLAPI
|
|
72
|
+
from graphql_http import GraphQLHTTP
|
|
73
|
+
|
|
74
|
+
api = GraphQLAPI()
|
|
75
|
+
|
|
76
|
+
@api.type(is_root_type=True)
|
|
77
|
+
class Query:
|
|
78
|
+
@api.field
|
|
79
|
+
def hello(self, name: str = "World") -> str:
|
|
80
|
+
return f"Hello, {name}!"
|
|
81
|
+
|
|
82
|
+
# Create server from API
|
|
83
|
+
server = GraphQLHTTP.from_api(api)
|
|
84
|
+
server.run()
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## What's Next?
|
|
88
|
+
|
|
89
|
+
- 📚 **[Getting Started](docs/getting-started/)** - Learn the basics with our comprehensive guide
|
|
90
|
+
- 💡 **[Examples](docs/examples/)** - Explore practical examples and tutorials for real-world scenarios
|
|
91
|
+
- 📖 **[API Reference](docs/api-reference/)** - Check out the complete API documentation
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Documentation
|
|
3
|
+
type: docs
|
|
4
|
+
bookCollapseSection: true
|
|
5
|
+
weight: 1
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# GraphQL HTTP Documentation
|
|
9
|
+
|
|
10
|
+
Welcome to the GraphQL HTTP documentation. This server provides a production-ready solution for serving GraphQL APIs over HTTP with extensive features for authentication, CORS, and development tools.
|
|
11
|
+
|
|
12
|
+
## Core Concepts
|
|
13
|
+
|
|
14
|
+
- **HTTP Server**: ASGI-based server built on Starlette for high performance
|
|
15
|
+
- **GraphQL Integration**: Seamless integration with any GraphQL schema
|
|
16
|
+
- **Authentication**: Built-in JWT authentication with JWKS support
|
|
17
|
+
- **Development Tools**: Integrated GraphiQL interface and testing utilities
|
|
18
|
+
|
|
19
|
+
## Getting Started
|
|
20
|
+
|
|
21
|
+
New to GraphQL HTTP? Start with our [Getting Started](./getting-started) guide.
|
|
22
|
+
|
|
23
|
+
## Documentation Structure
|
|
24
|
+
|
|
25
|
+
- **[Getting Started](./getting-started)**: Installation and basic setup
|
|
26
|
+
- **[Configuration](./configuration)**: Server configuration options
|
|
27
|
+
- **[Authentication](./authentication)**: JWT authentication setup
|
|
28
|
+
- **[Examples](./examples)**: Practical usage examples
|
|
29
|
+
- **[API Reference](./api-reference)**: Complete API documentation
|
|
30
|
+
- **[Testing](./testing)**: Testing your GraphQL server
|