跳转到主要内容

未提供项目描述

项目描述

Python的GraphQL助手。

CI状态:ci-status

模式定义

PyQL提供了一种更好/更简洁的语法来定义GraphQL模式。

使用PyQL

from pyql import Schema

schema = Schema()

@schema.query.field('hello')
def resolve_hello(root, info, name: str = 'world') -> str:
    return 'Hello {}'.format(name)

compiled = schema.compile()

与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看起来稍微好一些,但它相当复杂,并使用了不必要的对象

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在可能的情况下使用标准的Python内省来确定事物,因此例如,可以从解析函数自动获取参数定义等。

限制

虽然计划自动从文档字符串中获取字段参数文档,但尚未实现,因为可靠地解析文档字符串是一个非平凡的任务。

项目详情


下载文件

下载适合您平台文件的文件。如果您不确定要选择哪个,请了解更多关于安装软件包的信息。

源代码分发

PyQL-3.0.0.tar.gz (10.9 kB 查看散列值)

上传于 源码

构建版本

PyQL-3.0.0-py3-none-any.whl (12.4 kB 查看哈希值)

上传于 Python 3

由以下支持