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.
The whole API is currently work in progress and might change in the future.
Documentation coming as soon as things get a bit more well defined.
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.tar.gz
.
File metadata
- Download URL: PyQL-0.2.tar.gz
- Upload date:
- Size: 9.0 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.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0a6ff9c5121360a8524182b8b96a7a01cf8d4fc56e68c962760b3a1e36592a4 |
|
MD5 | bc7bac093a5a854c04a1162f9d82c00a |
|
BLAKE2b-256 | db1a5564b0de25b16b749a5bcc9d7277a5cca4cb10aed4170a5401de0089586b |
File details
Details for the file PyQL-0.2-py3-none-any.whl
.
File metadata
- Download URL: PyQL-0.2-py3-none-any.whl
- Upload date:
- Size: 10.0 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.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3328fd99b442af919c5b543666ca620d08d3d9fe2e6e58af7dc395235c822d4 |
|
MD5 | 9cae7500c857a713d1375628da418ae2 |
|
BLAKE2b-256 | f92672bbe51beb16c3efda058c39e0c0126abecae0b779da0f60c3ccc7d19f0c |