Skip to content

Commit

Permalink
chore: small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Leonard committed Jun 20, 2022
1 parent 294eb25 commit aba1c77
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 48 deletions.
9 changes: 7 additions & 2 deletions graphene_federation/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import Any, Callable

from graphene import List, Union
from graphene import List, NonNull, Union

from graphene.types.schema import Schema
from graphene.types.schema import TypeMap
Expand Down Expand Up @@ -50,7 +50,12 @@ def get_entity_query(schema: Schema):
entity_type = get_entity_cls(entities_dict)

class EntityQuery:
entities = List(entity_type, name="_entities", representations=List(_Any))
entities = List(
entity_type,
name="_entities",
representations=NonNull(List(NonNull(_Any))),
required=True,
)

def resolve_entities(self, info, representations):
entities = []
Expand Down
2 changes: 1 addition & 1 deletion graphene_federation/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def resolve_sdl(parent, _):
return sdl_str

class ServiceQuery(ObjectType):
_service = Field(_Service, name="_service")
_service = Field(_Service, name="_service", required=True)

def resolve__service(parent, info):
return _Service()
Expand Down
27 changes: 11 additions & 16 deletions graphene_federation/tests/test_annotation_corner_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ class ChatQuery(ObjectType):

chat_schema = build_schema(query=ChatQuery)
assert (
str(chat_schema).strip().strip()
str(chat_schema).strip()
== """schema {
query: ChatQuery
}
type ChatQuery {
message(id: ID!): ChatMessage
_entities(representations: [_Any]): [_Entity]
_service: _Service
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
}
type ChatMessage {
Expand All @@ -57,7 +57,6 @@ class ChatQuery(ObjectType):
union _Entity = ChatUser
\"\"\"Anything\"\"\"
scalar _Any
type _Service {
Expand Down Expand Up @@ -117,8 +116,8 @@ class Query(ObjectType):
str(schema).strip()
== """type Query {
camel: Camel
_entities(representations: [_Any]): [_Entity]
_service: _Service
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
}
type Camel {
Expand All @@ -130,7 +129,6 @@ class Query(ObjectType):
union _Entity = Camel
\"\"\"Anything\"\"\"
scalar _Any
type _Service {
Expand Down Expand Up @@ -184,8 +182,8 @@ class Query(ObjectType):
str(schema).strip()
== """type Query {
camel: Camel
_entities(representations: [_Any]): [_Entity]
_service: _Service
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
}
type Camel {
Expand All @@ -197,7 +195,6 @@ class Query(ObjectType):
union _Entity = Camel
\"\"\"Anything\"\"\"
scalar _Any
type _Service {
Expand Down Expand Up @@ -254,8 +251,8 @@ class Query(ObjectType):
str(schema).strip()
== """type Query {
a: A
_entities(representations: [_Any]): [_Entity]
_service: _Service
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
}
type A {
Expand All @@ -269,7 +266,6 @@ class Query(ObjectType):
union _Entity = A | B
\"\"\"Anything\"\"\"
scalar _Any
type _Service {
Expand Down Expand Up @@ -329,8 +325,8 @@ class Query(ObjectType):
str(schema).strip()
== """type Query {
a: Banana
_entities(representations: [_Any]): [_Entity]
_service: _Service
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
}
type Banana {
Expand All @@ -344,7 +340,6 @@ class Query(ObjectType):
union _Entity = Banana | Potato
\"\"\"Anything\"\"\"
scalar _Any
type _Service {
Expand Down
5 changes: 2 additions & 3 deletions graphene_federation/tests/test_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class Query(ObjectType):
str(schema).strip()
== """type Query {
user: User
_entities(representations: [_Any]): [_Entity]
_service: _Service
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
}
type User {
Expand All @@ -34,7 +34,6 @@ class Query(ObjectType):
union _Entity = User
\"\"\"Anything\"\"\"
scalar _Any
type _Service {
Expand Down
15 changes: 6 additions & 9 deletions graphene_federation/tests/test_provides.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class Query(ObjectType):
str(schema).strip()
== """type Query {
inStockCount: InStockCount
_entities(representations: [_Any]): [_Entity]
_service: _Service
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
}
type InStockCount {
Expand All @@ -48,7 +48,6 @@ class Query(ObjectType):
union _Entity = Product
\"\"\"Anything\"\"\"
scalar _Any
type _Service {
Expand Down Expand Up @@ -110,8 +109,8 @@ class Query(ObjectType):
str(schema).strip()
== """type Query {
inStockCount: InStockCount
_entities(representations: [_Any]): [_Entity]
_service: _Service
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
}
type InStockCount {
Expand All @@ -127,7 +126,6 @@ class Query(ObjectType):
union _Entity = Product
\"\"\"Anything\"\"\"
scalar _Any
type _Service {
Expand Down Expand Up @@ -189,8 +187,8 @@ class Query(ObjectType):
str(schema).strip()
== """type Query {
inStockCount: InStockCount
_entities(representations: [_Any]): [_Entity]
_service: _Service
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
}
type InStockCount {
Expand All @@ -206,7 +204,6 @@ class Query(ObjectType):
union _Entity = Product
\"\"\"Anything\"\"\"
scalar _Any
type _Service {
Expand Down
15 changes: 6 additions & 9 deletions graphene_federation/tests/test_requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class Query(ObjectType):
str(schema).strip()
== """type Query {
product: Product
_entities(representations: [_Any]): [_Entity]
_service: _Service
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
}
type Product {
Expand All @@ -55,7 +55,6 @@ class Query(ObjectType):
union _Entity = Product
\"\"\"Anything\"\"\"
scalar _Any
type _Service {
Expand Down Expand Up @@ -109,8 +108,8 @@ class Query(ObjectType):
str(schema).strip()
== """type Query {
product: Product
_entities(representations: [_Any]): [_Entity]
_service: _Service
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
}
type Product {
Expand All @@ -122,7 +121,6 @@ class Query(ObjectType):
union _Entity = Product
\"\"\"Anything\"\"\"
scalar _Any
type _Service {
Expand Down Expand Up @@ -175,8 +173,8 @@ class Query(ObjectType):
str(schema).strip()
== """type Query {
acme: Acme
_entities(representations: [_Any]): [_Entity]
_service: _Service
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
}
type Acme {
Expand All @@ -187,7 +185,6 @@ class Query(ObjectType):
union _Entity = Acme
\"\"\"Anything\"\"\"
scalar _Any
type _Service {
Expand Down
10 changes: 4 additions & 6 deletions graphene_federation/tests/test_schema_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ def test_user_schema():
type UserQuery {
user(userId: ID!): User
_entities(representations: [_Any]): [_Entity]
_service: _Service
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
}
type User {
Expand All @@ -107,7 +107,6 @@ def test_user_schema():
union _Entity = User
\"\"\"Anything\"\"\"
scalar _Any
type _Service {
Expand Down Expand Up @@ -163,8 +162,8 @@ def test_chat_schema():
type ChatQuery {
message(id: ID!): ChatMessage
_entities(representations: [_Any]): [_Entity]
_service: _Service
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
}
type ChatMessage {
Expand All @@ -180,7 +179,6 @@ def test_chat_schema():
union _Entity = ChatUser
\"\"\"Anything\"\"\"
scalar _Any
type _Service {
Expand Down
1 change: 0 additions & 1 deletion graphene_federation/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


class _Any(Scalar):
"""Anything"""

__typename = String(required=True)

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ WORKDIR project
COPY requirements.txt ./
RUN pip install -r requirements.txt

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

0 comments on commit aba1c77

Please sign in to comment.