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.
createGraphQLSchema
✓ import { createGraphQLSchema } from 'openapi-to-graphql'
✗ const createGraphQLSchema = require('openapi-to-graphql')
The package is ESM-compatible but also supports require(). Use named import for this function.
GraphQLSchema
✓ import { GraphQLSchema } from 'graphql'
✗ import GraphQLSchema from 'graphql'
GraphQLSchema is a named export from the graphql package, not a default one.
default
✓ import openapiToGraphql from 'openapi-to-graphql'
✗ import { default } from 'openapi-to-graphql'
The package has a default export that is the same as createGraphQLSchema. Use default import for convenience.
Generates a GraphQL schema from an OpenAPI spec and serves it via Express with GraphiQL.
import { createGraphQLSchema } from 'openapi-to-graphql';
import express from 'express';
import { graphqlHTTP } from 'express-graphql';
const oas = {
openapi: '3.0.0',
info: { title: 'Sample API', version: '1.0.0' },
paths: {
'/hello': {
get: {
operationId: 'hello',
responses: {
'200': {
description: 'OK',
content: { 'application/json': { schema: { type: 'string' } } }
}
}
}
}
}
};
async function main() {
const { schema } = await createGraphQLSchema(oas);
const app = express();
app.use('/graphql', graphqlHTTP({ schema, graphiql: true }));
app.listen(4000);
console.log('GraphQL server running at http://localhost:4000/graphql');
}
main();
Errors
Common errors & fixes
Cannot find module 'openapi-to-graphql'
Package not installed or missing in node_modules.
fixRun 'npm install openapi-to-graphql --save'
Cannot read properties of undefined (reading 'prototype')
Missing peer dependency graphql.
fixInstall graphql via 'npm install graphql'
graphql is not defined
graphql is not imported or installed when using the schema.
fixImport GraphQL.js: 'import { graphql, GraphQLSchema } from 'graphql'' Cannot find module 'express-graphql'
Missing express-graphql package when serving.
fixInstall it: 'npm install express-graphql --save'
Audit
Dependencies
graphqlrequiredPeer dependency required to generate GraphQL schema