profusion / sgqlc

Simple GraphQL Client
https://sgqlc.readthedocs.io/
ISC License
506 stars 85 forks source link

Removed types sorting #209

Closed Evgenus closed 1 year ago

Evgenus commented 2 years ago

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

joegoldbeck commented 2 years ago

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!

Evgenus commented 1 year ago

@barbieri Hi. Can we address this?

barbieri commented 1 year ago

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 commented 1 year ago

could you please check #219

barbieri commented 1 year ago

merged, pleas reopen if still an issue