Getting started¶
Defining a basic schema¶
from pyql import Schema
schema = Schema()
@schema.query.field('hello')
def resolve_hello(root, info, argument: str = 'stranger') -> str:
return 'Hello ' + argument
Or you can create your root Query object explicitly if you prefer doing so:
from pyql import Object, Schema
Query = Object('Query')
@Query.field('hello')
def resolve_hello(root, info, argument: str = 'stranger') -> str:
return 'Hello ' + argument
schema = Schema(query=Query)
Querying¶
result = schema.execute('{ hello }')
print(result.data['hello']) # "Hello stranger"
# Passing the argument as a variable
result = schema.execute("""
query hello($arg: String) {
hello (argument: $arg)
}
""", variables={'arg': 'World'})
print(result.data['hello']) # "Hello World"