No project description provided
Project description
GraphQL helpers for Python.
Schema definition
PyQL provides a better / cleaner syntax for defining GraphQL schemas.
Using PyQL:
from pyql import Object, Schema
Query = Object('Query')
@Query.field('hello')
def resolve_hello(root, info, name: str = 'world') -> str:
return 'Hello {}'.format(name)
schema = Schema(query=Query)
compiled = schema.compile()
Equivalent using graphql-core:
from graphql import (
GraphQLObjectType, GraphQLField, GraphQLArgument, GraphQLString,
GraphQLSchema)
Query = GraphQLObjectType(
'Query',
fields=lambda: {
'hello': GraphQLField(
GraphQLString,
args={
'name': GraphQLArgument(
type=GraphQLString,
default_value='world',
),
},
resolver=lambda root, info, name = 'world': f'Hello, {name}'
),
}
)
schema = GraphQLSchema(query=Query)
Graphene looks slightly better, but it’s quite confusing, and makes use of unncessary objects:
import graphene
class Query(graphene.ObjectType):
hello = graphene.Field(
graphene.String,
name=graphene.Argument(graphene.String))
def resolve_hello(self, info, name='world'):
return f'Hello {name}'
schema = graphene.Schema(query=Query)
PyQL uses standard Python introspection when possible to figure out things, so eg. argument definitions can be picked up automatically from a resolver function, etc.
Limitations
While there are plans for field argument documentation to be picked up automatically from docstrings, it’s not currently implemented as reliably parsing docstrings is a non-trivial task.
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 PyQL-0.2.3.tar.gz
.
File metadata
- Download URL: PyQL-0.2.3.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcc45acfc52b179f2b8db42fa18ffb799778f190f08f68a225c5783e23055b49 |
|
MD5 | c03fb2e91e7228169fda39852a8b2501 |
|
BLAKE2b-256 | a4fa05e50edc01c8c42e4d7a38939876ee75f834e1b880b81f6b112e818854ec |
File details
Details for the file PyQL-0.2.3-py3-none-any.whl
.
File metadata
- Download URL: PyQL-0.2.3-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e2a2aebeb1dc3ba416c14945e3ef88833a21b8bdba859573df22489eb622112 |
|
MD5 | 4548f5f5ed417c37fd3acbb6d89029be |
|
BLAKE2b-256 | 35c4d020f7a3a542e2764363ca8fce2fe4bbf8607c3dc36c4b4494cdac1f50b1 |