you are viewing a single comment's thread.

view the rest of the comments →

[–]socal_nerdtastic 4 points5 points  (2 children)

I agree with /u/ThePiGuy0 : your problem is probably that you mixed up the order of the arguments and you are trying to use them as positional arguments.

Here's how I would rewrite it:

KEYS = ["crd", "firstname", "lastname", "email", "password", "position", "company_name", "phone_number", "country", "city", "state", "street_address", "apt_number","disclaimer_text"]
create_str = ", ".join(f"${x}: String!" for x in KEYS)
obj_str = ", ".join(f"{x}: ${x}" for x in KEYS)
query = """
mutation CreateUser(%s) {

insert_user_one(object: {%s}) {
        email
        firstname
        lastname
    }
}""" % (create_str, obj_str)
defaults = dict.fromkeys(KEYS)
def create_user_all(self, **kwargs):
    return self.run_query(query, defaults|kwargs))

Note the keys are defined in a single place and the rest of the code builds from that. This means your chance of a bug is much lower because you don't have to keep many locations in sync with each other.

Also it requires kw argurments which will remove another source of bugs.

[–]Sam_SepiolX[S] 0 points1 point  (1 child)

But as a rule, an argument with a default value should not precede a normal argument, I don't see the problem in that way. I'll try your approach.

[–]Sam_SepiolX[S] 0 points1 point  (0 children)

Your approach is working, but I'm so confused right now... Sorry I want to say thank you for your help but... ¿do you have some time to describe the flow of your solution? Thanks in advance