Registry / devops / graphql-to-postman

graphql-to-postman

JSON →
library1.0.0jsnpmunverified

GraphQL-to-Postman is a tool by Postman Labs that converts GraphQL schema definitions (SDL) into Postman Collection v2 format. It supports both CLI and programmatic usage, with options for depth, deprecated fields, and interface version selection. Current stable version is 1.0.0. Unlike manual collection creation, this automates the process and ensures the collection matches the schema exactly.

npm install graphql-to-postman
INSTALL
IMPORT
SIG · GRAPHQL-TO-POSTMAN
G
graphql-to-postman
devopsjavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Converter
const Converter = require('graphql-to-postman');
import Converter from 'graphql-to-postman';
This package is CommonJS only; ESM import is not supported.
convert
const { convert } = require('graphql-to-postman');
const convert = require('graphql-to-postman').convert;
Named exports are destructured from require call.
validate
const { validate } = require('graphql-to-postman');
validate function checks the schema before converting.

Converts a GraphQL schema string into a Postman Collection object using the convert function.

const Converter = require('graphql-to-postman'); const { convert } = new Converter(); const schema = ` type Query { hello: String users: [User] } type User { id: ID! name: String } `; (async () => { try { const result = await convert({ type: 'graphql', data: schema, options: { depth: 2, includeDeprecatedFields: false } }); console.log(JSON.stringify(result.collection, null, 2)); } catch (error) { console.error('Conversion failed:', error.message); } })();
Debug
Known issues
gotchaThe convert function expects an input object with type and data fields; type must be 'graphql' for schema strings.
fix
Ensure input is { type: 'graphql', data: schemaString }.
affects: >=1.0.0
gotchaThe collection output is a Postman Collection object, not a JSON string; you must stringify before writing to file.
fix
Use JSON.stringify(result.collection) when saving.
affects: >=1.0.0
deprecatedInterface version 'v1' is deprecated; use 'v2' (default) for newer features.
fix
Omit the -i flag or explicitly set -i v2.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Converter is not a constructor
Using ESM import syntax with a CommonJS-only module.
fix
Use require('graphql-to-postman') instead of import.
Cannot read property 'collection' of undefined
Missing or invalid input to convert function or calling before conversion completes.
fix
Ensure input object has type and data properties, and await the convert call.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency used to parse and validate GraphQL schemas.
postman-collectionrequiredPeer dependency representing the Postman Collection data model.
Agent activity
6 hits · last 30 days
node
6
Resources
graphql-to-postman — npm install graphql-to-postman · libregistry