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

Allow updating Operation name and args after its initialization #244

Open
pwyllcrusader opened this issue Aug 19, 2024 · 3 comments
Open

Comments

@pwyllcrusader
Copy link

pwyllcrusader commented Aug 19, 2024

🚀 Feature Request

Description

Allow updating Operation name and args after its initialization

operation = Operation(query)
operation.name = "newlyNamedQuery"
operation.args = {"some_arg": Arg(SomeKindScalar)}
operation.find_something(some_args=Variable("some_arg"))

In some cases (for automated tests) this allows to avoid code duplication while using pytest fixtures
*

Implementation details

just putting this piece of code into Operation class worked for me:

    @property
    def name(self):
        return self.__name
    
    @name.setter
    def name(self, value):
        self.__name = value

    @property
    def args(self):
        return self.__args
    
    @args.setter
    def args(self, variables_dict):
        variable_args = OrderedDict()
        for k, v in variables_dict.items():
            variable_args['$' + k] = v
        self.__args = ArgDict(variable_args)
        self.__args._set_container(self.__type.__schema__, self)
@barbieri
Copy link
Member

I'm not that found of mutating objects to run tests, why don't you create new types with different names and args for each test?

Anyway, I'd take a patch/PR, but I can't work on this atm

@pwyllcrusader
Copy link
Author

I'm not that found of mutating objects to run tests, why don't you create new types with different names and args for each test?

It helps when I use one operation fixture for all tests

Anyway, I'd take a patch/PR, but I can't work on this atm

It seems that I have no permission to push branch, otherwise I'd create it already

@pwyllcrusader
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants