mirror of
https://github.com/graphql-python/graphene.git
synced 2025-04-07 10:54:15 +03:00
Improved quick start page
This commit is contained in:
parent
9a84945232
commit
8b1a3d0409
|
@ -33,9 +33,36 @@ pip install graphene
|
|||
|
||||
## Types
|
||||
|
||||
First we're going to define some GraphQL ObjectTypes that we'll use in our `Schema`:
|
||||
First we're going to define some GraphQL ObjectTypes for our `Schema`:
|
||||
|
||||
```
|
||||
|
||||
```python
|
||||
import graphene
|
||||
|
||||
```
|
||||
schema = graphene.Schema()
|
||||
|
||||
# This will be our root query
|
||||
class Query(graphene.ObjectType):
|
||||
username = graphene.StringField(description='The username')
|
||||
|
||||
def resolve_username(self, *args):
|
||||
return 'Hello World'
|
||||
|
||||
# Here we set the root query for our schema
|
||||
schema.query = Query
|
||||
```
|
||||
|
||||
Then, we can start querying our schema:
|
||||
|
||||
```python
|
||||
result = schema.execute('{ username }')
|
||||
|
||||
# result.data should be {'username': 'Hello World'}
|
||||
username = result.data['username']
|
||||
|
||||
print(username)
|
||||
```
|
||||
|
||||
Congrats! You got your first version of graphene working!
|
||||
|
||||
**This Quickstart page needs to be improved, meanwhile visit the [schema](https://github.com/graphql-python/django-graphene-example/blob/master/starwars/schema.py) of our Starwars Django example!**
|
||||
|
|
Loading…
Reference in New Issue
Block a user