sgqlc icon indicating copy to clipboard operation
sgqlc copied to clipboard

Removed types sorting

Open Evgenus opened this issue 2 years ago • 1 comments

Well, that might be a good idea to sort types in the file but sorting by name creates a mess with dependencies as was found in #189

fixes #189

Evgenus avatar Jul 22 '22 23:07 Evgenus

I ran into https://github.com/profusion/sgqlc/issues/189 exactly, and reordering the types + using this PR does seem to fix it for me!

joegoldbeck avatar Sep 07 '22 20:09 joegoldbeck

@barbieri Hi. Can we address this?

Evgenus avatar Nov 02 '22 10:11 Evgenus

sorry guys, I'm bit overloaded at work. As said in the ticket, removing the sorting is not a solution as it may break it.

Right now we're sorting by name only. what if we added weighted value for kind before that, similar to:

KIND_SORT_ORDER = {
    'SCALAR': 0,
    'ENUM': 1,
    'INPUT_OBJECT': 2,
    'INTERFACE': 3,
    'OBJECT': 4,
    'UNION': 5,
}

def get_type_sort_key(t):
    return (KIND_SORT_ORDER[t['kind']], t['name'])

# ...
class CodeGen:
# ...
    def __init__(self, schema_name, schema, writer, docstrings):
# ...
        self.types = sorted(schema['types'], key=get_type_sort_key)

Could you check if that one solves the issue? Otherwise we'd need to add toposort using the interfaces and possibleTypes

barbieri avatar Nov 10 '22 01:11 barbieri

could you please check #219

barbieri avatar Dec 05 '22 18:12 barbieri

merged, pleas reopen if still an issue

barbieri avatar Dec 05 '22 18:12 barbieri