mirror of
https://github.com/graphql-python/graphene.git
synced 2024-12-01 22:14:02 +03:00
Example of using a Python class as a field
This commit is contained in:
parent
b1d79c4f07
commit
25c59833cc
30
examples/field_example.py
Normal file
30
examples/field_example.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import graphene
|
||||||
|
|
||||||
|
class Person(graphene.Interface):
|
||||||
|
name = graphene.String()
|
||||||
|
age = graphene.ID()
|
||||||
|
|
||||||
|
class Patron(Person):
|
||||||
|
id = graphene.ID()
|
||||||
|
|
||||||
|
class Query(graphene.ObjectType):
|
||||||
|
|
||||||
|
patron = graphene.Field(Patron)
|
||||||
|
|
||||||
|
def resolve_patron(self, args, info):
|
||||||
|
return Patron(id=1, name='Demo')
|
||||||
|
|
||||||
|
schema = graphene.Schema(query=Query)
|
||||||
|
query = '''
|
||||||
|
query something{
|
||||||
|
patron {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
result = schema.execute(query)
|
||||||
|
# Print the result
|
||||||
|
print result.data['patron']
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user