diff --git a/README.md b/README.md index 27fd62f0..e005d337 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,9 @@ Here is one example for get you started: ```python class Query(graphene.ObjectType): - hello = graphene.StringField(description='A typical hello world') - ping = graphene.StringField(description='Ping someone', - to=graphene.Argument(graphene.String)) + hello = graphene.String(description='A typical hello world') + ping = graphene.String(description='Ping someone', + to=graphene.String()) def resolve_hello(self, args, info): return 'World' diff --git a/README.rst b/README.rst index 45706105..c21f2335 100644 --- a/README.rst +++ b/README.rst @@ -35,9 +35,9 @@ Here is one example for get you started: .. code:: python class Query(graphene.ObjectType): - hello = graphene.StringField(description='A typical hello world') - ping = graphene.StringField(description='Ping someone', - to=graphene.Argument(graphene.String)) + hello = graphene.String(description='A typical hello world') + ping = graphene.String(description='Ping someone', + to=graphene.String()) def resolve_hello(self, args, info): return 'World' diff --git a/examples/starwars/schema.py b/examples/starwars/schema.py index 6107a62d..b4f05fee 100644 --- a/examples/starwars/schema.py +++ b/examples/starwars/schema.py @@ -12,10 +12,10 @@ Episode = graphene.Enum('Episode', dict( class Character(graphene.Interface): - id = graphene.IDField() - name = graphene.StringField() - friends = graphene.ListField('Character') - appears_in = graphene.ListField(Episode) + id = graphene.ID() + name = graphene.String() + friends = graphene.List('Character') + appears_in = graphene.List(Episode) def resolve_friends(self, args, *_): # The character friends is a list of strings @@ -23,11 +23,11 @@ class Character(graphene.Interface): class Human(Character): - home_planet = graphene.StringField() + home_planet = graphene.String() class Droid(Character): - primary_function = graphene.StringField() + primary_function = graphene.String() class Query(graphene.ObjectType): @@ -35,10 +35,10 @@ class Query(graphene.ObjectType): episode=graphene.Argument(Episode) ) human = graphene.Field(Human, - id=graphene.Argument(graphene.String) + id=graphene.String() ) droid = graphene.Field(Droid, - id=graphene.Argument(graphene.String) + id=graphene.String() ) @resolve_only_args diff --git a/examples/starwars_django/schema.py b/examples/starwars_django/schema.py index 22e30e6a..7f267fed 100644 --- a/examples/starwars_django/schema.py +++ b/examples/starwars_django/schema.py @@ -40,8 +40,8 @@ class Faction(DjangoNode): class IntroduceShip(relay.ClientIDMutation): class Input: - ship_name = graphene.StringField(required=True) - faction_id = graphene.StringField(required=True) + ship_name = graphene.String(required=True) + faction_id = graphene.String(required=True) ship = graphene.Field(Ship) faction = graphene.Field(Faction) diff --git a/examples/starwars_relay/schema.py b/examples/starwars_relay/schema.py index b5d07cbc..da31a6f7 100644 --- a/examples/starwars_relay/schema.py +++ b/examples/starwars_relay/schema.py @@ -8,7 +8,7 @@ schema = graphene.Schema(name='Starwars Relay Schema') class Ship(relay.Node): '''A ship in the Star Wars saga''' - name = graphene.StringField(description='The name of the ship.') + name = graphene.String(description='The name of the ship.') @classmethod def get_node(cls, id): @@ -17,7 +17,7 @@ class Ship(relay.Node): class Faction(relay.Node): '''A faction in the Star Wars saga''' - name = graphene.StringField(description='The name of the faction.') + name = graphene.String(description='The name of the faction.') ships = relay.ConnectionField( Ship, description='The ships used by the faction.') @@ -34,8 +34,8 @@ class Faction(relay.Node): class IntroduceShip(relay.ClientIDMutation): class Input: - ship_name = graphene.StringField(required=True) - faction_id = graphene.StringField(required=True) + ship_name = graphene.String(required=True) + faction_id = graphene.String(required=True) ship = graphene.Field(Ship) faction = graphene.Field(Faction) diff --git a/graphene/__init__.py b/graphene/__init__.py index 7f58b988..61e73c6d 100644 --- a/graphene/__init__.py +++ b/graphene/__init__.py @@ -10,6 +10,7 @@ from graphene.core.schema import ( from graphene.core.types import ( ObjectType, + InputObjectType, Interface, Mutation, BaseType, @@ -55,6 +56,7 @@ __all__ = [ 'BaseType', 'LazyType', 'ObjectType', + 'InputObjectType', 'Interface', 'Mutation', 'Field', diff --git a/graphene/contrib/django/tests/test_types.py b/graphene/contrib/django/tests/test_types.py index f1af176d..2cfabfcb 100644 --- a/graphene/contrib/django/tests/test_types.py +++ b/graphene/contrib/django/tests/test_types.py @@ -2,7 +2,7 @@ from graphene import Schema from graphene.contrib.django.types import DjangoInterface, DjangoNode -from graphene.core.fields import Field, IntField +from graphene.core.fields import Field from graphene.core.types.scalars import Int from graphene.relay.fields import GlobalIDField from graphql.core.type import GraphQLInterfaceType, GraphQLObjectType @@ -23,7 +23,7 @@ class Character(DjangoInterface): class Human(DjangoNode): '''Human description''' - pub_date = IntField() + pub_date = Int() def get_node(self, id): pass diff --git a/graphene/contrib/django/tests/test_urls.py b/graphene/contrib/django/tests/test_urls.py index 2f0801ee..409471d4 100644 --- a/graphene/contrib/django/tests/test_urls.py +++ b/graphene/contrib/django/tests/test_urls.py @@ -18,7 +18,7 @@ class Character(DjangoNode): class Human(DjangoNode): - raises = graphene.StringField() + raises = graphene.String() class Meta: model = Article diff --git a/graphene/core/tests/test_mutations.py b/graphene/core/tests/test_mutations.py index d0efac76..c5a26daa 100644 --- a/graphene/core/tests/test_mutations.py +++ b/graphene/core/tests/test_mutations.py @@ -5,15 +5,15 @@ my_id = 0 class Query(graphene.ObjectType): - base = graphene.StringField() + base = graphene.String() class ChangeNumber(graphene.Mutation): '''Result mutation''' class Input: - to = graphene.IntField() + to = graphene.Int() - result = graphene.StringField() + result = graphene.String() @classmethod def mutate(cls, instance, args, info): diff --git a/graphene/core/tests/test_options.py b/graphene/core/tests/test_options.py index 009ae25d..3b656bd4 100644 --- a/graphene/core/tests/test_options.py +++ b/graphene/core/tests/test_options.py @@ -1,6 +1,6 @@ from py.test import raises -from graphene.core.fields import StringField +from graphene.core.fields import Field from graphene.core.options import Options @@ -20,7 +20,7 @@ def test_field_added_in_meta(): pass opt.contribute_to_class(ObjectType, '_meta') - f = StringField() + f = Field(None) f.attname = 'string_field' opt.add_field(f) assert f in opt.fields diff --git a/graphene/core/tests/test_query.py b/graphene/core/tests/test_query.py index 739bbdc6..d56b66f7 100644 --- a/graphene/core/tests/test_query.py +++ b/graphene/core/tests/test_query.py @@ -1,22 +1,22 @@ -from graphene.core.fields import Field, ListField, StringField +from graphene.core.fields import Field from graphene.core.schema import Schema -from graphene.core.types import Interface, ObjectType +from graphene.core.types import Interface, List, ObjectType, String from graphql.core import graphql from graphql.core.type import GraphQLSchema class Character(Interface): - name = StringField() + name = String() class Pet(ObjectType): - type = StringField(resolve=lambda *_: 'Dog') + type = String(resolver=lambda *_: 'Dog') class Human(Character): - friends = ListField(Character) + friends = List(Character) pet = Field(Pet) def resolve_name(self, *args): @@ -27,8 +27,6 @@ class Human(Character): def resolve_pet(self, *args): return Pet(object()) - # def resolve_friends(self, *args, **kwargs): - # return 'HEY YOU!' schema = Schema() diff --git a/graphene/core/tests/test_schema.py b/graphene/core/tests/test_schema.py index 03f7732a..3dcb0098 100644 --- a/graphene/core/tests/test_schema.py +++ b/graphene/core/tests/test_schema.py @@ -1,7 +1,7 @@ from py.test import raises -from graphene import Interface, ObjectType, Schema -from graphene.core.fields import Field, ListField, StringField +from graphene import Interface, List, ObjectType, Schema, String +from graphene.core.fields import Field from graphene.core.types.base import LazyType from graphql.core import graphql from tests.utils import assert_equal_lists @@ -10,15 +10,15 @@ schema = Schema(name='My own schema') class Character(Interface): - name = StringField() + name = String() class Pet(ObjectType): - type = StringField(resolve=lambda *_: 'Dog') + type = String(resolver=lambda *_: 'Dog') class Human(Character): - friends = ListField(Character) + friends = List(Character) pet = Field(Pet) def resolve_name(self, *args): @@ -109,7 +109,7 @@ def test_schema_register(): @schema.register class MyType(ObjectType): - type = StringField(resolve=lambda *_: 'Dog') + type = String(resolver=lambda *_: 'Dog') schema.query = MyType @@ -121,7 +121,7 @@ def test_schema_register_no_query_type(): @schema.register class MyType(ObjectType): - type = StringField(resolve=lambda *_: 'Dog') + type = String(resolver=lambda *_: 'Dog') with raises(Exception) as excinfo: schema.get_type('MyType') @@ -132,7 +132,7 @@ def test_schema_introspect(): schema = Schema(name='My own schema') class MyType(ObjectType): - type = StringField(resolve=lambda *_: 'Dog') + type = String(resolver=lambda *_: 'Dog') schema.query = MyType @@ -147,7 +147,7 @@ def test_lazytype(): @schema.register class MyType(ObjectType): - type = StringField(resolve=lambda *_: 'Dog') + type = String(resolver=lambda *_: 'Dog') schema.query = MyType diff --git a/graphene/core/types/tests/test_objecttype.py b/graphene/core/types/tests/test_objecttype.py index 125df407..06ac1626 100644 --- a/graphene/core/types/tests/test_objecttype.py +++ b/graphene/core/types/tests/test_objecttype.py @@ -1,8 +1,7 @@ from py.test import raises -from graphene.core.fields import IntField, StringField from graphene.core.schema import Schema -from graphene.core.types import Interface +from graphene.core.types import Int, Interface, String from graphql.core.execution.middlewares.utils import (resolver_has_tag, tag_resolver) from graphql.core.type import GraphQLInterfaceType, GraphQLObjectType @@ -10,7 +9,7 @@ from graphql.core.type import GraphQLInterfaceType, GraphQLObjectType class Character(Interface): '''Character description''' - name = StringField() + name = String() class Meta: type_name = 'core_Character' @@ -18,7 +17,7 @@ class Character(Interface): class Human(Character): '''Human description''' - friends = StringField() + friends = String() class Meta: type_name = 'core_Human' @@ -93,7 +92,7 @@ def test_object_type_container_too_many_args(): def test_field_clashes(): with raises(Exception) as excinfo: class Droid(Character): - name = IntField() + name = Int() assert 'clashes' in str(excinfo.value) @@ -104,7 +103,7 @@ def test_fields_inherited_should_be_different(): def test_field_mantain_resolver_tags(): class Droid(Character): - name = StringField() + name = String() def resolve_name(self, *args): return 'My Droid' diff --git a/graphene/relay/tests/test_mutations.py b/graphene/relay/tests/test_mutations.py index 313a2c1d..f8c840f2 100644 --- a/graphene/relay/tests/test_mutations.py +++ b/graphene/relay/tests/test_mutations.py @@ -1,20 +1,21 @@ import graphene from graphene import relay from graphene.core.schema import Schema +from graphql.core.type import GraphQLInputObjectField my_id = 0 class Query(graphene.ObjectType): - base = graphene.StringField() + base = graphene.String() class ChangeNumber(relay.ClientIDMutation): '''Result mutation''' class Input: - to = graphene.IntField() + to = graphene.Int() - result = graphene.StringField() + result = graphene.String() @classmethod def mutate_and_get_payload(cls, input, info): @@ -33,16 +34,15 @@ schema = Schema(query=Query, mutation=MyResultMutation) def test_mutation_arguments(): assert ChangeNumber.arguments assert list(ChangeNumber.arguments) == ['input'] - ChangeNumber.arguments['input'] - - # inner_type = _input.get_object_type(schema) - # client_mutation_id_field = inner_type._meta.fields_map[ - # 'client_mutation_id'] - # assert issubclass(inner_type, InputObjectType) - # assert isinstance(client_mutation_id_field, graphene.StringField) - # assert client_mutation_id_field.object_type == inner_type - # assert isinstance(client_mutation_id_field.internal_field( - # schema), GraphQLInputObjectField) + assert 'input' in ChangeNumber.arguments + inner_type = ChangeNumber.input_type + client_mutation_id_field = inner_type._meta.fields_map[ + 'client_mutation_id'] + assert issubclass(inner_type, graphene.InputObjectType) + assert isinstance(client_mutation_id_field.type, graphene.NonNull) + assert isinstance(client_mutation_id_field.type.of_type, graphene.String) + assert client_mutation_id_field.object_type == inner_type + assert isinstance(schema.T(client_mutation_id_field), GraphQLInputObjectField) def test_execute_mutations(): diff --git a/graphene/relay/tests/test_query.py b/graphene/relay/tests/test_query.py index 92e9d6f7..5a78d4ba 100644 --- a/graphene/relay/tests/test_query.py +++ b/graphene/relay/tests/test_query.py @@ -6,12 +6,12 @@ schema = graphene.Schema() class MyConnection(relay.Connection): - my_custom_field = graphene.StringField( - resolve=lambda instance, *_: 'Custom') + my_custom_field = graphene.String( + resolver=lambda instance, *_: 'Custom') class MyNode(relay.Node): - name = graphene.StringField() + name = graphene.String() @classmethod def get_node(cls, id): diff --git a/graphene/relay/tests/test_types.py b/graphene/relay/tests/test_types.py index 0c011b0e..19c055a9 100644 --- a/graphene/relay/tests/test_types.py +++ b/graphene/relay/tests/test_types.py @@ -7,7 +7,7 @@ schema = graphene.Schema() class OtherNode(relay.Node): - name = graphene.StringField() + name = graphene.String() @classmethod def get_node(cls, id): @@ -17,7 +17,7 @@ class OtherNode(relay.Node): def test_field_no_contributed_raises_error(): with raises(Exception) as excinfo: class Part(relay.Node): - x = graphene.StringField() + x = graphene.String() assert 'get_node' in str(excinfo.value) diff --git a/graphene/relay/types.py b/graphene/relay/types.py index b66e77fc..91bc9210 100644 --- a/graphene/relay/types.py +++ b/graphene/relay/types.py @@ -1,6 +1,5 @@ -from graphene.core.fields import BooleanField, Field, ListField, StringField -from graphene.core.types import (InputObjectType, Interface, Mutation, - ObjectType) +from graphene.core.types import (Boolean, Field, InputObjectType, Interface, + List, Mutation, ObjectType, String) from graphene.core.types.argument import ArgumentsGroup from graphene.core.types.base import LazyType from graphene.core.types.definitions import NonNull @@ -10,15 +9,15 @@ from graphql_relay.node.node import to_global_id class PageInfo(ObjectType): - has_next_page = BooleanField( + has_next_page = Boolean( required=True, description='When paginating forwards, are there more items?') - has_previous_page = BooleanField( + has_previous_page = Boolean( required=True, description='When paginating backwards, are there more items?') - start_cursor = StringField( + start_cursor = String( description='When paginating backwards, the cursor to continue.') - end_cursor = StringField( + end_cursor = String( description='When paginating forwards, the cursor to continue.') @@ -29,7 +28,7 @@ class Edge(ObjectType): node = Field(LazyType(lambda object_type: object_type.node_type), description='The item at the end of the edge') - cursor = StringField( + cursor = String( required=True, description='A cursor for use in pagination') @classmethod @@ -50,8 +49,8 @@ class Connection(ObjectType): page_info = Field(PageInfo, required=True, description='The Information to aid in pagination') - edges = ListField(LazyType(lambda object_type: object_type.edge_type), - description='Information to aid in pagination.') + edges = List(LazyType(lambda object_type: object_type.edge_type), + description='Information to aid in pagination.') _connection_data = None @@ -104,11 +103,11 @@ class Node(BaseNode, Interface): class MutationInputType(InputObjectType): - client_mutation_id = StringField(required=True) + client_mutation_id = String(required=True) class ClientIDMutation(Mutation): - client_mutation_id = StringField(required=True) + client_mutation_id = String(required=True) @classmethod def _prepare_class(cls):