GraphQL Server via Starlette
Project description
Starlette GraphQL
由starlette-graphql
包改编制成。
The starlette GraphQL implement, which support query, mutate and subscription. Based on python-gql.
Requirement
Python 3.7+
Installation
pip install starlette-graphql
Getting started
# app.py
from gql import query, gql
from stargql import GraphQL
type_defs = gql("""
type Query {
hello(name: String!): String!
}
""")
@query
async def hello(parent, info, name: str) -> str:
return name
app = GraphQL(type_defs=type_defs)
Use uvicorn to run app.
uvicorn app:app --reload
Upload File
import uvicorn
from gql import gql, mutate
from stargql import GraphQL
type_defs = gql("""
scalar Upload
type File {
filename: String!
}
type Query {
uploads: [File]
}
type Mutation {
singleUpload(file: Upload!): File!
multiUpload(files: [Upload!]!): [File!]!
}
""")
@mutate
def single_upload(parent, info, file):
return file
@mutate
def multi_upload(parent, info, files):
return files
app = GraphQL(type_defs=type_defs)
if __name__ == '__main__':
uvicorn.run(app, port=8080)
Subscription
For more about subscription, please see gql-subscriptions.
Apollo Federation
For more abount subscription, please see Apollo Federation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file starlette-graphql-zifulu-0.0.1a6.tar.gz
.
File metadata
- Download URL: starlette-graphql-zifulu-0.0.1a6.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eca32a5d82fe47631823763dff15c67d67cee548ef81e1ad5fd8ffc30d33e9c9 |
|
MD5 | bb4b5db66fa1ca3630ef90b971bb2939 |
|
BLAKE2b-256 | 80637937a1e0f644367bc104eb7e643ee9479fc0cf5360959f5e0a585e4fe9ab |
File details
Details for the file starlette_graphql_zifulu-0.0.1a6-py3-none-any.whl
.
File metadata
- Download URL: starlette_graphql_zifulu-0.0.1a6-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | adc1b47329ccb1a055b2e876df7de849e1b43091e409f054efedaf6d902bf5bd |
|
MD5 | 4b4e5f50d2e7cb56f939c4a8e0b4ab4f |
|
BLAKE2b-256 | 6b484a9859bd188406451ea33b9724b377538fdc46b5f132ef4652487c39ca7d |