GraphQL Query Generator by IBM
Tags: graphql, webdev, beginners, news
Published: 2020-07-22 08:20:55

GraphQL Query Generator is an interesting library brought to you by the IBM team, which's the main idea is to allow users to **generate randomized GraphQL queries** from any given GraphQL schema.

The first thought that comes to your mind might be:
> *"Why I may ever want a bunch of randomized queries?"*

but giving it a second thought it might be quite useful. The team behind the GraphQL Query Generator suggested **two basic use-cases** for their library:

- **Engineering** - when operating a GraphQL service you might find this library useful for:
  - developing a collection of test modules of GraphQL queries,
  - developing a test group of queries to check the effect of performance improvements,
- **Scientific** - to learn about the characteristics of various GraphQL services.

## Queries generation

The library provides two functions for generating random GraphQL queries, both expecting a GraphQL schema, as well as specific  instructions provided in configuration object as an input:

- `getRandomQuery(schema: GraphQLSchema, config: Configuration)` - this function produces a random query from the given schema, considering configuration passed as an input,

- `getRandomMutation(schema: GraphQLSchema, config: Configuration)` -  that produces a random mutation from the given schema, considering passed configuration.

![Diagram representing how GraphQL Query Generator works](https://dev-to-uploads.s3.amazonaws.com/i/9qro42act2tp7h55c9t0.png)

##### Source: [github.com/IBM](https://github.com/IBM/graphql-query-generator)

The configuration object accepts a set of predefined properties i.e.:
- `maxDepth` - that defines the maximum depths of the query/mutation to generate,
- `argumentsToIgnore` - in which you can  list arguments names that should be ignored,
- `considerInterfaces`- which a signal for the generator that it should create queries containing interfaces,
- `considerUnions` - that creates queries that contain unions etc.

The full list of available properties is available in the [GraphQL Query Generator docs](https://github.com/IBM/graphql-query-generator).

### Sample GraphQL Query Generator configuration object

![Sample configuration object](https://dev-to-uploads.s3.amazonaws.com/i/6u3ic30ngj1zx6mg28fd.png)

##### Source: [github.com/IBM/graphql-query-generator](https://github.com/IBM/graphql-query-generator)


## Great addition

GraphQL Query Generator is a great addition to the already broad spectrum of GraphQL tools. Its a relatively new library that is worth experimenting with as maybe you could find some other innovative ways it could be used by the GraphQL community.

---

## Speed up your GraphQL API development

*GraphQL Editor* is a supportive tool for both advanced GraphQL users as well as those taking their first steps with GraphQL APIs. Our all-in-one development environment for GraphQL will help you build, manage & deploy your GraphQL API much faster. **[Try GraphQL Editor for free!](https://graphqleditor.com)**


[![GraphQL Editor](https://res.cloudinary.com/practicaldev/image/fetch/s--XhJnT9d1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/835ac1nun474qfgn1tfi.gif)](https://graphqleditor.com/)