Skip to content

Commit 4636f92

Browse files
committed
Merge branch 'master' into django-choices-grouping
# Conflicts: # graphene/contrib/django/tests/test_converter.py
2 parents 7d5d7ea + 6eb0008 commit 4636f92

File tree

8 files changed

+97
-8
lines changed

8 files changed

+97
-8
lines changed

docs/css/main.styl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,12 @@ $title
362362
.docs
363363
@extend $wrapper
364364

365+
.homepage-intro
366+
col(1/2)
367+
368+
.homepage-schema
369+
col(1/2)
370+
365371
.docs-aside
366372
col(1/4)
367373
margin-top 60px

docs/pages/docs/quickstart.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Let's build a basic GraphQL schema from scratch.
1010

1111
## Requirements
1212

13-
- Python (2.6.5+, 2.7, 3.2, 3.3, 3.4, 3.5, pypy)
14-
- Graphene (0.4+)
13+
- Python (2.7, 3.2, 3.3, 3.4, 3.5, pypy)
14+
- Graphene (0.10+)
1515

1616

1717
## Project setup

docs/pages/index.md

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,50 @@ path: /
33
---
44
<div class="starwars-example-wrapper"><a class="starwars-example" href="http://swapi.graphene-python.org/">Check our Django Starwars API example!</a></div>
55

6+
7+
<div>
8+
<div class="homepage-intro">
9+
610
## Meet Graphene
711

8-
Graphene is a Python library for building GraphQL schemas/types fast and easily.
12+
Graphene is a Python library for building *GraphQL* schemas/types fast and easily.
13+
14+
15+
* **Easy to use**: Graphene helps you use *GraphQL* in Python easily.
16+
* Graphene has **builtin support for Relay**.
17+
* Support for **Django**, **SQLAlchemy** and **GAE**: mapping the models automatically to *GraphQL* types.
18+
19+
</div>
20+
21+
<div class="homepage-schema">
22+
23+
```python
24+
import graphene
25+
26+
class Query(graphene.ObjectType):
27+
hello = graphene.String()
28+
29+
def resolve_hello(self, args, info):
30+
return 'world'
31+
32+
schema = graphene.Schema(query=Query)
33+
```
34+
35+
36+
```python
37+
result = schema.execute('{ hello }')
38+
```
39+
40+
</div>
41+
</div>
42+
43+
<div>
44+
45+
#### What is GraphQL?
46+
*GraphQL* is a data query language and runtime designed to request and deliver data in a performant way.
947

10-
**But, what is GraphQL?** A GraphQL query is a string interpreted by a server that returns data in a specified format. We believe *GraphQL* is the next big thing after peanut butter and *REST*.
48+
Advantages of using *GraphQL*:
49+
* Only **one API endpoint**. One roundtrip for fetch everything you need.
50+
* No data overfetching or underfetching.
51+
* Autogenerated Graphical UI and docs based in your schema.
52+
<div>

graphene/contrib/django/converter.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.db import models
2+
from django.utils.encoding import force_text
23

34
from ...core.classtypes.enum import Enum
45
from ...core.types.custom_scalars import DateTime, JSONString
@@ -14,13 +15,14 @@
1415

1516
def convert_choices(choices):
1617
for value, name in choices:
17-
yield to_const(name), value
18+
yield to_const(force_text(name)), value
1819

1920

2021
def convert_django_field_with_choices(field):
2122
choices = getattr(field, 'choices', None)
22-
if choices:
23-
meta = field.model._meta
23+
model = getattr(field, 'model', None)
24+
if choices and model:
25+
meta = model._meta
2426
name = '{}_{}_{}'.format(meta.app_label, meta.object_name, field.name)
2527
return Enum(name.upper(), list(convert_choices(choices)), description=field.help_text)
2628
return convert_django_field(field)

graphene/contrib/django/tests/models.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
from __future__ import absolute_import
22

33
from django.db import models
4+
from django.utils.translation import ugettext_lazy as _
5+
6+
CHOICES = (
7+
(1, 'this'),
8+
(2, _('that'))
9+
)
410

511

612
class Pet(models.Model):
@@ -22,6 +28,7 @@ class Reporter(models.Model):
2228
last_name = models.CharField(max_length=30)
2329
email = models.EmailField()
2430
pets = models.ManyToManyField('self')
31+
a_choice = models.CharField(max_length=30, choices=CHOICES)
2532

2633
def __str__(self): # __unicode__ on Python 2
2734
return "%s %s" % (self.first_name, self.last_name)

graphene/contrib/django/tests/test_converter.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22
from django.db import models
3+
from django.utils.translation import ugettext_lazy as _
34
from py.test import raises
45

56
import graphene
@@ -125,7 +126,22 @@ def test_field_with_grouped_choices():
125126
)),
126127
))
127128

128-
class TranslatedModel(models.Model):
129+
class GroupedChoicesModel(models.Model):
130+
language = field
131+
132+
class Meta:
133+
app_label = 'test'
134+
135+
convert_django_field_with_choices(field)
136+
137+
138+
def test_field_with_choices_gettext():
139+
field = models.CharField(help_text='Language', choices=(
140+
('es', _('Spanish')),
141+
('en', _('English'))
142+
))
143+
144+
class TranslatedChoicesModel(models.Model):
129145
language = field
130146

131147
class Meta:

graphene/core/schema.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def schema(self):
7777
self,
7878
query=self.T(self.query),
7979
mutation=self.T(self.mutation),
80+
types=[self.T(_type) for _type in list(self._types_names.values())],
8081
subscription=self.T(self.subscription))
8182

8283
def register(self, object_type, force=False):

graphene/core/tests/test_schema.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,21 @@ class MyType(ObjectType):
132132
assert schema.get_type('MyType') == MyType
133133

134134

135+
def test_schema_register_interfaces():
136+
class Query(ObjectType):
137+
f = Field(Character)
138+
139+
def resolve_f(self, args, info):
140+
return Human()
141+
142+
schema = Schema(query=Query)
143+
144+
schema.register(Human)
145+
146+
result = schema.execute('{ f { name } }')
147+
assert not result.errors
148+
149+
135150
def test_schema_register_no_query_type():
136151
schema = Schema(name='My own schema')
137152

0 commit comments

Comments
 (0)