graphql-http 2.0.0__tar.gz → 2.0.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.
Files changed (40) hide show
  1. graphql_http-2.0.2/.coverage +0 -0
  2. graphql_http-2.0.2/.github/workflows/python-package.yml +78 -0
  3. graphql_http-2.0.2/.gitignore +24 -0
  4. {graphql_http-2.0.0/graphql_http.egg-info → graphql_http-2.0.2}/PKG-INFO +26 -24
  5. {graphql_http-2.0.0 → graphql_http-2.0.2}/README.md +11 -0
  6. graphql_http-2.0.2/VERSION +1 -0
  7. graphql_http-2.0.2/examples/README.md +288 -0
  8. graphql_http-2.0.2/examples/advanced_server.py +411 -0
  9. graphql_http-2.0.2/examples/auth_server.py +234 -0
  10. graphql_http-2.0.2/examples/basic_server.py +139 -0
  11. graphql_http-2.0.2/examples/graphql_api_server.py +367 -0
  12. {graphql_http-2.0.0 → graphql_http-2.0.2}/graphql_http/error.py +2 -1
  13. {graphql_http-2.0.0 → graphql_http-2.0.2}/graphql_http/helpers.py +9 -5
  14. {graphql_http-2.0.0 → graphql_http-2.0.2}/graphql_http/server.py +18 -9
  15. {graphql_http-2.0.0 → graphql_http-2.0.2/graphql_http.egg-info}/PKG-INFO +26 -24
  16. {graphql_http-2.0.0 → graphql_http-2.0.2}/graphql_http.egg-info/SOURCES.txt +11 -3
  17. graphql_http-2.0.2/graphql_http.egg-info/requires.txt +9 -0
  18. {graphql_http-2.0.0 → graphql_http-2.0.2}/graphql_http.egg-info/top_level.txt +0 -1
  19. graphql_http-2.0.2/pyproject.toml +77 -0
  20. graphql_http-2.0.2/setup.cfg +4 -0
  21. graphql_http-2.0.2/test_server.py +41 -0
  22. {graphql_http-2.0.0 → graphql_http-2.0.2}/tests/app.py +33 -12
  23. {graphql_http-2.0.0 → graphql_http-2.0.2}/tests/conftest.py +2 -1
  24. {graphql_http-2.0.0 → graphql_http-2.0.2}/tests/test_auth.py +23 -24
  25. {graphql_http-2.0.0 → graphql_http-2.0.2}/tests/test_cors.py +35 -35
  26. {graphql_http-2.0.0 → graphql_http-2.0.2}/tests/test_graphql_api.py +6 -3
  27. {graphql_http-2.0.0 → graphql_http-2.0.2}/tests/test_server.py +14 -17
  28. graphql_http-2.0.2/uv.lock +969 -0
  29. graphql_http-2.0.0/MANIFEST.in +0 -4
  30. graphql_http-2.0.0/VERSION +0 -1
  31. graphql_http-2.0.0/graphql_http.egg-info/requires.txt +0 -7
  32. graphql_http-2.0.0/setup.cfg +0 -12
  33. graphql_http-2.0.0/setup.py +0 -44
  34. {graphql_http-2.0.0 → graphql_http-2.0.2}/LICENSE +0 -0
  35. {graphql_http-2.0.0 → graphql_http-2.0.2}/graphql_http/__init__.py +0 -0
  36. {graphql_http-2.0.0 → graphql_http-2.0.2}/graphql_http/graphiql/index.html +0 -0
  37. {graphql_http-2.0.0 → graphql_http-2.0.2}/graphql_http.egg-info/dependency_links.txt +0 -0
  38. {graphql_http-2.0.0 → graphql_http-2.0.2}/tests/__init__.py +0 -0
  39. {graphql_http-2.0.0 → graphql_http-2.0.2}/tests/app_federation.py +0 -0
  40. {graphql_http-2.0.0 → graphql_http-2.0.2}/tests/test_federation.py +0 -0
Binary file
@@ -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,39 +1,30 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: graphql_http
3
- Version: 2.0.0
3
+ Version: 2.0.2
4
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
5
+ Author-email: Robert Parker <rob@parob.com>
9
6
  License: MIT
10
- Keywords: GraphQL,HTTP,Server,werkzeug
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>=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
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
29
  # GraphQL HTTP Server
39
30
 
@@ -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
  ```
@@ -251,6 +247,12 @@ The server provides comprehensive error handling:
251
247
 
252
248
  ### Running Tests
253
249
 
250
+ With UV:
251
+ ```bash
252
+ uv run pytest tests/ -v
253
+ ```
254
+
255
+ Or with Python directly:
254
256
  ```bash
255
257
  python -m pytest tests/ -v
256
258
  ```
@@ -15,6 +15,11 @@ A lightweight, production-ready HTTP server for GraphQL APIs built on top of Sta
15
15
 
16
16
  ## Installation
17
17
 
18
+ ```bash
19
+ uv add graphql_http
20
+ ```
21
+
22
+ Or with pip:
18
23
  ```bash
19
24
  pip install graphql_http
20
25
  ```
@@ -214,6 +219,12 @@ The server provides comprehensive error handling:
214
219
 
215
220
  ### Running Tests
216
221
 
222
+ With UV:
223
+ ```bash
224
+ uv run pytest tests/ -v
225
+ ```
226
+
227
+ Or with Python directly:
217
228
  ```bash
218
229
  python -m pytest tests/ -v
219
230
  ```
@@ -0,0 +1 @@
1
+ 2.0.2
@@ -0,0 +1,288 @@
1
+ # GraphQL HTTP Server Examples
2
+
3
+ This directory contains practical examples demonstrating different use cases and features of the GraphQL HTTP server.
4
+
5
+ ## Available Examples
6
+
7
+ ### 1. Basic Server (`basic_server.py`)
8
+
9
+ **What it demonstrates:**
10
+ - Simple GraphQL schema definition
11
+ - Basic queries and mutations
12
+ - GraphiQL integration
13
+ - Sample data with resolvers
14
+
15
+ **How to run:**
16
+ ```bash
17
+ python examples/basic_server.py
18
+ ```
19
+
20
+ **Features shown:**
21
+ - Book catalog API with queries and mutations
22
+ - Basic GraphQL types (String, Int, List)
23
+ - Simple resolver functions
24
+ - GraphiQL with default query
25
+
26
+ **Try these queries:**
27
+ ```graphql
28
+ # Get all books
29
+ {
30
+ books {
31
+ id
32
+ title
33
+ author
34
+ }
35
+ }
36
+
37
+ # Get a specific book
38
+ {
39
+ book(id: 1) {
40
+ title
41
+ author
42
+ }
43
+ }
44
+
45
+ # Add a new book
46
+ mutation {
47
+ addBook(title: "New Book", author: "New Author") {
48
+ id
49
+ title
50
+ author
51
+ }
52
+ }
53
+ ```
54
+
55
+ ### 2. Authentication Server (`auth_server.py`)
56
+
57
+ **What it demonstrates:**
58
+ - JWT authentication configuration
59
+ - CORS setup
60
+ - Protected and public endpoints
61
+ - Environment-based configuration
62
+
63
+ **How to run:**
64
+ ```bash
65
+ # Without authentication (development mode)
66
+ python examples/auth_server.py
67
+
68
+ # With authentication enabled
69
+ ENABLE_AUTH=true python examples/auth_server.py
70
+ ```
71
+
72
+ **Environment variables:**
73
+ ```bash
74
+ export ENABLE_AUTH=true
75
+ export JWKS_URI=https://your-auth0-domain.auth0.com/.well-known/jwks.json
76
+ export JWT_ISSUER=https://your-auth0-domain.auth0.com/
77
+ export JWT_AUDIENCE=your-api-identifier
78
+ ```
79
+
80
+ **Features shown:**
81
+ - JWT token validation
82
+ - JWKS integration
83
+ - Public vs protected fields
84
+ - Introspection without authentication
85
+ - CORS configuration
86
+ - Health check endpoint
87
+
88
+ ### 3. GraphQL-API Integration (`graphql_api_server.py`)
89
+
90
+ **What it demonstrates:**
91
+ - Integration with the `graphql-api` package
92
+ - Automatic type inference
93
+ - Dataclass integration
94
+ - Advanced schema patterns
95
+
96
+ **Prerequisites:**
97
+ ```bash
98
+ pip install graphql-api
99
+ ```
100
+
101
+ **How to run:**
102
+ ```bash
103
+ python examples/graphql_api_server.py
104
+ ```
105
+
106
+ **Features shown:**
107
+ - Automatic Python type to GraphQL type conversion
108
+ - Dataclass models
109
+ - Relationship resolution
110
+ - Context injection
111
+ - Advanced querying patterns
112
+ - Automatic resolver generation
113
+
114
+ **Try these queries:**
115
+ ```graphql
116
+ # Get authors with their posts and comments
117
+ {
118
+ authors {
119
+ id
120
+ name
121
+ posts {
122
+ id
123
+ title
124
+ published
125
+ comments {
126
+ id
127
+ authorName
128
+ content
129
+ }
130
+ }
131
+ }
132
+ }
133
+
134
+ # Search functionality
135
+ {
136
+ searchPosts(query: "GraphQL") {
137
+ id
138
+ title
139
+ content
140
+ }
141
+ }
142
+ ```
143
+
144
+ ### 4. Advanced Server (`advanced_server.py`)
145
+
146
+ **What it demonstrates:**
147
+ - Custom middleware implementation
148
+ - Performance monitoring
149
+ - Error handling strategies
150
+ - Custom execution context
151
+ - Caching middleware
152
+
153
+ **How to run:**
154
+ ```bash
155
+ python examples/advanced_server.py
156
+ ```
157
+
158
+ **Features shown:**
159
+ - Performance monitoring middleware
160
+ - Simple in-memory caching
161
+ - Authentication middleware
162
+ - Custom execution context for metrics
163
+ - Custom request context
164
+ - Slow field detection
165
+ - Error handling and validation
166
+
167
+ **Testing tips:**
168
+ - Set `X-User-ID: admin123` header for admin access
169
+ - Watch console for performance metrics
170
+ - Try the `slowField` and `errorField` for testing
171
+ - Run the same query twice to see caching in action
172
+
173
+ ## Running the Examples
174
+
175
+ ### Prerequisites
176
+
177
+ 1. Install the package:
178
+ ```bash
179
+ pip install graphql_http
180
+ ```
181
+
182
+ 2. For the GraphQL-API example:
183
+ ```bash
184
+ pip install graphql-api
185
+ ```
186
+
187
+ ### Quick Start
188
+
189
+ 1. Choose an example that matches your use case
190
+ 2. Run the Python file
191
+ 3. Open http://localhost:8000/graphql in your browser
192
+ 4. Explore the GraphiQL interface
193
+ 5. Try the sample queries provided
194
+
195
+ ### Common Patterns
196
+
197
+ All examples include:
198
+ - GraphiQL interface at `/graphql`
199
+ - Health check endpoint at `/health` (where configured)
200
+ - CORS support for web applications
201
+ - Comprehensive error handling
202
+ - Sample queries in GraphiQL
203
+
204
+ ## Example Use Cases
205
+
206
+ ### Development and Testing
207
+ Start with `basic_server.py` to understand the fundamentals.
208
+
209
+ ### Production Applications
210
+ Use `auth_server.py` as a template for applications requiring authentication.
211
+
212
+ ### Advanced Type Systems
213
+ Use `graphql_api_server.py` for complex schemas with relationships.
214
+
215
+ ### Performance and Monitoring
216
+ Use `advanced_server.py` for applications requiring performance monitoring and custom middleware.
217
+
218
+ ## Customization
219
+
220
+ Each example is designed to be easily customizable:
221
+
222
+ 1. **Modify the data models** to match your domain
223
+ 2. **Update resolver functions** to connect to your data sources
224
+ 3. **Configure authentication** with your auth provider
225
+ 4. **Add custom middleware** for your specific requirements
226
+ 5. **Extend the schema** with additional fields and types
227
+
228
+ ## Common Configuration Options
229
+
230
+ ### CORS Configuration
231
+ ```python
232
+ server = GraphQLHTTP(
233
+ schema=schema,
234
+ allow_cors=True, # Enable CORS for web apps
235
+ )
236
+ ```
237
+
238
+ ### GraphiQL Customization
239
+ ```python
240
+ server = GraphQLHTTP(
241
+ schema=schema,
242
+ serve_graphiql=True,
243
+ graphiql_default_query="{ hello }", # Default query
244
+ )
245
+ ```
246
+
247
+ ### Health Checks
248
+ ```python
249
+ server = GraphQLHTTP(
250
+ schema=schema,
251
+ health_path="/health", # Enable health endpoint
252
+ )
253
+ ```
254
+
255
+ ### Authentication
256
+ ```python
257
+ server = GraphQLHTTP(
258
+ schema=schema,
259
+ auth_enabled=True,
260
+ auth_jwks_uri="https://your-domain/.well-known/jwks.json",
261
+ auth_issuer="https://your-domain/",
262
+ auth_audience="your-audience",
263
+ )
264
+ ```
265
+
266
+ ## Troubleshooting
267
+
268
+ ### Common Issues
269
+
270
+ 1. **Port already in use**: Change the port in `server.run(port=8001)`
271
+ 2. **Authentication errors**: Verify your JWT configuration
272
+ 3. **Import errors**: Install required dependencies
273
+ 4. **CORS issues**: Ensure `allow_cors=True` is set
274
+
275
+ ### Getting Help
276
+
277
+ - Check the main README.md for detailed API documentation
278
+ - Review the test files for more usage examples
279
+ - Open issues on GitHub for bugs or feature requests
280
+
281
+ ## Contributing
282
+
283
+ Feel free to contribute additional examples! Useful examples include:
284
+ - Database integration (SQLAlchemy, MongoDB)
285
+ - Real-time subscriptions
286
+ - File upload handling
287
+ - Integration with popular frameworks
288
+ - Deployment configurations