Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constructors for auto generated classes? #42

Closed
Tbilgere-td opened this issue May 17, 2019 · 2 comments
Closed

Constructors for auto generated classes? #42

Tbilgere-td opened this issue May 17, 2019 · 2 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Tbilgere-td
Copy link

Tbilgere-td commented May 17, 2019

We're using sgqlc to interact with a GQL service we've built and love the removal of dict-of-stuff navigation in the response objects and field selections. We can't quite figure out how to do the same for complex argument/input values though.
As an example:

class FilterDateInput(sgqlc.types.Input):
    start = sgqlc.types.Field(String, graphql_name='start')
    end = sgqlc.types.Field(String, graphql_name='end')
class FilterValueInput(sgqlc.types.Input):
    value = sgqlc.types.Field(String, graphql_name='value')
class FilterInput(sgqlc.types.Input):
    date = sgqlc.types.Field(FilterDateInput, graphql_name='date')
    id = sgqlc.types.Field(FilterInput, graphql_name='id')

Ideally we would be able to generate a filter by:

gql_filter = FilterInput(
    date=FilterDateInput(start='04-12-2012', end='04-15-2012'), 
    id=FilterValueInput(value='A17')
)
operation.queryThings(filter=gql_filter, user="bill")

This would benefit from tool tips and autocomplete where as the current method we're aware of is:

gql_filter = { 
    'date': {'start':'04-12-2012', 'end':'04-12-2012'}, 
    'id':{'value':'A17'}
}
operation.queryThings(filter=gql_filter, user="bill")

Which as the schema grows become increasingly unwieldy. Is there a way that we are missing to do this or is there a way to generate classes that will act in this way using introspection of the sgqlc’s autogenerated classes?

@barbieri barbieri self-assigned this May 17, 2019
@barbieri
Copy link
Member

I focused on the read-side of the data, it's basically implemented by the sgqlc.operation and selectors, so I think the creation side will need some specific work to allow that.

Shouldn't be hard as input types are much simpler and particularly if you stick with __init__ and __setattr__ to set values.

I did this for some other project (customer private), not hard... but takes some time I don't have at this moment. This month is being particularly busy at work. I'll try to get back to sqglc development in June.

@barbieri barbieri added enhancement New feature or request good first issue Good for newcomers labels May 17, 2019
josephlbarnett added a commit to josephlbarnett/sgqlc that referenced this issue Jun 11, 2019
Allows specification of Input type values using the actual classes
instead of dicts of strings

Fixes profusion#42
@barbieri
Copy link
Member

could you confirm b1c740c fixed it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants