Skip to main content

The starlette GraphQL implement, which support query, mutate and subscription.

Project description

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.

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-0.1.3.tar.gz (6.7 kB view details)

Uploaded Source

File details

Details for the file starlette-graphql-0.1.3.tar.gz.

File metadata

  • Download URL: starlette-graphql-0.1.3.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.0 CPython/3.7.7 Darwin/19.5.0

File hashes

Hashes for starlette-graphql-0.1.3.tar.gz
Algorithm Hash digest
SHA256 028e0be68a6b7ac5826f34aa0a41b661d8eefe61e1e3435d59b8c4b0a17cc98f
MD5 01885887c8b52f9a003ce9d4c2e45a8c
BLAKE2b-256 95e89c981c4c990ea808e5e9472866837bcd54e5aa62438e762b4d485202fafd

See more details on using hashes here.

Supported by

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