profusion / sgqlc

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

Best practice to construct nested query variables #217

Open elados93 opened 1 year ago

elados93 commented 1 year ago

I'm having a GraphQL schema that I'm using codegen for schema & operations generation, just like the README suggest.

I wonder if there is a better way in sgqlc to construct variables with type hints so the experience will be closer to sending queries with GraphQL playground, see this API example.

I'd like to have:

  1. Autocomplete in IDE (currently fields are part of **kwargs and not part of init args).
  2. Type hints for the variables, mainly because I have many inputs and some of them are nested so it's very errors prune.

currently I'm building my variables with the schema objects I generated:

input = CollectionWhereInput(name='some-collection_name', create_time_gt=datetime.time())
op = Operations.query.get_collections
res = endpoint(op, variables=input.__to_json_value__())

Thanks.