timqian / gql-generator

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

Unexpected output on scheme based on unions #37

Open menxit opened 4 years ago

menxit commented 4 years ago

I'm generating queries based on this graphql scheme:

type Query {
  animals: [AnimalResult]!
}

union AnimalResult = Dog | Cat

type Dog {
  example: [Something!]!
}

type Cat {
  example: [Something!]!
}

type Something {
  id: ID!
}

I would expect that a animals.gql would be generated:

query animals{
    animals{
        ... on Dog {
            example{
                id
            }
        }
        ... on Cat {
            example{
                id
            }
        }
    }
}

But I obtain this:

query animals{
    animals{
        ... on Dog {
            example{
                id
            }
        }
        ... on Cat {

        }
    }
}

As you can see id field in Cat is not included.

Is this a bug? I would like to fix this, I think it could be something about this loop: https://github.com/timqian/gql-generator/blob/master/index.js#L140

mishasyrbu commented 3 years ago

fix #44