timqian / gql-generator

Generate queries from graphql schema, used for writing api test.
MIT License
374 stars 93 forks source link

Add union type support, fix empty fields #10

Closed robCrawford closed 5 years ago

robCrawford commented 5 years ago

Adds union type support. Adds child argument declarations to query. Fixes bug where child query had no fields i.e. empty braces. All working so far on a fairly large schema!

timqian commented 5 years ago

@robCrawford Thanks for bringing union type into this lib. About the child argument feature, I have considered to add similar implementation like yours, but there is an issue if two fields have the same argument names. For example:

mutation signup($email: String!, $username: String!, $password: String!, $count: Int, $count: Int){
    signup(email: $email, username: $username, password: $password){
        token(count: $count)
        user{
            id
            username(count: $count)
            email
            createdAt
            context{
                user{
                    id
                    username(count: $count)
                    email
                }
                domain
            }
        }
    }
}

What do you think about it?

robCrawford commented 5 years ago

Hi @timqian, thanks for your great work on this. I thought i'd fixed this issue already... I will take another look.

robCrawford commented 5 years ago

The only solution I can see is to prefix the var with its parent field name... seems to work well enough for my current tests.

timqian commented 5 years ago

Thanks, @robCrawford This solution is not perfect but better than current behavior.

timqian commented 5 years ago

@robCrawford I reverted the code to the first version you suggested and published to npm (in this commit 6250299), the reason is prefixing did not fully resolve the issue I mentioned above and brings compatible behavior to the earlier version