Skip to main content

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

Example

For more abount subscription, please see Apollo Federation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

starlette-graphql-zifulu-0.0.1a3.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file starlette-graphql-zifulu-0.0.1a3.tar.gz.

File metadata

  • Download URL: starlette-graphql-zifulu-0.0.1a3.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

Hashes for starlette-graphql-zifulu-0.0.1a3.tar.gz
Algorithm Hash digest
SHA256 5382d9036e3b96f68c3abd480b0b91e15fc9a2a9ae6fd795ec2f876da22b04dc
MD5 9558734244a9598acc71031049105e18
BLAKE2b-256 31b3acc37f1633d2699bf615ba7d648d2cbbeca216d1f24ab004414656780588

See more details on using hashes here.

File details

Details for the file starlette_graphql_zifulu-0.0.1a3-py3-none-any.whl.

File metadata

  • Download URL: starlette_graphql_zifulu-0.0.1a3-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

Hashes for starlette_graphql_zifulu-0.0.1a3-py3-none-any.whl
Algorithm Hash digest
SHA256 2071306969bbaafbf513ecb5cc082b522b879ee5ed6497a6a44cedcc3128e452
MD5 ee2ecffa9d7320fd8e7aa7032cea5250
BLAKE2b-256 2dbfdbd1ca9afec100bb488c56c8b3d9592934fa3acc6da86f39297ddf506733

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page