Skip to content

Commit aba1c77

Browse files
author
Thomas Leonard
committed
chore: small improvements
1 parent 294eb25 commit aba1c77

File tree

9 files changed

+38
-48
lines changed

9 files changed

+38
-48
lines changed

graphene_federation/entity.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from typing import Any, Callable
44

5-
from graphene import List, Union
5+
from graphene import List, NonNull, Union
66

77
from graphene.types.schema import Schema
88
from graphene.types.schema import TypeMap
@@ -50,7 +50,12 @@ def get_entity_query(schema: Schema):
5050
entity_type = get_entity_cls(entities_dict)
5151

5252
class EntityQuery:
53-
entities = List(entity_type, name="_entities", representations=List(_Any))
53+
entities = List(
54+
entity_type,
55+
name="_entities",
56+
representations=NonNull(List(NonNull(_Any))),
57+
required=True,
58+
)
5459

5560
def resolve_entities(self, info, representations):
5661
entities = []

graphene_federation/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def resolve_sdl(parent, _):
127127
return sdl_str
128128

129129
class ServiceQuery(ObjectType):
130-
_service = Field(_Service, name="_service")
130+
_service = Field(_Service, name="_service", required=True)
131131

132132
def resolve__service(parent, info):
133133
return _Service()

graphene_federation/tests/test_annotation_corner_cases.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ class ChatQuery(ObjectType):
3131

3232
chat_schema = build_schema(query=ChatQuery)
3333
assert (
34-
str(chat_schema).strip().strip()
34+
str(chat_schema).strip()
3535
== """schema {
3636
query: ChatQuery
3737
}
3838
3939
type ChatQuery {
4040
message(id: ID!): ChatMessage
41-
_entities(representations: [_Any]): [_Entity]
42-
_service: _Service
41+
_entities(representations: [_Any!]!): [_Entity]!
42+
_service: _Service!
4343
}
4444
4545
type ChatMessage {
@@ -57,7 +57,6 @@ class ChatQuery(ObjectType):
5757
5858
union _Entity = ChatUser
5959
60-
\"\"\"Anything\"\"\"
6160
scalar _Any
6261
6362
type _Service {
@@ -117,8 +116,8 @@ class Query(ObjectType):
117116
str(schema).strip()
118117
== """type Query {
119118
camel: Camel
120-
_entities(representations: [_Any]): [_Entity]
121-
_service: _Service
119+
_entities(representations: [_Any!]!): [_Entity]!
120+
_service: _Service!
122121
}
123122
124123
type Camel {
@@ -130,7 +129,6 @@ class Query(ObjectType):
130129
131130
union _Entity = Camel
132131
133-
\"\"\"Anything\"\"\"
134132
scalar _Any
135133
136134
type _Service {
@@ -184,8 +182,8 @@ class Query(ObjectType):
184182
str(schema).strip()
185183
== """type Query {
186184
camel: Camel
187-
_entities(representations: [_Any]): [_Entity]
188-
_service: _Service
185+
_entities(representations: [_Any!]!): [_Entity]!
186+
_service: _Service!
189187
}
190188
191189
type Camel {
@@ -197,7 +195,6 @@ class Query(ObjectType):
197195
198196
union _Entity = Camel
199197
200-
\"\"\"Anything\"\"\"
201198
scalar _Any
202199
203200
type _Service {
@@ -254,8 +251,8 @@ class Query(ObjectType):
254251
str(schema).strip()
255252
== """type Query {
256253
a: A
257-
_entities(representations: [_Any]): [_Entity]
258-
_service: _Service
254+
_entities(representations: [_Any!]!): [_Entity]!
255+
_service: _Service!
259256
}
260257
261258
type A {
@@ -269,7 +266,6 @@ class Query(ObjectType):
269266
270267
union _Entity = A | B
271268
272-
\"\"\"Anything\"\"\"
273269
scalar _Any
274270
275271
type _Service {
@@ -329,8 +325,8 @@ class Query(ObjectType):
329325
str(schema).strip()
330326
== """type Query {
331327
a: Banana
332-
_entities(representations: [_Any]): [_Entity]
333-
_service: _Service
328+
_entities(representations: [_Any!]!): [_Entity]!
329+
_service: _Service!
334330
}
335331
336332
type Banana {
@@ -344,7 +340,6 @@ class Query(ObjectType):
344340
345341
union _Entity = Banana | Potato
346342
347-
\"\"\"Anything\"\"\"
348343
scalar _Any
349344
350345
type _Service {

graphene_federation/tests/test_key.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class Query(ObjectType):
2323
str(schema).strip()
2424
== """type Query {
2525
user: User
26-
_entities(representations: [_Any]): [_Entity]
27-
_service: _Service
26+
_entities(representations: [_Any!]!): [_Entity]!
27+
_service: _Service!
2828
}
2929
3030
type User {
@@ -34,7 +34,6 @@ class Query(ObjectType):
3434
3535
union _Entity = User
3636
37-
\"\"\"Anything\"\"\"
3837
scalar _Any
3938
4039
type _Service {

graphene_federation/tests/test_provides.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class Query(ObjectType):
3131
str(schema).strip()
3232
== """type Query {
3333
inStockCount: InStockCount
34-
_entities(representations: [_Any]): [_Entity]
35-
_service: _Service
34+
_entities(representations: [_Any!]!): [_Entity]!
35+
_service: _Service!
3636
}
3737
3838
type InStockCount {
@@ -48,7 +48,6 @@ class Query(ObjectType):
4848
4949
union _Entity = Product
5050
51-
\"\"\"Anything\"\"\"
5251
scalar _Any
5352
5453
type _Service {
@@ -110,8 +109,8 @@ class Query(ObjectType):
110109
str(schema).strip()
111110
== """type Query {
112111
inStockCount: InStockCount
113-
_entities(representations: [_Any]): [_Entity]
114-
_service: _Service
112+
_entities(representations: [_Any!]!): [_Entity]!
113+
_service: _Service!
115114
}
116115
117116
type InStockCount {
@@ -127,7 +126,6 @@ class Query(ObjectType):
127126
128127
union _Entity = Product
129128
130-
\"\"\"Anything\"\"\"
131129
scalar _Any
132130
133131
type _Service {
@@ -189,8 +187,8 @@ class Query(ObjectType):
189187
str(schema).strip()
190188
== """type Query {
191189
inStockCount: InStockCount
192-
_entities(representations: [_Any]): [_Entity]
193-
_service: _Service
190+
_entities(representations: [_Any!]!): [_Entity]!
191+
_service: _Service!
194192
}
195193
196194
type InStockCount {
@@ -206,7 +204,6 @@ class Query(ObjectType):
206204
207205
union _Entity = Product
208206
209-
\"\"\"Anything\"\"\"
210207
scalar _Any
211208
212209
type _Service {

graphene_federation/tests/test_requires.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class Query(ObjectType):
4242
str(schema).strip()
4343
== """type Query {
4444
product: Product
45-
_entities(representations: [_Any]): [_Entity]
46-
_service: _Service
45+
_entities(representations: [_Any!]!): [_Entity]!
46+
_service: _Service!
4747
}
4848
4949
type Product {
@@ -55,7 +55,6 @@ class Query(ObjectType):
5555
5656
union _Entity = Product
5757
58-
\"\"\"Anything\"\"\"
5958
scalar _Any
6059
6160
type _Service {
@@ -109,8 +108,8 @@ class Query(ObjectType):
109108
str(schema).strip()
110109
== """type Query {
111110
product: Product
112-
_entities(representations: [_Any]): [_Entity]
113-
_service: _Service
111+
_entities(representations: [_Any!]!): [_Entity]!
112+
_service: _Service!
114113
}
115114
116115
type Product {
@@ -122,7 +121,6 @@ class Query(ObjectType):
122121
123122
union _Entity = Product
124123
125-
\"\"\"Anything\"\"\"
126124
scalar _Any
127125
128126
type _Service {
@@ -175,8 +173,8 @@ class Query(ObjectType):
175173
str(schema).strip()
176174
== """type Query {
177175
acme: Acme
178-
_entities(representations: [_Any]): [_Entity]
179-
_service: _Service
176+
_entities(representations: [_Any!]!): [_Entity]!
177+
_service: _Service!
180178
}
181179
182180
type Acme {
@@ -187,7 +185,6 @@ class Query(ObjectType):
187185
188186
union _Entity = Acme
189187
190-
\"\"\"Anything\"\"\"
191188
scalar _Any
192189
193190
type _Service {

graphene_federation/tests/test_schema_annotation.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ def test_user_schema():
9595
9696
type UserQuery {
9797
user(userId: ID!): User
98-
_entities(representations: [_Any]): [_Entity]
99-
_service: _Service
98+
_entities(representations: [_Any!]!): [_Entity]!
99+
_service: _Service!
100100
}
101101
102102
type User {
@@ -107,7 +107,6 @@ def test_user_schema():
107107
108108
union _Entity = User
109109
110-
\"\"\"Anything\"\"\"
111110
scalar _Any
112111
113112
type _Service {
@@ -163,8 +162,8 @@ def test_chat_schema():
163162
164163
type ChatQuery {
165164
message(id: ID!): ChatMessage
166-
_entities(representations: [_Any]): [_Entity]
167-
_service: _Service
165+
_entities(representations: [_Any!]!): [_Entity]!
166+
_service: _Service!
168167
}
169168
170169
type ChatMessage {
@@ -180,7 +179,6 @@ def test_chat_schema():
180179
181180
union _Entity = ChatUser
182181
183-
\"\"\"Anything\"\"\"
184182
scalar _Any
185183
186184
type _Service {

graphene_federation/types.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
class _Any(Scalar):
5-
"""Anything"""
65

76
__typename = String(required=True)
87

integration_tests/tests/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ WORKDIR project
88
COPY requirements.txt ./
99
RUN pip install -r requirements.txt
1010

11-
CMD [ "pytest", "-s"]
11+
CMD [ "pytest", "-svv"]

0 commit comments

Comments
 (0)