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.
graphqlToOpenApi
✓ import { graphqlToOpenApi } from 'graphql-to-openapi'
✗ const graphqlToOpenApi = require('graphql-to-openapi')
Package is ESM-only; named export, not default.
graphqlToOpenApi
✓ import { graphqlToOpenApi } from 'graphql-to-openapi'
✗ import graphqlToOpenApi from 'graphql-to-openapi'
graphqlToOpenApi is a named export, not the default.
GraphqlToOpenApiOptions
✓ import type { GraphqlToOpenApiOptions } from 'graphql-to-openapi'
✗ import { GraphqlToOpenApiOptions } from 'graphql-to-openapi'
It's a type, use `import type` for TypeScript.
Shows programmatic usage: parse schema and query, convert to OpenAPI, handle errors.
import { graphqlToOpenApi } from 'graphql-to-openapi';
import { buildSchema } from 'graphql';
const schema = buildSchema(`
type Query {
hello: String
}
`);
const query = `
query MyQuery {
hello
}
`;
const { error, openApiSchema, queryErrors, schemaError } = graphqlToOpenApi({
schema,
query,
});
if (error) {
console.error('Error:', error);
} else if (schemaError) {
console.error('Schema error:', schemaError);
} else if (queryErrors.length > 0) {
console.error('Query errors:', queryErrors);
} else {
console.log('OpenAPI schema:', JSON.stringify(openApiSchema, null, 2));
}
Errors
Common errors & fixes
Error: GraphQL query must be named
The input query string does not specify a name for the operation.
fixAdd a name to the query, e.g., 'query MyQuery { ... }'. TypeError: Cannot read properties of undefined (reading 'definitions')
The schema object passed is not valid or is undefined.
fixEnsure the schema is a valid GraphQL schema object (use buildSchema or similar).
Audit
Dependencies
No dependency data recorded yet.