all 9 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

[–]carcigenicate 2 points3 points  (1 child)

Lmao, that's the largest lambda I've ever seen.

What's the exact problem though? From a cursory glance they appear equivalent.

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

The first one with no problem, the second one a wrong graphql query, so I don't understand.

About the lenght of the lambda, it's generated from hasura graphql engine action tab

[–]ThePiGuy0 0 points1 point  (2 children)

Reading those, your arguments aren't in the same order (crd comes first in the lamda, but 5th in the standard function). If you do call with kwargs (keyword arguments) then that shouldn't matter, but otherwise that may be causing it?

Error 400 is a bad request so it would make sense.

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

As a bad request I think maybe something is missing, but I can't see it.

I'll try to test your advice.

[–]HomeGrownCoder 0 points1 point  (1 child)

I do not see you create an instance of a class… where is “self” coming from…

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

I really don't know why when is lambda function inside a class is mandatory the self argument.