prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Federated schemas should not require at least one query to be implemented
  In a Federated environment, the Gateway instantiates the Query type by default. This means that an implementing services should _not_ be required to implement or extend a query. 
  
  # Ideal Scenario
  This is an example scenario of what is valid in Node and Java implementations. For example, it should be valid to expose a service that exposes no root queries, but only the federated query fields, like below.
  
  Produced Query type:
  
  
  **Example**: This is what the schemas would look like for two federated services:
  ## Product Service
  product/schema.gql
  ```gql
  extend type Query {
     products: [Product]
  }
  
  type Product {
    id: ID!
    name: String
    reviews: [ProductReview]
  }
  
  extend type ProductReview @key(fields: "id") {
    id: ID! @external
  }
  ```
  **Output**:
  
  ```
  products: [Product]
  _entities(representations: [_Any]): [_Entity]
  _service: _Service
  ```
  
  ## Review Service
  review/schema.gql
  ```gql
  # Notice how we don't have to extend the Query type
  type ProductReview @key(fields: "id") {
     id: ID!
     comment: String!
  }
  ```
  
  **Output**:
  This should be valid.
  ```
  _entities(representations: [_Any]): [_Entity]
  _service: _Service
  ```
  
  
  # Breaking Scenario
  When attempting to implement the `ProductReview` service (see example above) without extending the Query type, Ariadne will fail to [generate a federated schema](https://github.com/mirumee/ariadne/blob/master/ariadne/contrib/federation/schema.py#L57). This is because `make_executable_schema` attempts to generate a federated schema by [extending a Query type](https://github.com/mirumee/ariadne/blob/master/ariadne/contrib/federation/schema.py#L24) with the assumption that a Query type has been defined, which technically it isn't. 
  
  
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `ariadne/contrib/federation/schema.py`
  Content:
  ```
  1 from typing import Dict, List, Type, Union, cast
  2 
  3 from graphql import extend_schema, parse
  4 from graphql.language import DocumentNode
  5 from graphql.type import (
  6     GraphQLObjectType,
  7     GraphQLSchema,
  8     GraphQLUnionType,
  9 )
  10 
  11 from ...executable_schema import make_executable_schema, join_type_defs
  12 from ...schema_visitor import SchemaDirectiveVisitor
  13 from ...types import SchemaBindable
  14 from .utils import get_entity_types, purge_schema_directives, resolve_entities
  15 
  16 
  17 federation_service_type_defs = """
  18     scalar _Any
  19 
  20     type _Service {
  21         sdl: String
  22     }
  23 
  24     extend type Query {
  25         _service: _Service!
  26     }
  27 
  28     directive @external on FIELD_DEFINITION
  29     directive @requires(fields: String!) on FIELD_DEFINITION
  30     directive @provides(fields: String!) on FIELD_DEFINITION
  31     directive @key(fields: String!) repeatable on OBJECT | INTERFACE
  32     directive @extends on OBJECT | INTERFACE
  33 """
  34 
  35 federation_entity_type_defs = """
  36     union _Entity
  37 
  38     extend type Query {
  39         _entities(representations: [_Any!]!): [_Entity]!
  40     }
  41 """
  42 
  43 
  44 def make_federated_schema(
  45     type_defs: Union[str, List[str]],
  46     *bindables: Union[SchemaBindable, List[SchemaBindable]],
  47     directives: Dict[str, Type[SchemaDirectiveVisitor]] = None,
  48 ) -> GraphQLSchema:
  49     if isinstance(type_defs, list):
  50         type_defs = join_type_defs(type_defs)
  51 
  52     # Remove custom schema directives (to avoid apollo-gateway crashes).
  53     # NOTE: This does NOT interfere with ariadne's directives support.
  54     sdl = purge_schema_directives(type_defs)
  55 
  56     type_defs = join_type_defs([type_defs, federation_service_type_defs])
  57     schema = make_executable_schema(
  58         type_defs,
  59         *bindables,
  60         directives=directives,
  61     )
  62 
  63     # Parse through the schema to find all entities with key directive.
  64     entity_types = get_entity_types(schema)
  65     has_entities = len(entity_types) > 0
  66 
  67     # Add the federation type definitions.
  68     if has_entities:
  69         schema = extend_federated_schema(
  70             schema,
  71             parse(federation_entity_type_defs),
  72         )
  73 
  74         # Add _entities query.
  75         entity_type = schema.get_type("_Entity")
  76         if entity_type:
  77             entity_type = cast(GraphQLUnionType, entity_type)
  78             entity_type.types = entity_types
  79 
  80         query_type = schema.get_type("Query")
  81         if query_type:
  82             query_type = cast(GraphQLObjectType, query_type)
  83             query_type.fields["_entities"].resolve = resolve_entities
  84 
  85     # Add _service query.
  86     query_type = schema.get_type("Query")
  87     if query_type:
  88         query_type = cast(GraphQLObjectType, query_type)
  89         query_type.fields["_service"].resolve = lambda _service, info: {"sdl": sdl}
  90 
  91     return schema
  92 
  93 
  94 def extend_federated_schema(
  95     schema: GraphQLSchema,
  96     document_ast: DocumentNode,
  97     assume_valid: bool = False,
  98     assume_valid_sdl: bool = False,
  99 ) -> GraphQLSchema:
  100     extended_schema = extend_schema(
  101         schema,
  102         document_ast,
  103         assume_valid,
  104         assume_valid_sdl,
  105     )
  106 
  107     for (k, v) in schema.type_map.items():
  108         resolve_reference = getattr(v, "__resolve_reference__", None)
  109         if resolve_reference and k in extended_schema.type_map:
  110             setattr(
  111                 extended_schema.type_map[k],
  112                 "__resolve_reference__",
  113                 resolve_reference,
  114             )
  115 
  116     return extended_schema
  117
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/ariadne/contrib/federation/schema.py b/ariadne/contrib/federation/schema.py
  --- a/ariadne/contrib/federation/schema.py
  +++ b/ariadne/contrib/federation/schema.py
  @@ -2,6 +2,7 @@
   
   from graphql import extend_schema, parse
   from graphql.language import DocumentNode
  +from graphql.language.ast import ObjectTypeDefinitionNode
   from graphql.type import (
       GraphQLObjectType,
       GraphQLSchema,
  @@ -17,13 +18,13 @@
   federation_service_type_defs = """
       scalar _Any
   
  -    type _Service {
  +    type _Service {{
           sdl: String
  -    }
  +    }}
   
  -    extend type Query {
  +    {type_token} Query {{
           _service: _Service!
  -    }
  +    }}
   
       directive @external on FIELD_DEFINITION
       directive @requires(fields: String!) on FIELD_DEFINITION
  @@ -41,6 +42,17 @@
   """
   
   
  +def has_query_type(type_defs: str) -> bool:
  +    ast_document = parse(type_defs)
  +    for definition in ast_document.definitions:
  +        if (
  +            isinstance(definition, ObjectTypeDefinitionNode)
  +            and definition.name.value == "Query"
  +        ):
  +            return True
  +    return False
  +
  +
   def make_federated_schema(
       type_defs: Union[str, List[str]],
       *bindables: Union[SchemaBindable, List[SchemaBindable]],
  @@ -52,8 +64,10 @@
       # Remove custom schema directives (to avoid apollo-gateway crashes).
       # NOTE: This does NOT interfere with ariadne's directives support.
       sdl = purge_schema_directives(type_defs)
  +    type_token = "extend type" if has_query_type(sdl) else "type"
  +    federation_service_type = federation_service_type_defs.format(type_token=type_token)
   
  -    type_defs = join_type_defs([type_defs, federation_service_type_defs])
  +    type_defs = join_type_defs([type_defs, federation_service_type])
       schema = make_executable_schema(
           type_defs,
           *bindables,
  @@ -66,10 +80,7 @@
   
       # Add the federation type definitions.
       if has_entities:
  -        schema = extend_federated_schema(
  -            schema,
  -            parse(federation_entity_type_defs),
  -        )
  +        schema = extend_federated_schema(schema, parse(federation_entity_type_defs))
   
           # Add _entities query.
           entity_type = schema.get_type("_Entity")
  
verification_info: {"golden_diff": "diff --git a/ariadne/contrib/federation/schema.py b/ariadne/contrib/federation/schema.py\n--- a/ariadne/contrib/federation/schema.py\n+++ b/ariadne/contrib/federation/schema.py\n@@ -2,6 +2,7 @@\n \n from graphql import extend_schema, parse\n from graphql.language import DocumentNode\n+from graphql.language.ast import ObjectTypeDefinitionNode\n from graphql.type import (\n     GraphQLObjectType,\n     GraphQLSchema,\n@@ -17,13 +18,13 @@\n federation_service_type_defs = \"\"\"\n     scalar _Any\n \n-    type _Service {\n+    type _Service {{\n         sdl: String\n-    }\n+    }}\n \n-    extend type Query {\n+    {type_token} Query {{\n         _service: _Service!\n-    }\n+    }}\n \n     directive @external on FIELD_DEFINITION\n     directive @requires(fields: String!) on FIELD_DEFINITION\n@@ -41,6 +42,17 @@\n \"\"\"\n \n \n+def has_query_type(type_defs: str) -> bool:\n+    ast_document = parse(type_defs)\n+    for definition in ast_document.definitions:\n+        if (\n+            isinstance(definition, ObjectTypeDefinitionNode)\n+            and definition.name.value == \"Query\"\n+        ):\n+            return True\n+    return False\n+\n+\n def make_federated_schema(\n     type_defs: Union[str, List[str]],\n     *bindables: Union[SchemaBindable, List[SchemaBindable]],\n@@ -52,8 +64,10 @@\n     # Remove custom schema directives (to avoid apollo-gateway crashes).\n     # NOTE: This does NOT interfere with ariadne's directives support.\n     sdl = purge_schema_directives(type_defs)\n+    type_token = \"extend type\" if has_query_type(sdl) else \"type\"\n+    federation_service_type = federation_service_type_defs.format(type_token=type_token)\n \n-    type_defs = join_type_defs([type_defs, federation_service_type_defs])\n+    type_defs = join_type_defs([type_defs, federation_service_type])\n     schema = make_executable_schema(\n         type_defs,\n         *bindables,\n@@ -66,10 +80,7 @@\n \n     # Add the federation type definitions.\n     if has_entities:\n-        schema = extend_federated_schema(\n-            schema,\n-            parse(federation_entity_type_defs),\n-        )\n+        schema = extend_federated_schema(schema, parse(federation_entity_type_defs))\n \n         # Add _entities query.\n         entity_type = schema.get_type(\"_Entity\")\n", "issue": "Federated schemas should not require at least one query to be implemented\nIn a Federated environment, the Gateway instantiates the Query type by default. This means that an implementing services should _not_ be required to implement or extend a query. \r\n\r\n# Ideal Scenario\r\nThis is an example scenario of what is valid in Node and Java implementations. For example, it should be valid to expose a service that exposes no root queries, but only the federated query fields, like below.\r\n\r\nProduced Query type:\r\n\r\n\r\n**Example**: This is what the schemas would look like for two federated services:\r\n## Product Service\r\nproduct/schema.gql\r\n```gql\r\nextend type Query {\r\n   products: [Product]\r\n}\r\n\r\ntype Product {\r\n  id: ID!\r\n  name: String\r\n  reviews: [ProductReview]\r\n}\r\n\r\nextend type ProductReview @key(fields: \"id\") {\r\n  id: ID! @external\r\n}\r\n```\r\n**Output**:\r\n\r\n```\r\nproducts: [Product]\r\n_entities(representations: [_Any]): [_Entity]\r\n_service: _Service\r\n```\r\n\r\n## Review Service\r\nreview/schema.gql\r\n```gql\r\n# Notice how we don't have to extend the Query type\r\ntype ProductReview @key(fields: \"id\") {\r\n   id: ID!\r\n   comment: String!\r\n}\r\n```\r\n\r\n**Output**:\r\nThis should be valid.\r\n```\r\n_entities(representations: [_Any]): [_Entity]\r\n_service: _Service\r\n```\r\n\r\n\r\n# Breaking Scenario\r\nWhen attempting to implement the `ProductReview` service (see example above) without extending the Query type, Ariadne will fail to [generate a federated schema](https://github.com/mirumee/ariadne/blob/master/ariadne/contrib/federation/schema.py#L57). This is because `make_executable_schema` attempts to generate a federated schema by [extending a Query type](https://github.com/mirumee/ariadne/blob/master/ariadne/contrib/federation/schema.py#L24) with the assumption that a Query type has been defined, which technically it isn't. \r\n\r\n\r\n\n", "before_files": [{"content": "from typing import Dict, List, Type, Union, cast\n\nfrom graphql import extend_schema, parse\nfrom graphql.language import DocumentNode\nfrom graphql.type import (\n    GraphQLObjectType,\n    GraphQLSchema,\n    GraphQLUnionType,\n)\n\nfrom ...executable_schema import make_executable_schema, join_type_defs\nfrom ...schema_visitor import SchemaDirectiveVisitor\nfrom ...types import SchemaBindable\nfrom .utils import get_entity_types, purge_schema_directives, resolve_entities\n\n\nfederation_service_type_defs = \"\"\"\n    scalar _Any\n\n    type _Service {\n        sdl: String\n    }\n\n    extend type Query {\n        _service: _Service!\n    }\n\n    directive @external on FIELD_DEFINITION\n    directive @requires(fields: String!) on FIELD_DEFINITION\n    directive @provides(fields: String!) on FIELD_DEFINITION\n    directive @key(fields: String!) repeatable on OBJECT | INTERFACE\n    directive @extends on OBJECT | INTERFACE\n\"\"\"\n\nfederation_entity_type_defs = \"\"\"\n    union _Entity\n\n    extend type Query {\n        _entities(representations: [_Any!]!): [_Entity]!\n    }\n\"\"\"\n\n\ndef make_federated_schema(\n    type_defs: Union[str, List[str]],\n    *bindables: Union[SchemaBindable, List[SchemaBindable]],\n    directives: Dict[str, Type[SchemaDirectiveVisitor]] = None,\n) -> GraphQLSchema:\n    if isinstance(type_defs, list):\n        type_defs = join_type_defs(type_defs)\n\n    # Remove custom schema directives (to avoid apollo-gateway crashes).\n    # NOTE: This does NOT interfere with ariadne's directives support.\n    sdl = purge_schema_directives(type_defs)\n\n    type_defs = join_type_defs([type_defs, federation_service_type_defs])\n    schema = make_executable_schema(\n        type_defs,\n        *bindables,\n        directives=directives,\n    )\n\n    # Parse through the schema to find all entities with key directive.\n    entity_types = get_entity_types(schema)\n    has_entities = len(entity_types) > 0\n\n    # Add the federation type definitions.\n    if has_entities:\n        schema = extend_federated_schema(\n            schema,\n            parse(federation_entity_type_defs),\n        )\n\n        # Add _entities query.\n        entity_type = schema.get_type(\"_Entity\")\n        if entity_type:\n            entity_type = cast(GraphQLUnionType, entity_type)\n            entity_type.types = entity_types\n\n        query_type = schema.get_type(\"Query\")\n        if query_type:\n            query_type = cast(GraphQLObjectType, query_type)\n            query_type.fields[\"_entities\"].resolve = resolve_entities\n\n    # Add _service query.\n    query_type = schema.get_type(\"Query\")\n    if query_type:\n        query_type = cast(GraphQLObjectType, query_type)\n        query_type.fields[\"_service\"].resolve = lambda _service, info: {\"sdl\": sdl}\n\n    return schema\n\n\ndef extend_federated_schema(\n    schema: GraphQLSchema,\n    document_ast: DocumentNode,\n    assume_valid: bool = False,\n    assume_valid_sdl: bool = False,\n) -> GraphQLSchema:\n    extended_schema = extend_schema(\n        schema,\n        document_ast,\n        assume_valid,\n        assume_valid_sdl,\n    )\n\n    for (k, v) in schema.type_map.items():\n        resolve_reference = getattr(v, \"__resolve_reference__\", None)\n        if resolve_reference and k in extended_schema.type_map:\n            setattr(\n                extended_schema.type_map[k],\n                \"__resolve_reference__\",\n                resolve_reference,\n            )\n\n    return extended_schema\n", "path": "ariadne/contrib/federation/schema.py"}], "after_files": [{"content": "from typing import Dict, List, Type, Union, cast\n\nfrom graphql import extend_schema, parse\nfrom graphql.language import DocumentNode\nfrom graphql.language.ast import ObjectTypeDefinitionNode\nfrom graphql.type import (\n    GraphQLObjectType,\n    GraphQLSchema,\n    GraphQLUnionType,\n)\n\nfrom ...executable_schema import make_executable_schema, join_type_defs\nfrom ...schema_visitor import SchemaDirectiveVisitor\nfrom ...types import SchemaBindable\nfrom .utils import get_entity_types, purge_schema_directives, resolve_entities\n\n\nfederation_service_type_defs = \"\"\"\n    scalar _Any\n\n    type _Service {{\n        sdl: String\n    }}\n\n    {type_token} Query {{\n        _service: _Service!\n    }}\n\n    directive @external on FIELD_DEFINITION\n    directive @requires(fields: String!) on FIELD_DEFINITION\n    directive @provides(fields: String!) on FIELD_DEFINITION\n    directive @key(fields: String!) repeatable on OBJECT | INTERFACE\n    directive @extends on OBJECT | INTERFACE\n\"\"\"\n\nfederation_entity_type_defs = \"\"\"\n    union _Entity\n\n    extend type Query {\n        _entities(representations: [_Any!]!): [_Entity]!\n    }\n\"\"\"\n\n\ndef has_query_type(type_defs: str) -> bool:\n    ast_document = parse(type_defs)\n    for definition in ast_document.definitions:\n        if (\n            isinstance(definition, ObjectTypeDefinitionNode)\n            and definition.name.value == \"Query\"\n        ):\n            return True\n    return False\n\n\ndef make_federated_schema(\n    type_defs: Union[str, List[str]],\n    *bindables: Union[SchemaBindable, List[SchemaBindable]],\n    directives: Dict[str, Type[SchemaDirectiveVisitor]] = None,\n) -> GraphQLSchema:\n    if isinstance(type_defs, list):\n        type_defs = join_type_defs(type_defs)\n\n    # Remove custom schema directives (to avoid apollo-gateway crashes).\n    # NOTE: This does NOT interfere with ariadne's directives support.\n    sdl = purge_schema_directives(type_defs)\n    type_token = \"extend type\" if has_query_type(sdl) else \"type\"\n    federation_service_type = federation_service_type_defs.format(type_token=type_token)\n\n    type_defs = join_type_defs([type_defs, federation_service_type])\n    schema = make_executable_schema(\n        type_defs,\n        *bindables,\n        directives=directives,\n    )\n\n    # Parse through the schema to find all entities with key directive.\n    entity_types = get_entity_types(schema)\n    has_entities = len(entity_types) > 0\n\n    # Add the federation type definitions.\n    if has_entities:\n        schema = extend_federated_schema(schema, parse(federation_entity_type_defs))\n\n        # Add _entities query.\n        entity_type = schema.get_type(\"_Entity\")\n        if entity_type:\n            entity_type = cast(GraphQLUnionType, entity_type)\n            entity_type.types = entity_types\n\n        query_type = schema.get_type(\"Query\")\n        if query_type:\n            query_type = cast(GraphQLObjectType, query_type)\n            query_type.fields[\"_entities\"].resolve = resolve_entities\n\n    # Add _service query.\n    query_type = schema.get_type(\"Query\")\n    if query_type:\n        query_type = cast(GraphQLObjectType, query_type)\n        query_type.fields[\"_service\"].resolve = lambda _service, info: {\"sdl\": sdl}\n\n    return schema\n\n\ndef extend_federated_schema(\n    schema: GraphQLSchema,\n    document_ast: DocumentNode,\n    assume_valid: bool = False,\n    assume_valid_sdl: bool = False,\n) -> GraphQLSchema:\n    extended_schema = extend_schema(\n        schema,\n        document_ast,\n        assume_valid,\n        assume_valid_sdl,\n    )\n\n    for (k, v) in schema.type_map.items():\n        resolve_reference = getattr(v, \"__resolve_reference__\", None)\n        if resolve_reference and k in extended_schema.type_map:\n            setattr(\n                extended_schema.type_map[k],\n                \"__resolve_reference__\",\n                resolve_reference,\n            )\n\n    return extended_schema\n", "path": "ariadne/contrib/federation/schema.py"}]}