diff --git a/graphene_federation/main.py b/graphene_federation/main.py index 0144209..247381d 100644 --- a/graphene_federation/main.py +++ b/graphene_federation/main.py @@ -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) diff --git a/graphene_federation/service.py b/graphene_federation/service.py index 85c0286..ca3aab7 100644 --- a/graphene_federation/service.py +++ b/graphene_federation/service.py @@ -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) diff --git a/graphene_federation/tests/test_annotation_corner_cases.py b/graphene_federation/tests/test_annotation_corner_cases.py index 5265794..72aeea0 100644 --- a/graphene_federation/tests/test_annotation_corner_cases.py +++ b/graphene_federation/tests/test_annotation_corner_cases.py @@ -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 } @@ -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 = """ @@ -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 { @@ -92,7 +95,8 @@ class ChatQuery(ObjectType): iD: ID ID: ID } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) @@ -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]! @@ -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 = """ @@ -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 @@ -156,7 +163,8 @@ class Query(ObjectType): aSnake: String aCamel: String } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) @@ -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]! @@ -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 = """ @@ -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 @@ -221,7 +232,8 @@ class Query(ObjectType): a_snake: String aCamel: String } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) @@ -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]! @@ -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 = """ @@ -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 @@ -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) @@ -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]! @@ -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 = """ @@ -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 @@ -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) diff --git a/graphene_federation/tests/test_annotation_corner_cases_v1.py b/graphene_federation/tests/test_annotation_corner_cases_v1.py index a4e12de..82ca7fc 100644 --- a/graphene_federation/tests/test_annotation_corner_cases_v1.py +++ b/graphene_federation/tests/test_annotation_corner_cases_v1.py @@ -33,7 +33,8 @@ class ChatQuery(ObjectType): message = Field(ChatMessage, id=ID(required=True)) chat_schema = build_schema(query=ChatQuery) - expected_result = dedent(""" + expected_result = dedent( + """ schema { query: ChatQuery } @@ -64,7 +65,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 = """ @@ -76,7 +78,8 @@ class ChatQuery(ObjectType): """ result = graphql_sync(chat_schema.graphql_schema, query) assert not result.errors - expected_result = dedent(""" + expected_result = dedent( + """ type ChatQuery { message(id: ID!): ChatMessage } @@ -93,7 +96,8 @@ class ChatQuery(ObjectType): iD: ID ID: ID } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) @@ -113,7 +117,8 @@ class Query(ObjectType): camel = Field(Camel) schema = build_schema(query=Query) - expected_result = dedent(""" + expected_result = dedent( + """ type Query { camel: Camel _entities(representations: [_Any!]!): [_Entity]! @@ -134,7 +139,8 @@ class Query(ObjectType): type _Service { sdl: String } - """) + """ + ) assert clean_schema(schema) == clean_schema(expected_result) # Check the federation service schema definition language query = """ @@ -146,7 +152,8 @@ class Query(ObjectType): """ result = graphql_sync(schema.graphql_schema, query) assert not result.errors - expected_result = dedent(""" + expected_result = dedent( + """ type Query { camel: Camel } @@ -157,7 +164,8 @@ class Query(ObjectType): aSnake: String aCamel: String } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) @@ -177,7 +185,8 @@ class Query(ObjectType): camel = Field(Camel) schema = build_schema(query=Query, auto_camelcase=False) - expected_result = dedent(""" + expected_result = dedent( + """ type Query { camel: Camel _entities(representations: [_Any!]!): [_Entity]! @@ -198,7 +207,8 @@ class Query(ObjectType): type _Service { sdl: String } - """) + """ + ) assert clean_schema(schema) == clean_schema(expected_result) # Check the federation service schema definition language query = """ @@ -210,7 +220,8 @@ class Query(ObjectType): """ result = graphql_sync(schema.graphql_schema, query) assert not result.errors - expected_result = dedent(""" + expected_result = dedent( + """ type Query { camel: Camel } @@ -221,7 +232,8 @@ class Query(ObjectType): a_snake: String aCamel: String } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) @@ -244,7 +256,8 @@ class Query(ObjectType): a = Field(A) schema = build_schema(query=Query) - expected_result = dedent(""" + expected_result = dedent( + """ type Query { a: A _entities(representations: [_Any!]!): [_Entity]! @@ -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 = """ @@ -279,7 +293,8 @@ class Query(ObjectType): """ result = graphql_sync(schema.graphql_schema, query) assert not result.errors - expected_result = dedent(""" + expected_result = dedent( + """ type Query { a: A } @@ -292,7 +307,8 @@ class Query(ObjectType): type B @key(fields: "id") { id: ID } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) @@ -316,7 +332,8 @@ class Query(ObjectType): a = Field(A) schema = build_schema(query=Query) - expected_result = dedent(""" + expected_result = dedent( + """ type Query { a: Banana _entities(representations: [_Any!]!): [_Entity]! @@ -339,7 +356,8 @@ class Query(ObjectType): type _Service { sdl: String } - """) + """ + ) assert clean_schema(schema) == clean_schema(expected_result) # Check the federation service schema definition language query = """ @@ -351,7 +369,8 @@ class Query(ObjectType): """ result = graphql_sync(schema.graphql_schema, query) assert not result.errors - expected_result = dedent(""" + expected_result = dedent( + """ type Query { a: Banana } @@ -364,5 +383,6 @@ class Query(ObjectType): type Potato @key(fields: "id") { id: ID } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) diff --git a/graphene_federation/tests/test_custom_enum.py b/graphene_federation/tests/test_custom_enum.py index 70e1b42..933c559 100644 --- a/graphene_federation/tests/test_custom_enum.py +++ b/graphene_federation/tests/test_custom_enum.py @@ -34,7 +34,8 @@ class Query(ObjectType): } """ result = graphql_sync(schema.graphql_schema, query) - expected_result = dedent(""" + expected_result = dedent( + """ extend schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@inaccessible", "@shareable"]) type TestCustomEnum @shareable { testShareableScalar: Episode @shareable @@ -51,5 +52,6 @@ class Query(ObjectType): test: Episode test2: [TestCustomEnum]! } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) diff --git a/graphene_federation/tests/test_extend.py b/graphene_federation/tests/test_extend.py index 0055c8f..b34c884 100644 --- a/graphene_federation/tests/test_extend.py +++ b/graphene_federation/tests/test_extend.py @@ -71,7 +71,8 @@ class Query(ObjectType): user = Field(User) schema = build_schema(query=Query, enable_federation_2=True) - expected_result = dedent(""" + expected_result = dedent( + """ type Query { user: User _entities(representations: [_Any!]!): [_Entity]! @@ -94,7 +95,8 @@ class Query(ObjectType): type _Service { sdl: String } - """) + """ + ) assert clean_schema(schema) == clean_schema(expected_result) # Check the federation service schema definition language query = """ @@ -106,7 +108,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", "@shareable"]) type Query { user: User @@ -120,5 +123,6 @@ class Query(ObjectType): type Organization @shareable { id: ID } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) diff --git a/graphene_federation/tests/test_inaccessible.py b/graphene_federation/tests/test_inaccessible.py index 9f693d5..171c94b 100644 --- a/graphene_federation/tests/test_inaccessible.py +++ b/graphene_federation/tests/test_inaccessible.py @@ -47,7 +47,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: ["@inaccessible"]) type Position @inaccessible { x: Int! @@ -57,7 +58,8 @@ class Query(ObjectType): type Query { inStockCount: Int! } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) @@ -96,7 +98,8 @@ class Query(ObjectType): """ result = graphql_sync(schema.graphql_schema, query) assert not result.errors - expected_schema = dedent(""" + expected_schema = dedent( + """ extend schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@inaccessible"]) union SearchResult @inaccessible = Human | Droid | Starship @@ -118,5 +121,6 @@ class Query(ObjectType): type Query { inStockCount: Int! } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_schema) diff --git a/graphene_federation/tests/test_key.py b/graphene_federation/tests/test_key.py index 78dfea2..5f09c95 100644 --- a/graphene_federation/tests/test_key.py +++ b/graphene_federation/tests/test_key.py @@ -21,7 +21,8 @@ class Query(ObjectType): user = Field(User) schema = build_schema(query=Query, enable_federation_2=True) - expected_result = dedent(""" + expected_result = dedent( + """ type Query { user: User _entities(representations: [_Any!]!): [_Entity]! @@ -40,7 +41,8 @@ class Query(ObjectType): type _Service { sdl: String } - """) + """ + ) assert clean_schema(schema) == clean_schema(expected_result) # Check the federation service schema definition language query = """ @@ -52,7 +54,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: ["@key"]) type Query { user: User @@ -62,7 +65,8 @@ class Query(ObjectType): identifier: ID email: String } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) @@ -92,7 +96,8 @@ class Query(ObjectType): user = Field(User) schema = build_schema(query=Query, enable_federation_2=True) - expected_result = dedent(""" + expected_result = dedent( + """ type Query { user: User _entities(representations: [_Any!]!): [_Entity]! @@ -115,7 +120,8 @@ class Query(ObjectType): type _Service { sdl: String } - """) + """ + ) assert clean_schema(schema) == clean_schema(expected_result) # Check the federation service schema definition language query = """ @@ -127,7 +133,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: ["@key"]) type Query { user: User @@ -141,7 +148,8 @@ class Query(ObjectType): type Organization { registrationNumber: ID } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) @@ -163,7 +171,8 @@ class Query(ObjectType): user = Field(User) schema = build_schema(query=Query, enable_federation_2=True) - expected_result = dedent(""" + expected_result = dedent( + """ type Query { user: User _entities(representations: [_Any!]!): [_Entity]! @@ -192,7 +201,8 @@ class Query(ObjectType): type _Service { sdl: String } - """) + """ + ) assert clean_schema(schema) == clean_schema(expected_result) # Check the federation service schema definition language query = """ @@ -204,7 +214,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: ["@key"]) type Query { user: User @@ -224,7 +235,8 @@ class Query(ObjectType): id: ID name: String } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) diff --git a/graphene_federation/tests/test_key_v1.py b/graphene_federation/tests/test_key_v1.py index 22529aa..a25f81b 100644 --- a/graphene_federation/tests/test_key_v1.py +++ b/graphene_federation/tests/test_key_v1.py @@ -22,7 +22,8 @@ class Query(ObjectType): user = Field(User) schema = build_schema(query=Query) - expected_result = dedent(""" + expected_result = dedent( + """ type Query { user: User _entities(representations: [_Any!]!): [_Entity]! @@ -41,7 +42,8 @@ class Query(ObjectType): type _Service { sdl: String } - """) + """ + ) assert clean_schema(schema) == clean_schema(expected_result) # Check the federation service schema definition language query = """ @@ -53,7 +55,8 @@ class Query(ObjectType): """ result = graphql_sync(schema.graphql_schema, query) assert not result.errors - expected_result = dedent(""" + expected_result = dedent( + """ type Query { user: User } @@ -62,7 +65,8 @@ class Query(ObjectType): identifier: ID email: String } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) diff --git a/graphene_federation/tests/test_provides.py b/graphene_federation/tests/test_provides.py index c36a2b8..021f6c3 100644 --- a/graphene_federation/tests/test_provides.py +++ b/graphene_federation/tests/test_provides.py @@ -31,7 +31,8 @@ class Query(ObjectType): in_stock_count = Field(InStockCount) schema = build_schema(query=Query, enable_federation_2=True) - expected_result = dedent(""" + expected_result = dedent( + """ type Query { inStockCount: InStockCount _entities(representations: [_Any!]!): [_Entity]! @@ -56,7 +57,8 @@ class Query(ObjectType): type _Service { sdl: String } - """) + """ + ) assert clean_schema(schema) == clean_schema(expected_result) # Check the federation service schema definition language @@ -69,7 +71,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", "@provides"]) type Query { inStockCount: InStockCount @@ -85,7 +88,8 @@ class Query(ObjectType): name: String @external weight: Int @external } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) @@ -109,7 +113,8 @@ class Query(ObjectType): in_stock_count = Field(InStockCount) schema = build_schema(query=Query, enable_federation_2=True) - expected_result = dedent(""" + expected_result = dedent( + """ type Query { inStockCount: InStockCount _entities(representations: [_Any!]!): [_Entity]! @@ -134,7 +139,8 @@ class Query(ObjectType): type _Service { sdl: String } - """) + """ + ) assert clean_schema(schema) == clean_schema(expected_result) # Check the federation service schema definition language query = """ @@ -146,7 +152,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", "@provides"]) type Query { inStockCount: InStockCount @@ -162,7 +169,8 @@ class Query(ObjectType): name: String @external weight: Int @external } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) @@ -186,7 +194,8 @@ class Query(ObjectType): in_stock_count = Field(InStockCount) schema = build_schema(query=Query, enable_federation_2=True) - expected_result = dedent(""" + expected_result = dedent( + """ type Query { inStockCount: InStockCount _entities(representations: [_Any!]!): [_Entity]! @@ -211,7 +220,8 @@ class Query(ObjectType): type _Service { sdl: String } - """) + """ + ) assert clean_schema(schema) == clean_schema(expected_result) # Check the federation service schema definition language @@ -224,7 +234,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", "@provides"]) type Query { inStockCount: InStockCount @@ -240,6 +251,6 @@ class Query(ObjectType): name: String @external weight: Int @external } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) - diff --git a/graphene_federation/tests/test_provides_v1.py b/graphene_federation/tests/test_provides_v1.py index 1c76999..c59649b 100644 --- a/graphene_federation/tests/test_provides_v1.py +++ b/graphene_federation/tests/test_provides_v1.py @@ -31,7 +31,8 @@ class Query(ObjectType): in_stock_count = Field(InStockCount) schema = build_schema(query=Query) - expected_result = dedent(""" + expected_result = dedent( + """ type Query { inStockCount: InStockCount _entities(representations: [_Any!]!): [_Entity]! @@ -56,7 +57,8 @@ class Query(ObjectType): type _Service { sdl: String } - """) + """ + ) assert clean_schema(schema) == clean_schema(expected_result) # Check the federation service schema definition language query = """ @@ -68,7 +70,8 @@ class Query(ObjectType): """ result = graphql_sync(schema.graphql_schema, query) assert not result.errors - expected_result = dedent(""" + expected_result = dedent( + """ type Query { inStockCount: InStockCount } @@ -83,7 +86,8 @@ class Query(ObjectType): name: String @external weight: Int @external } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) @@ -107,7 +111,8 @@ class Query(ObjectType): in_stock_count = Field(InStockCount) schema = build_schema(query=Query) - expected_result = dedent(""" + expected_result = dedent( + """ type Query { inStockCount: InStockCount _entities(representations: [_Any!]!): [_Entity]! @@ -132,7 +137,8 @@ class Query(ObjectType): type _Service { sdl: String } - """) + """ + ) assert clean_schema(schema) == clean_schema(expected_result) # Check the federation service schema definition language query = """ @@ -144,7 +150,8 @@ class Query(ObjectType): """ result = graphql_sync(schema.graphql_schema, query) assert not result.errors - expected_result = dedent(""" + expected_result = dedent( + """ type Query { inStockCount: InStockCount } @@ -159,7 +166,8 @@ class Query(ObjectType): name: String @external weight: Int @external } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) @@ -183,7 +191,8 @@ class Query(ObjectType): in_stock_count = Field(InStockCount) schema = build_schema(query=Query) - expected_result = dedent(""" + expected_result = dedent( + """ type Query { inStockCount: InStockCount _entities(representations: [_Any!]!): [_Entity]! @@ -208,7 +217,8 @@ class Query(ObjectType): type _Service { sdl: String } - """) + """ + ) assert clean_schema(schema) == clean_schema(expected_result) # Check the federation service schema definition language query = """ @@ -220,7 +230,8 @@ class Query(ObjectType): """ result = graphql_sync(schema.graphql_schema, query) assert not result.errors - expected_result = dedent(""" + expected_result = dedent( + """ type Query { inStockCount: InStockCount } @@ -235,5 +246,6 @@ class Query(ObjectType): name: String @external weight: Int @external } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) diff --git a/graphene_federation/tests/test_requires.py b/graphene_federation/tests/test_requires.py index c6fda96..469c95d 100644 --- a/graphene_federation/tests/test_requires.py +++ b/graphene_federation/tests/test_requires.py @@ -42,7 +42,8 @@ class Query(ObjectType): product = Field(Product) schema = build_schema(query=Query, enable_federation_2=True) - expected_result = dedent(""" + expected_result = dedent( + """ type Query { product: Product _entities(representations: [_Any!]!): [_Entity]! @@ -63,7 +64,8 @@ class Query(ObjectType): type _Service { sdl: String } - """) + """ + ) assert clean_schema(schema) == clean_schema(expected_result) # Check the federation service schema definition language query = """ @@ -75,7 +77,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 { product: Product @@ -87,7 +90,8 @@ class Query(ObjectType): weight: Int @external shippingEstimate: String @requires(fields: "size weight") } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) @@ -107,7 +111,8 @@ class Query(ObjectType): product = Field(Product) schema = build_schema(query=Query, enable_federation_2=True) - expected_result = dedent(""" + expected_result = dedent( + """ type Query { product: Product _entities(representations: [_Any!]!): [_Entity]! @@ -128,7 +133,8 @@ class Query(ObjectType): type _Service { sdl: String } - """) + """ + ) assert clean_schema(schema) == clean_schema(expected_result) # Check the federation service schema definition language query = """ @@ -140,7 +146,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 { product: Product @@ -152,7 +159,8 @@ class Query(ObjectType): weight: Int @external shippingEstimate: String @requires(fields: "size weight") } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) @@ -171,7 +179,8 @@ class Query(ObjectType): acme = Field(Acme) schema = build_schema(query=Query, enable_federation_2=True) - expected_result = dedent(""" + expected_result = dedent( + """ type Query { acme: Acme _entities(representations: [_Any!]!): [_Entity]! @@ -191,7 +200,8 @@ class Query(ObjectType): type _Service { sdl: String } - """) + """ + ) assert clean_schema(schema) == clean_schema(expected_result) # Check the federation service schema definition language query = """ @@ -203,7 +213,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 { acme: Acme @@ -214,5 +225,6 @@ class Query(ObjectType): age: Int @external foo(someInput: String): String @requires(fields: "age") } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) diff --git a/graphene_federation/tests/test_requires_v1.py b/graphene_federation/tests/test_requires_v1.py index 5668c48..3505473 100644 --- a/graphene_federation/tests/test_requires_v1.py +++ b/graphene_federation/tests/test_requires_v1.py @@ -43,7 +43,8 @@ class Query(ObjectType): product = Field(Product) schema = build_schema(query=Query) - expected_result = dedent(""" + expected_result = dedent( + """ type Query { product: Product _entities(representations: [_Any!]!): [_Entity]! @@ -64,7 +65,8 @@ class Query(ObjectType): type _Service { sdl: String } - """) + """ + ) assert clean_schema(schema) == clean_schema(expected_result) # Check the federation service schema definition language query = """ @@ -76,7 +78,8 @@ class Query(ObjectType): """ result = graphql_sync(schema.graphql_schema, query) assert not result.errors - expected_result = dedent(""" + expected_result = dedent( + """ type Query { product: Product } @@ -87,7 +90,8 @@ class Query(ObjectType): weight: Int @external shippingEstimate: String @requires(fields: "size weight") } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) @@ -107,7 +111,8 @@ class Query(ObjectType): product = Field(Product) schema = build_schema(query=Query) - expected_result = dedent(""" + expected_result = dedent( + """ type Query { product: Product _entities(representations: [_Any!]!): [_Entity]! @@ -128,7 +133,8 @@ class Query(ObjectType): type _Service { sdl: String } - """) + """ + ) assert clean_schema(schema) == clean_schema(expected_result) # Check the federation service schema definition language query = """ @@ -140,7 +146,8 @@ class Query(ObjectType): """ result = graphql_sync(schema.graphql_schema, query) assert not result.errors - expected_result = dedent(""" + expected_result = dedent( + """ type Query { product: Product } @@ -151,7 +158,8 @@ class Query(ObjectType): weight: Int @external shippingEstimate: String @requires(fields: "size weight") } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) @@ -170,7 +178,8 @@ class Query(ObjectType): acme = Field(Acme) schema = build_schema(query=Query) - expected_result = dedent(""" + expected_result = dedent( + """ type Query { acme: Acme _entities(representations: [_Any!]!): [_Entity]! @@ -190,7 +199,8 @@ class Query(ObjectType): type _Service { sdl: String } - """) + """ + ) assert clean_schema(schema) == clean_schema(expected_result) # Check the federation service schema definition language query = """ @@ -202,7 +212,8 @@ class Query(ObjectType): """ result = graphql_sync(schema.graphql_schema, query) assert not result.errors - expected_result = dedent(""" + expected_result = dedent( + """ type Query { acme: Acme } @@ -212,6 +223,6 @@ class Query(ObjectType): age: Int @external foo(someInput: String): String @requires(fields: "age") } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) - diff --git a/graphene_federation/tests/test_scalar.py b/graphene_federation/tests/test_scalar.py index d5f1791..e80a2d0 100644 --- a/graphene_federation/tests/test_scalar.py +++ b/graphene_federation/tests/test_scalar.py @@ -42,7 +42,8 @@ class Query(ObjectType): } """ result = graphql_sync(schema.graphql_schema, query) - expected_result = dedent(""" + expected_result = dedent( + """ extend schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@inaccessible", "@shareable"]) type TestScalar @shareable { testShareableScalar(x: AddressScalar): String @shareable @@ -55,5 +56,6 @@ class Query(ObjectType): test(x: AddressScalar): String test2: [AddressScalar]! } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) diff --git a/graphene_federation/tests/test_schema_annotation.py b/graphene_federation/tests/test_schema_annotation.py index 223d791..7de4fe4 100644 --- a/graphene_federation/tests/test_schema_annotation.py +++ b/graphene_federation/tests/test_schema_annotation.py @@ -92,7 +92,8 @@ def test_user_schema(): Check that the user schema has been annotated correctly and that a request to retrieve a user works. """ - expected_result = dedent(""" + expected_result = dedent( + """ schema { query: UserQuery } @@ -116,7 +117,8 @@ def test_user_schema(): type _Service { sdl: String } - """) + """ + ) assert clean_schema(user_schema) == clean_schema(expected_result) query = """ @@ -139,7 +141,8 @@ def test_user_schema(): """ result = graphql_sync(user_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: ["@key"]) type UserQuery { @@ -151,7 +154,8 @@ def test_user_schema(): email: String! name: String } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) @@ -160,7 +164,8 @@ def test_chat_schema(): Check that the chat schema has been annotated correctly and that a request to retrieve a chat message works. """ - expected_result = dedent(""" + expected_result = dedent( + """ schema { query: ChatQuery } @@ -189,7 +194,8 @@ def test_chat_schema(): type _Service { sdl: String } - """) + """ + ) assert clean_schema(chat_schema) == clean_schema(expected_result) # Query the message field @@ -215,7 +221,8 @@ def test_chat_schema(): """ 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 { message(id: ID!): ChatMessage @@ -231,5 +238,6 @@ def test_chat_schema(): extend type ChatUser @key(fields: "userId") { userId: ID! @external } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) diff --git a/graphene_federation/tests/test_schema_annotation_v1.py b/graphene_federation/tests/test_schema_annotation_v1.py index e41181f..3ef2602 100644 --- a/graphene_federation/tests/test_schema_annotation_v1.py +++ b/graphene_federation/tests/test_schema_annotation_v1.py @@ -91,7 +91,8 @@ def test_user_schema(): Check that the user schema has been annotated correctly and that a request to retrieve a user works. """ - expected_result = dedent(""" + expected_result = dedent( + """ schema { query: UserQuery } @@ -115,7 +116,8 @@ def test_user_schema(): type _Service { sdl: String } - """) + """ + ) assert clean_schema(user_schema) == clean_schema(expected_result) query = """ query { @@ -137,7 +139,8 @@ def test_user_schema(): """ result = graphql_sync(user_schema.graphql_schema, query) assert not result.errors - expected_result = dedent(""" + expected_result = dedent( + """ type UserQuery { user(userId: ID!): User } @@ -147,7 +150,8 @@ def test_user_schema(): email: String! name: String } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) @@ -156,7 +160,8 @@ def test_chat_schema(): Check that the chat schema has been annotated correctly and that a request to retrieve a chat message works. """ - expected_result = dedent(""" + expected_result = dedent( + """ schema { query: ChatQuery } @@ -185,7 +190,8 @@ def test_chat_schema(): type _Service { sdl: String } - """) + """ + ) assert clean_schema(chat_schema) == clean_schema(expected_result) # Query the message field @@ -211,7 +217,8 @@ def test_chat_schema(): """ result = graphql_sync(chat_schema.graphql_schema, query) assert not result.errors - expected_result = dedent(""" + expected_result = dedent( + """ type ChatQuery { message(id: ID!): ChatMessage } @@ -226,5 +233,6 @@ def test_chat_schema(): extend type ChatUser @key(fields: "userId") { userId: ID! @external } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) diff --git a/graphene_federation/tests/test_shareable.py b/graphene_federation/tests/test_shareable.py index 7fbf0ae..9d28b5a 100644 --- a/graphene_federation/tests/test_shareable.py +++ b/graphene_federation/tests/test_shareable.py @@ -56,7 +56,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: ["@shareable"]) type Position @shareable { x: Int! @@ -66,7 +67,8 @@ class Query(ObjectType): type Query { inStockCount: Int! } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result) @@ -105,7 +107,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: ["@shareable"]) union SearchResult @shareable = Human | Droid | Starship @@ -127,5 +130,6 @@ class Query(ObjectType): type Query { inStockCount: Int! } - """) + """ + ) assert clean_schema(result.data["_service"]["sdl"]) == clean_schema(expected_result)