Skip to content

Commit 9b635c8

Browse files
committed
Merge pull request #21 from graphql-python/0.4.0
Ride to 0.4.0
2 parents 5c4db65 + 46cfe90 commit 9b635c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1700
-1073
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Graphene is a Python library for building GraphQL schemas/types fast and easily.
88
- **Django:** Automatic *Django model* mapping to Graphene Types. Check a fully working [Django](http://github.com/graphql-python/swapi-graphene) implementation
99

1010

11-
*But, what is supported in this Python version?* **Everything**: Interfaces, ObjectTypes, Mutations and Relay (Nodes, Connections and Mutations).
11+
*What is supported in this Python version?* **Everything**: Interfaces, ObjectTypes, Mutations, Scalars, Unions and Relay (Nodes, Connections and Mutations).
1212

1313

1414
## Installation
@@ -28,9 +28,9 @@ Here is one example for get you started:
2828

2929
```python
3030
class Query(graphene.ObjectType):
31-
hello = graphene.StringField(description='A typical hello world')
32-
ping = graphene.StringField(description='Ping someone',
33-
to=graphene.Argument(graphene.String))
31+
hello = graphene.String(description='A typical hello world')
32+
ping = graphene.String(description='Ping someone',
33+
to=graphene.String())
3434

3535
def resolve_hello(self, args, info):
3636
return 'World'

README.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ easily.
1212
`Django <http://github.com/graphql-python/swapi-graphene>`__
1313
implementation
1414

15-
*But, what is supported in this Python version?* **Everything**:
16-
Interfaces, ObjectTypes, Mutations and Relay (Nodes, Connections and
17-
Mutations).
15+
*What is supported in this Python version?* **Everything**: Interfaces,
16+
ObjectTypes, Mutations, Scalars, Unions and Relay (Nodes, Connections
17+
and Mutations).
1818

1919
Installation
2020
------------
@@ -35,9 +35,9 @@ Here is one example for get you started:
3535
.. code:: python
3636
3737
class Query(graphene.ObjectType):
38-
hello = graphene.StringField(description='A typical hello world')
39-
ping = graphene.StringField(description='Ping someone',
40-
to=graphene.Argument(graphene.String))
38+
hello = graphene.String(description='A typical hello world')
39+
ping = graphene.String(description='Ping someone',
40+
to=graphene.String())
4141
4242
def resolve_hello(self, args, info):
4343
return 'World'

bin/autolinter

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
22

3-
autoflake ./ -r --remove-unused-variables --remove-all-unused-imports --in-place
3+
autoflake ./ -r --remove-unused-variables --remove-all-unused-imports --in-place
4+
autopep8 ./ -r --in-place --experimental --aggressive --max-line-length 120
45
isort -rc .

examples/starwars/schema.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from graphql.core.type import GraphQLEnumValue
2+
13
import graphene
24
from graphene import resolve_only_args
3-
from graphql.core.type import GraphQLEnumValue
45

56
from .data import get_character, get_droid, get_hero, get_human
67

@@ -12,33 +13,33 @@
1213

1314

1415
class Character(graphene.Interface):
15-
id = graphene.IDField()
16-
name = graphene.StringField()
17-
friends = graphene.ListField('self')
18-
appears_in = graphene.ListField(Episode)
16+
id = graphene.ID()
17+
name = graphene.String()
18+
friends = graphene.List('Character')
19+
appears_in = graphene.List(Episode)
1920

2021
def resolve_friends(self, args, *_):
2122
# The character friends is a list of strings
2223
return [get_character(f) for f in self.friends]
2324

2425

2526
class Human(Character):
26-
home_planet = graphene.StringField()
27+
home_planet = graphene.String()
2728

2829

2930
class Droid(Character):
30-
primary_function = graphene.StringField()
31+
primary_function = graphene.String()
3132

3233

3334
class Query(graphene.ObjectType):
3435
hero = graphene.Field(Character,
3536
episode=graphene.Argument(Episode)
3637
)
3738
human = graphene.Field(Human,
38-
id=graphene.Argument(graphene.String)
39+
id=graphene.String()
3940
)
4041
droid = graphene.Field(Droid,
41-
id=graphene.Argument(graphene.String)
42+
id=graphene.String()
4243
)
4344

4445
@resolve_only_args

examples/starwars_django/schema.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313

1414
class Ship(DjangoNode):
15+
1516
class Meta:
1617
model = ShipModel
1718

@@ -21,11 +22,13 @@ def get_node(cls, id):
2122

2223

2324
class Character(DjangoObjectType):
25+
2426
class Meta:
2527
model = CharacterModel
2628

2729

2830
class Faction(DjangoNode):
31+
2932
class Meta:
3033
model = FactionModel
3134

@@ -35,9 +38,10 @@ def get_node(cls, id):
3538

3639

3740
class IntroduceShip(relay.ClientIDMutation):
41+
3842
class Input:
39-
ship_name = graphene.StringField(required=True)
40-
faction_id = graphene.StringField(required=True)
43+
ship_name = graphene.String(required=True)
44+
faction_id = graphene.String(required=True)
4145

4246
ship = graphene.Field(Ship)
4347
faction = graphene.Field(Faction)
@@ -48,7 +52,7 @@ def mutate_and_get_payload(cls, input, info):
4852
faction_id = input.get('faction_id')
4953
ship = create_ship(ship_name, faction_id)
5054
faction = get_faction(faction_id)
51-
return IntroduceShip(ship=ship, faction=faction)
55+
return IntroduceShip(ship=Ship(ship), faction=Faction(faction))
5256

5357

5458
class Query(graphene.ObjectType):

examples/starwars_relay/schema.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class Ship(relay.Node):
1010
'''A ship in the Star Wars saga'''
11-
name = graphene.StringField(description='The name of the ship.')
11+
name = graphene.String(description='The name of the ship.')
1212

1313
@classmethod
1414
def get_node(cls, id):
@@ -17,7 +17,7 @@ def get_node(cls, id):
1717

1818
class Faction(relay.Node):
1919
'''A faction in the Star Wars saga'''
20-
name = graphene.StringField(description='The name of the faction.')
20+
name = graphene.String(description='The name of the faction.')
2121
ships = relay.ConnectionField(
2222
Ship, description='The ships used by the faction.')
2323

@@ -34,8 +34,8 @@ def get_node(cls, id):
3434
class IntroduceShip(relay.ClientIDMutation):
3535

3636
class Input:
37-
ship_name = graphene.StringField(required=True)
38-
faction_id = graphene.StringField(required=True)
37+
ship_name = graphene.String(required=True)
38+
faction_id = graphene.String(required=True)
3939

4040
ship = graphene.Field(Ship)
4141
faction = graphene.Field(Faction)

graphene/__init__.py

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
from graphql.core.type import (
2-
GraphQLEnumType as Enum,
3-
GraphQLArgument as Argument,
4-
GraphQLString as String,
5-
GraphQLInt as Int,
6-
GraphQLID as ID
2+
GraphQLEnumType as Enum
73
)
84

95
from graphene import signals
@@ -14,12 +10,24 @@
1410

1511
from graphene.core.types import (
1612
ObjectType,
13+
InputObjectType,
1714
Interface,
1815
Mutation,
16+
BaseType,
17+
LazyType,
18+
Argument,
19+
Field,
20+
InputField,
21+
String,
22+
Int,
23+
Boolean,
24+
ID,
25+
Float,
26+
List,
27+
NonNull
1928
)
2029

2130
from graphene.core.fields import (
22-
Field,
2331
StringField,
2432
IntField,
2533
BooleanField,
@@ -29,11 +37,35 @@
2937
FloatField,
3038
)
3139

32-
from graphene.decorators import (
40+
from graphene.utils import (
3341
resolve_only_args
3442
)
3543

36-
__all__ = ['Enum', 'Argument', 'String', 'Int', 'ID', 'signals', 'Schema',
37-
'ObjectType', 'Interface', 'Mutation', 'Field', 'StringField',
38-
'IntField', 'BooleanField', 'IDField', 'ListField', 'NonNullField',
39-
'FloatField', 'resolve_only_args']
44+
__all__ = [
45+
'Enum',
46+
'Argument',
47+
'String',
48+
'Int',
49+
'Boolean',
50+
'Float',
51+
'ID',
52+
'List',
53+
'NonNull',
54+
'signals',
55+
'Schema',
56+
'BaseType',
57+
'LazyType',
58+
'ObjectType',
59+
'InputObjectType',
60+
'Interface',
61+
'Mutation',
62+
'Field',
63+
'InputField',
64+
'StringField',
65+
'IntField',
66+
'BooleanField',
67+
'IDField',
68+
'ListField',
69+
'NonNullField',
70+
'FloatField',
71+
'resolve_only_args']

graphene/contrib/django/converter.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
from django.db import models
22
from singledispatch import singledispatch
33

4-
from graphene.contrib.django.fields import (ConnectionOrListField,
5-
DjangoModelField)
6-
from graphene.core.fields import (BooleanField, FloatField, IDField, IntField,
7-
StringField)
4+
from ...core.types.scalars import ID, Boolean, Float, Int, String
5+
from .fields import ConnectionOrListField, DjangoModelField
86

97
try:
108
UUIDField = models.UUIDField
@@ -17,7 +15,8 @@ class UUIDField(object):
1715
@singledispatch
1816
def convert_django_field(field):
1917
raise Exception(
20-
"Don't know how to convert the Django field %s (%s)" % (field, field.__class__))
18+
"Don't know how to convert the Django field %s (%s)" %
19+
(field, field.__class__))
2120

2221

2322
@convert_django_field.register(models.DateField)
@@ -28,12 +27,12 @@ def convert_django_field(field):
2827
@convert_django_field.register(models.URLField)
2928
@convert_django_field.register(UUIDField)
3029
def convert_field_to_string(field):
31-
return StringField(description=field.help_text)
30+
return String(description=field.help_text)
3231

3332

3433
@convert_django_field.register(models.AutoField)
3534
def convert_field_to_id(field):
36-
return IDField(description=field.help_text)
35+
return ID(description=field.help_text)
3736

3837

3938
@convert_django_field.register(models.PositiveIntegerField)
@@ -42,23 +41,23 @@ def convert_field_to_id(field):
4241
@convert_django_field.register(models.BigIntegerField)
4342
@convert_django_field.register(models.IntegerField)
4443
def convert_field_to_int(field):
45-
return IntField(description=field.help_text)
44+
return Int(description=field.help_text)
4645

4746

4847
@convert_django_field.register(models.BooleanField)
4948
def convert_field_to_boolean(field):
50-
return BooleanField(description=field.help_text, required=True)
49+
return Boolean(description=field.help_text, required=True)
5150

5251

5352
@convert_django_field.register(models.NullBooleanField)
5453
def convert_field_to_nullboolean(field):
55-
return BooleanField(description=field.help_text)
54+
return Boolean(description=field.help_text)
5655

5756

5857
@convert_django_field.register(models.DecimalField)
5958
@convert_django_field.register(models.FloatField)
6059
def convert_field_to_float(field):
61-
return FloatField(description=field.help_text)
60+
return Float(description=field.help_text)
6261

6362

6463
@convert_django_field.register(models.ManyToManyField)

0 commit comments

Comments
 (0)