def can_deep_copy_a_schema(): source = """ schema { query: Farm mutation: Work } type Cow { id: ID! name: String moos: Boolean } type Pig { id: ID! name: String oink: Boolean } union Animal = Cow | Pig enum Food { CORN FRUIT } input Feed { amount: Float type: Food } type Farm { animals: [Animal!]! } type Work { feed(feed: Feed): Boolean } """ schema = build_schema(source) schema_copy = deepcopy(schema) for name in ("Cow", "Pig", "Animal", "Food", "Feed", "Farm", "Work"): assert schema.get_type(name) is not schema_copy.get_type(name) assert print_schema(lexicographic_sort_schema(schema)) == print_schema( lexicographic_sort_schema(schema_copy))
def sort_sdl(sdl: str) -> str: schema = build_schema(sdl) return print_schema(lexicographic_sort_schema(schema))