Skip to content

Commit 696b590

Browse files
committed
Dump
1 parent 2af1926 commit 696b590

File tree

11 files changed

+384
-255
lines changed

11 files changed

+384
-255
lines changed

graphene_django/converter.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
)
2424
from graphene.types.json import JSONString
2525
from graphene.utils.str_converters import to_camel_case, to_const
26-
from graphql import assert_valid_name
26+
from graphql import assert_valid_name, GraphQLError
2727

2828
from .settings import graphene_settings
2929
from .compat import ArrayField, HStoreField, JSONField, RangeField
@@ -34,7 +34,7 @@ def convert_choice_name(name):
3434
name = to_const(force_str(name))
3535
try:
3636
assert_valid_name(name)
37-
except AssertionError:
37+
except GraphQLError:
3838
name = "A_%s" % name
3939
return name
4040

@@ -64,7 +64,7 @@ def convert_choices_to_named_enum_with_descriptions(name, choices):
6464
class EnumWithDescriptionsType(object):
6565
@property
6666
def description(self):
67-
return named_choices_descriptions[self.name]
67+
return str(named_choices_descriptions[self.name])
6868

6969
return Enum(name, list(named_choices), type=EnumWithDescriptionsType)
7070

@@ -276,3 +276,12 @@ def convert_postgres_range_to_string(field, registry=None):
276276
if not isinstance(inner_type, (List, NonNull)):
277277
inner_type = type(inner_type)
278278
return List(inner_type, description=field.help_text, required=not field.null)
279+
280+
281+
from django.utils.functional import Promise
282+
from graphql.pyutils import register_description
283+
284+
285+
# Register Django lazy()-wrapped values as GraphQL description/help_text.
286+
# This is needed for using lazy translations, see https://github.com/graphql-python/graphql-core-next/issues/58.
287+
register_description(Promise)

graphene_django/debug/middleware.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def get_debug_promise(self):
1717
if not self.debug_promise:
1818
self.debug_promise = Promise.all(self.promises)
1919
self.promises = []
20-
return self.debug_promise.then(self.on_resolve_all_promises)
20+
return self.debug_promise.then(self.on_resolve_all_promises).get()
2121

2222
def on_resolve_all_promises(self, values):
2323
if self.promises:

graphene_django/fields.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from functools import partial
22

33
from django.db.models.query import QuerySet
4+
from graphene.relay.connection import page_info_adapter, connection_adapter
45

56
from graphql_relay.connection.arrayconnection import connection_from_array_slice
67
from promise import Promise
78

89
from graphene import NonNull
9-
from graphene.relay import ConnectionField, PageInfo
10+
from graphene.relay import ConnectionField
1011
from graphene.types import Field, List
1112

1213
from .settings import graphene_settings
@@ -127,11 +128,11 @@ def resolve_connection(cls, connection, args, iterable):
127128
iterable,
128129
args,
129130
slice_start=0,
130-
connection_type=connection,
131131
array_length=_len,
132132
array_slice_length=_len,
133+
connection_type=partial(connection_adapter, connection),
133134
edge_type=connection.Edge,
134-
page_info_type=PageInfo,
135+
page_info_type=page_info_adapter,
135136
)
136137
connection.iterable = iterable
137138
connection.length = _len

graphene_django/filter/tests/test_fields.py

+71-35
Original file line numberDiff line numberDiff line change
@@ -809,38 +809,56 @@ class Query(ObjectType):
809809

810810
assert str(schema) == dedent(
811811
"""\
812-
schema {
813-
query: Query
812+
type Query {
813+
pets(before: String = null, after: String = null, first: Int = null, last: Int = null, age: Int = null): PetTypeConnection
814814
}
815815
816-
interface Node {
817-
id: ID!
816+
type PetTypeConnection {
817+
\"""Pagination data for this connection.\"""
818+
pageInfo: PageInfo!
819+
820+
\"""Contains the nodes in this connection.\"""
821+
edges: [PetTypeEdge]!
818822
}
819823
824+
\"""
825+
The Relay compliant `PageInfo` type, containing data necessary to paginate this connection.
826+
\"""
820827
type PageInfo {
828+
\"""When paginating forwards, are there more items?\"""
821829
hasNextPage: Boolean!
830+
831+
\"""When paginating backwards, are there more items?\"""
822832
hasPreviousPage: Boolean!
833+
834+
\"""When paginating backwards, the cursor to continue.\"""
823835
startCursor: String
836+
837+
\"""When paginating forwards, the cursor to continue.\"""
824838
endCursor: String
825839
}
826-
827-
type PetType implements Node {
828-
age: Int!
829-
id: ID!
830-
}
831-
832-
type PetTypeConnection {
833-
pageInfo: PageInfo!
834-
edges: [PetTypeEdge]!
835-
}
836-
840+
841+
\"""A Relay edge containing a `PetType` and its cursor.\"""
837842
type PetTypeEdge {
843+
\"""The item at the end of the edge\"""
838844
node: PetType
845+
846+
\"""A cursor for use in pagination\"""
839847
cursor: String!
840848
}
841-
842-
type Query {
843-
pets(before: String, after: String, first: Int, last: Int, age: Int): PetTypeConnection
849+
850+
type PetType implements Node {
851+
\"""\"""
852+
age: Int!
853+
854+
\"""The ID of the object\"""
855+
id: ID!
856+
}
857+
858+
\"""An object with an ID\"""
859+
interface Node {
860+
\"""The ID of the object\"""
861+
id: ID!
844862
}
845863
"""
846864
)
@@ -861,40 +879,58 @@ class Query(ObjectType):
861879

862880
assert str(schema) == dedent(
863881
"""\
864-
schema {
865-
query: Query
882+
type Query {
883+
pets(before: String = null, after: String = null, first: Int = null, last: Int = null, age: Int = null, age_Isnull: Boolean = null, age_Lt: Int = null): PetTypeConnection
866884
}
867885
868-
interface Node {
869-
id: ID!
886+
type PetTypeConnection {
887+
\"""Pagination data for this connection.\"""
888+
pageInfo: PageInfo!
889+
890+
\"""Contains the nodes in this connection.\"""
891+
edges: [PetTypeEdge]!
870892
}
871893
894+
\"""
895+
The Relay compliant `PageInfo` type, containing data necessary to paginate this connection.
896+
\"""
872897
type PageInfo {
898+
\"""When paginating forwards, are there more items?\"""
873899
hasNextPage: Boolean!
900+
901+
\"""When paginating backwards, are there more items?\"""
874902
hasPreviousPage: Boolean!
875-
startCursor: String
876-
endCursor: String
877-
}
878903
879-
type PetType implements Node {
880-
age: Int!
881-
id: ID!
882-
}
904+
\"""When paginating backwards, the cursor to continue.\"""
905+
startCursor: String
883906
884-
type PetTypeConnection {
885-
pageInfo: PageInfo!
886-
edges: [PetTypeEdge]!
907+
\"""When paginating forwards, the cursor to continue.\"""
908+
endCursor: String
887909
}
888910
911+
\"""A Relay edge containing a `PetType` and its cursor.\"""
889912
type PetTypeEdge {
913+
\"""The item at the end of the edge\"""
890914
node: PetType
915+
916+
\"""A cursor for use in pagination\"""
891917
cursor: String!
892918
}
893919
894-
type Query {
895-
pets(before: String, after: String, first: Int, last: Int, age: Int, age_Isnull: Boolean, age_Lt: Int): PetTypeConnection
920+
type PetType implements Node {
921+
\"""\"""
922+
age: Int!
923+
924+
\"""The ID of the object\"""
925+
id: ID!
896926
}
897-
"""
927+
928+
\"""An object with an ID\"""
929+
interface Node {
930+
\"""The ID of the object\"""
931+
id: ID!
932+
}
933+
"""
898934
)
899935

900936

graphene_django/management/commands/graphql_schema.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def save_json_file(self, out, schema_dict, indent):
5555

5656
def save_graphql_file(self, out, schema):
5757
with open(out, "w") as outfile:
58-
outfile.write(print_schema(schema))
58+
outfile.write(print_schema(schema.graphql_schema))
5959

6060
def get_schema(self, schema, out, indent):
6161
schema_dict = {"data": schema.introspect()}

graphene_django/rest_framework/tests/test_mutation.py

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def mock_info():
1818
None,
1919
None,
2020
None,
21+
path=None,
2122
schema=None,
2223
fragments=None,
2324
root_value=None,

graphene_django/tests/test_command.py

-4
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ class Query(ObjectType):
5151
schema_output = handle.write.call_args[0][0]
5252
assert schema_output == dedent(
5353
"""\
54-
schema {
55-
query: Query
56-
}
57-
5854
type Query {
5955
hi: String
6056
}

graphene_django/tests/test_query.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -620,9 +620,9 @@ class Query(graphene.ObjectType):
620620

621621
result = schema.execute(query)
622622
assert len(result.errors) == 1
623-
assert str(result.errors[0]) == (
623+
assert str(result.errors[0]).startswith(
624624
"You must provide a `first` or `last` value to properly "
625-
"paginate the `allReporters` connection."
625+
"paginate the `allReporters` connection.\n"
626626
)
627627
assert result.data == expected
628628

@@ -661,9 +661,9 @@ class Query(graphene.ObjectType):
661661

662662
result = schema.execute(query)
663663
assert len(result.errors) == 1
664-
assert str(result.errors[0]) == (
664+
assert str(result.errors[0]).startswith(
665665
"Requesting 101 records on the `allReporters` connection "
666-
"exceeds the `first` limit of 100 records."
666+
"exceeds the `first` limit of 100 records.\n"
667667
)
668668
assert result.data == expected
669669

@@ -704,9 +704,9 @@ class Query(graphene.ObjectType):
704704

705705
result = schema.execute(query)
706706
assert len(result.errors) == 1
707-
assert str(result.errors[0]) == (
707+
assert str(result.errors[0]).startswith(
708708
"Requesting 101 records on the `allReporters` connection "
709-
"exceeds the `last` limit of 100 records."
709+
"exceeds the `last` limit of 100 records.\n"
710710
)
711711
assert result.data == expected
712712

@@ -725,7 +725,7 @@ class Query(graphene.ObjectType):
725725
all_reporters = DjangoConnectionField(ReporterType)
726726

727727
def resolve_all_reporters(self, info, **args):
728-
return Promise.resolve([Reporter(id=1)])
728+
return Promise.resolve([Reporter(id=1)]).get()
729729

730730
schema = graphene.Schema(query=Query)
731731
query = """
@@ -854,7 +854,7 @@ class Meta:
854854
articles = DjangoConnectionField(ArticleType)
855855

856856
def resolve_articles(self, info, **args):
857-
return article_loader.load(self.id)
857+
return article_loader.load(self.id).get()
858858

859859
class Query(graphene.ObjectType):
860860
all_reporters = DjangoConnectionField(ReporterType)
@@ -1117,6 +1117,7 @@ def resolve_films(root, info, **kwargs):
11171117
}
11181118
"""
11191119
schema = graphene.Schema(query=Query)
1120+
11201121
with django_assert_num_queries(3) as captured:
11211122
result = schema.execute(query)
11221123
assert not result.errors

0 commit comments

Comments
 (0)