Skip to content

Commit

Permalink
style(Lint): Format using black
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinand-c committed Dec 29, 2023
1 parent 26d5d85 commit 859ce3b
Show file tree
Hide file tree
Showing 17 changed files with 282 additions and 156 deletions.
10 changes: 5 additions & 5 deletions graphene_federation/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def _get_query(schema: Schema, query_cls: Optional[ObjectType] = None) -> Object


def build_schema(
query: Optional[ObjectType] = None,
mutation: Optional[ObjectType] = None,
enable_federation_2=False,
schema: Optional[Schema] = None,
**kwargs
query: Optional[ObjectType] = None,
mutation: Optional[ObjectType] = None,
enable_federation_2=False,
schema: Optional[Schema] = None,
**kwargs
) -> Schema:
schema = schema or Schema(query=query, mutation=mutation, **kwargs)
schema.auto_camelcase = kwargs.get("auto_camelcase", True)
Expand Down
18 changes: 5 additions & 13 deletions graphene_federation/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,14 @@ def get_sdl(schema: Schema) -> str:
and hasattr(entity, "_resolvable")
and not entity._resolvable
):
type_annotation = (
(
" ".join(
[
f'@key(fields: "{get_field_name(key)}"'
for key in entity._keys
]
)
)
+ f", resolvable: {str(entity._resolvable).lower()})"
)
else:
type_annotation = (
" ".join(
[f'@key(fields: "{get_field_name(key)}")' for key in entity._keys]
[f'@key(fields: "{get_field_name(key)}"' for key in entity._keys]
)
) + f", resolvable: {str(entity._resolvable).lower()})"
else:
type_annotation = " ".join(
[f'@key(fields: "{get_field_name(key)}")' for key in entity._keys]
)
repl_str = rf"\1 {type_annotation} "
pattern = re.compile(type_def_re)
Expand Down
60 changes: 40 additions & 20 deletions graphene_federation/tests/test_annotation_corner_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class ChatQuery(ObjectType):
message = Field(ChatMessage, id=ID(required=True))

chat_schema = build_schema(query=ChatQuery, enable_federation_2=True)
expected_result = (dedent("""
expected_result = dedent(
"""
schema {
query: ChatQuery
}
Expand Down Expand Up @@ -63,7 +64,8 @@ class ChatQuery(ObjectType):
type _Service {
sdl: String
}
"""))
"""
)
assert clean_schema(chat_schema) == clean_schema(expected_result)
# Check the federation service schema definition language
query = """
Expand All @@ -75,7 +77,8 @@ class ChatQuery(ObjectType):
"""
result = graphql_sync(chat_schema.graphql_schema, query)
assert not result.errors
expected_result = dedent("""
expected_result = dedent(
"""
extend schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@extends", "@external", "@key"])
type ChatQuery {
Expand All @@ -92,7 +95,8 @@ class ChatQuery(ObjectType):
iD: ID
ID: ID
}
""")
"""
)
assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result)


Expand All @@ -112,7 +116,8 @@ class Query(ObjectType):
camel = Field(Camel)

schema = build_schema(query=Query, enable_federation_2=True)
expected_result = dedent("""
expected_result = dedent(
"""
type Query {
camel: Camel
_entities(representations: [_Any!]!): [_Entity]!
Expand All @@ -133,7 +138,8 @@ class Query(ObjectType):
type _Service {
sdl: String
}
""")
"""
)
assert clean_schema(schema) == clean_schema(expected_result)
# Check the federation service schema definition language
query = """
Expand All @@ -145,7 +151,8 @@ class Query(ObjectType):
"""
result = graphql_sync(schema.graphql_schema, query)
assert not result.errors
expected_result = dedent("""
expected_result = dedent(
"""
extend schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@extends", "@external", "@key", "@requires"])
type Query {
camel: Camel
Expand All @@ -156,7 +163,8 @@ class Query(ObjectType):
aSnake: String
aCamel: String
}
""")
"""
)
assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result)


Expand All @@ -176,7 +184,8 @@ class Query(ObjectType):
camel = Field(Camel)

schema = build_schema(query=Query, auto_camelcase=False, enable_federation_2=True)
expected_result = dedent("""
expected_result = dedent(
"""
type Query {
camel: Camel
_entities(representations: [_Any!]!): [_Entity]!
Expand All @@ -197,7 +206,8 @@ class Query(ObjectType):
type _Service {
sdl: String
}
""")
"""
)
assert clean_schema(schema) == clean_schema(expected_result)
# Check the federation service schema definition language
query = """
Expand All @@ -209,7 +219,8 @@ class Query(ObjectType):
"""
result = graphql_sync(schema.graphql_schema, query)
assert not result.errors
expected_result = dedent("""
expected_result = dedent(
"""
extend schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@extends", "@external", "@key", "@requires"])
type Query {
camel: Camel
Expand All @@ -221,7 +232,8 @@ class Query(ObjectType):
a_snake: String
aCamel: String
}
""")
"""
)
assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result)


Expand All @@ -244,7 +256,8 @@ class Query(ObjectType):
a = Field(A)

schema = build_schema(query=Query, enable_federation_2=True)
expected_result = dedent("""
expected_result = dedent(
"""
type Query {
a: A
_entities(representations: [_Any!]!): [_Entity]!
Expand All @@ -267,7 +280,8 @@ class Query(ObjectType):
type _Service {
sdl: String
}
""")
"""
)
assert clean_schema(schema) == clean_schema(expected_result)
# Check the federation service schema definition language
query = """
Expand All @@ -279,7 +293,8 @@ class Query(ObjectType):
"""
result = graphql_sync(schema.graphql_schema, query)
assert not result.errors
expected_result = dedent("""
expected_result = dedent(
"""
extend schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@extends", "@external", "@key"])
type Query {
a: A
Expand All @@ -293,7 +308,8 @@ class Query(ObjectType):
type B @key(fields: "id") {
id: ID
}
""")
"""
)
assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result)


Expand All @@ -317,7 +333,8 @@ class Query(ObjectType):
a = Field(A)

schema = build_schema(query=Query, enable_federation_2=True)
expected_result = dedent("""
expected_result = dedent(
"""
type Query {
a: Banana
_entities(representations: [_Any!]!): [_Entity]!
Expand All @@ -340,7 +357,8 @@ class Query(ObjectType):
type _Service {
sdl: String
}
""")
"""
)
assert clean_schema(schema) == clean_schema(expected_result)
# Check the federation service schema definition language
query = """
Expand All @@ -352,7 +370,8 @@ class Query(ObjectType):
"""
result = graphql_sync(schema.graphql_schema, query)
assert not result.errors
expected_result = dedent("""
expected_result = dedent(
"""
extend schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@extends", "@external", "@key"])
type Query {
a: Banana
Expand All @@ -366,6 +385,7 @@ class Query(ObjectType):
type Potato @key(fields: "id") {
id: ID
}
""")
"""
)
# assert compare_schema(result.data["_service"]["sdl"].strip(), expected_result)
assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result)
Loading

0 comments on commit 859ce3b

Please sign in to comment.