def is_schema_of_common_names(schema: GraphQLSchema) -> bool: """Check whether this schema uses the common naming convention. GraphQL schema define root types for each type of operation. These types are the same as any other type and can be named in any manner, however there is a common naming convention: schema { query: Query mutation: Mutation subscription: Subscription } When using this naming convention, the schema description can be omitted. """ query_type = schema.get_query_type() if query_type and query_type.name != "Query": return False mutation_type = schema.get_mutation_type() if mutation_type and mutation_type.name != "Mutation": return False subscription_type = schema.get_subscription_type() return not subscription_type or subscription_type.name == "Subscription"
def print_schema_definition(schema: GraphQLSchema) -> Optional[str]: operation_types = [] query_type = schema.get_query_type() if query_type: operation_types.append(f" query: {query_type.name}") mutation_type = schema.get_mutation_type() if mutation_type: operation_types.append(f" mutation: {mutation_type.name}") subscription_type = schema.get_subscription_type() if subscription_type: operation_types.append(f" subscription: {subscription_type.name}") return "schema {\n" + "\n".join(operation_types) + "\n}"