timqian / gql-generator

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

Using programmatically #6

Open samhatoum opened 5 years ago

samhatoum commented 5 years ago

Thanks for writing this.

Is there a way to use this programmatically instead of writing files?

I would love to use this tool + https://github.com/marak/Faker.js to use the field types in the schema to generate a query with random data :)

timqian commented 5 years ago

This tool generates general queries accepting variables as the query argument. In your case, you can generate random data as the variables. However, this tool did not tell you what the possible variables a query accepts, you might need to get this info by other ways.

lgandecki commented 5 years ago

What Sam is asking about is whether there is a way of generating and running the queries on-the-fly instead of writing to files first and then importing. I imagine there is no easy way to do so now, but it shouldn't be too hard to add that option.

Skitionek commented 5 years ago

For reference, I ran into the same question and I adopted the code so queries can be generated programmatically. Moreover, it runs with more clever arguments dedupe algorithm (symbol23 -> amar_symbolB) and request fields might be customized (useful with fragments resolvers). https://github.com/Skitionek/gql-generator-node