endpoint-to-query
v1.0.9
Published
A simple yet powerful CLI tool that introspects a GraphQL endpoint and generates a ready-to-use `.graphql` file containing all available **Queries** and **Mutations**.
Readme
endpoint-to-query
A simple yet powerful CLI tool that introspects a GraphQL endpoint and generates a ready-to-use .graphql file containing all available Queries and Mutations.
It automatically generates selection sets for objects, interfaces, and unions (up to a depth of 7 to avoid massive files), making it incredibly easy to explore a new API or bootstrap your client-side queries.
Features
- Zero Config: Just provide the endpoint URL.
- Complete Coverage: Generates operations for every Query and Mutation field defined in the schema.
- Smart Selection: Recursively builds selection sets. By default, it traverses as deep as possible until cycles are detected ("Auto" mode).
- Safety Fallback: If "Auto" mode produces a file too large for memory, it automatically retries with a safe depth of 3.
- Union Support: Automatically generates inline fragments for Union types.
- Prettified: Output is automatically formatted using Prettier.
- Flexible Output: Defaults to
query.graphql, or specify your own output path.
Usage
Using npx (Recommended)
You don't need to install anything. Just run:
npx endpoint-to-query <graphql-endpoint-url> [output-file] [--depth <number>]Examples:
Generate query.graphql in the current directory (default depth 7):
npx endpoint-to-query https://graphql.mainnet.sui.io/graphqlGenerate with a custom depth of 10:
npx endpoint-to-query https://graphql.mainnet.sui.io/graphql --depth 10Generate to a specific file:
npx endpoint-to-query https://graphql.mainnet.sui.io/graphql ./sui-operations.graphqlGlobal Installation
If you use it frequently, you can install it globally:
npm install -g endpoint-to-queryThen run it anywhere:
endpoint-to-query https://your-api.com/graphqlDevelopment
If you want to run it locally or contribute:
- Clone the repository.
- Install dependencies:
npm install - Build the project:
npm run build - Run the CLI:
node dist/index.js https://graphql.mainnet.sui.io/graphql
License
MIT
