@@ -3,20 +3,10 @@ Please read [UPGRADE-v1.0.md](https://github.com/graphql-python/graphene/blob/ma
3
3
4
4
---
5
5
6
- # ![ Graphene Logo] ( http://graphene-python.org/favicon.png ) [ Graphene-Django] ( http://graphene-python.org ) [ ![ Build Status] ( https://travis-ci.org/graphql-python/graphene-django.svg?branch=master )] ( https://travis-ci.org/graphql-python/graphene-django ) [ ![ PyPI version] ( https://badge.fury.io/py/graphene-django.svg )] ( https://badge.fury.io/py/graphene-django ) [ ![ Coverage Status] ( https://coveralls.io/repos/graphql-python/graphene-django/badge.svg?branch=master&service=github )] ( https://coveralls.io/github/graphql-python/graphene-django?branch=master )
6
+ # ![ Graphene Logo] ( http://graphene-python.org/favicon.png ) Graphene-Django [ ![ Build Status] ( https://travis-ci.org/graphql-python/graphene-django.svg?branch=master )] ( https://travis-ci.org/graphql-python/graphene-django ) [ ![ PyPI version] ( https://badge.fury.io/py/graphene-django.svg )] ( https://badge.fury.io/py/graphene-django ) [ ![ Coverage Status] ( https://coveralls.io/repos/graphql-python/graphene-django/badge.svg?branch=master&service=github )] ( https://coveralls.io/github/graphql-python/graphene-django?branch=master )
7
7
8
8
9
- [ Graphene] ( http://graphene-python.org ) is a Python library for building GraphQL schemas/types fast and easily.
10
-
11
- - ** Easy to use:** Graphene helps you use GraphQL in Python without effort.
12
- - ** Relay:** Graphene has builtin support for Relay
13
- - ** Django:** Automatic * Django model* mapping to Graphene Types. Check a fully working [ Django] ( http://github.com/graphql-python/swapi-graphene ) implementation
14
-
15
- Graphene also supports * SQLAlchemy* !
16
-
17
- * What is supported in this Python version?* ** Everything** : Interfaces, ObjectTypes, Scalars, Unions and Relay (Nodes, Connections), in addition to queries, mutations and subscriptions.
18
-
19
- ** NEW** !: [ Try graphene online] ( http://graphene-python.org/playground/ )
9
+ A [ Django] ( https://www.djangoproject.com/ ) integration for [ Graphene] ( http://graphene-python.org/ ) .
20
10
21
11
## Installation
22
12
@@ -28,30 +18,50 @@ pip install "graphene-django>=1.0.dev"
28
18
29
19
## Examples
30
20
31
- Here is one example for get you started :
21
+ Here is a simple Django model :
32
22
33
23
``` python
34
24
from django.db import models
35
- from graphene_django import DjangoObjectType
36
25
37
26
class UserModel (models .Model ):
38
27
name = models.CharField(max_length = 100 )
39
28
last_name = models.CharField(max_length = 100 )
29
+ ```
30
+
31
+ To create a GraphQL schema for it you simply have to write the following:
32
+
33
+ ``` python
34
+ from graphene_django import DjangoObjectType
40
35
41
36
class User (DjangoObjectType ):
42
37
class Meta :
43
- # This type will transform all the UserModel fields
44
- # into Graphene fields automatically
45
38
model = UserModel
46
39
47
- # An extra field in the User Type
48
- full_name = graphene.String( )
40
+ class Query ( graphene . ObjectType ):
41
+ users = graphene.List(User )
49
42
50
- def resolve_full_name (self , args , context , info ):
51
- return " {} {} " .format(self .name, self .last_name)
43
+ @graphene.resolve_only_args
44
+ def resolve_users (self ):
45
+ return UserModel.objects.all()
46
+
47
+ schema = graphene.Schema(query = QueryRoot)
48
+ ```
49
+
50
+ Then you can simply query the schema:
51
+
52
+ ``` python
53
+ query = '''
54
+ query {
55
+ users {
56
+ name,
57
+ lastName
58
+ }
59
+ }
60
+ '''
61
+ result = schema.execute(query)
52
62
```
53
63
54
- If you want to learn even more, you can also check the following [ examples] ( examples/ ) :
64
+ To learn more check out the following [ examples] ( examples/ ) :
55
65
56
66
* ** Schema with Filtering** : [ Cookbook example] ( examples/cookbook )
57
67
* ** Relay Schema** : [ Starwars Relay example] ( examples/starwars )
0 commit comments