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
Close
Hashes for starlette-graphql-zifulu-0.0.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20d1959a1ef5c4ef707219a8e3616ffd55e2c50721859bc4665ad616f3c8b09e |
|
MD5 | 423790279dac59b05b7544331f19e926 |
|
BLAKE2b-256 | c74b0cf215a97748a695680b384f9ddaa8f6d6fd14e4285ebc43ca0e8a02604b |
Close
Hashes for starlette_graphql_zifulu-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fb19faf2b90156f2a10cd0bcdfab9fdc9798d060cd1cca39f8c598f2213346b |
|
MD5 | 7aea24c8e1eba254718c2fd577b63d8a |
|
BLAKE2b-256 | 3f7a483a5938bbbe9968b9fc2d5cd5a759f63c544906578f3fe19013cfae199f |