{"id":47953,"library":"graphql-to-openapi","title":"GraphQL-to-OpenAPI","description":"Converts a GraphQL schema and query into an OpenAPI specification. Current stable version is 4.0.25, released regularly. Key differentiator: focuses on generating OpenAPI from a specific GraphQL query (not full schema), providing a targeted mapping. Includes CLI and programmatic API. Ships TypeScript types.","status":"active","version":"4.0.25","language":"javascript","source_language":"en","source_url":"https://github.com/schwer/graphql-to-openapi","tags":["javascript","graphql","openapi","typescript"],"install":[{"cmd":"npm install graphql-to-openapi","lang":"bash","label":"npm"},{"cmd":"yarn add graphql-to-openapi","lang":"bash","label":"yarn"},{"cmd":"pnpm add graphql-to-openapi","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package is ESM-only; named export, not default.","wrong":"const graphqlToOpenApi = require('graphql-to-openapi')","symbol":"graphqlToOpenApi","correct":"import { graphqlToOpenApi } from 'graphql-to-openapi'"},{"note":"graphqlToOpenApi is a named export, not the default.","wrong":"import graphqlToOpenApi from 'graphql-to-openapi'","symbol":"graphqlToOpenApi","correct":"import { graphqlToOpenApi } from 'graphql-to-openapi'"},{"note":"It's a type, use `import type` for TypeScript.","wrong":"import { GraphqlToOpenApiOptions } from 'graphql-to-openapi'","symbol":"GraphqlToOpenApiOptions","correct":"import type { GraphqlToOpenApiOptions } from 'graphql-to-openapi'"}],"quickstart":{"code":"import { graphqlToOpenApi } from 'graphql-to-openapi';\nimport { buildSchema } from 'graphql';\n\nconst schema = buildSchema(`\n  type Query {\n    hello: String\n  }\n`);\n\nconst query = `\n  query MyQuery {\n    hello\n  }\n`;\n\nconst { error, openApiSchema, queryErrors, schemaError } = graphqlToOpenApi({\n  schema,\n  query,\n});\n\nif (error) {\n  console.error('Error:', error);\n} else if (schemaError) {\n  console.error('Schema error:', schemaError);\n} else if (queryErrors.length > 0) {\n  console.error('Query errors:', queryErrors);\n} else {\n  console.log('OpenAPI schema:', JSON.stringify(openApiSchema, null, 2));\n}","lang":"typescript","description":"Shows programmatic usage: parse schema and query, convert to OpenAPI, handle errors."},"warnings":[{"fix":"Always provide a named operation (e.g., 'query MyQuery { ... }').","message":"The input query must be named; otherwise graphql-to-openapi throws an error.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use --scalarConfigFile to override types for custom scalars.","message":"Unknown scalar types default to 'string' in OpenAPI output without warning.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Add --yaml to CLI command if YAML output is desired.","message":"The CLI output is JSON by default; use --yaml flag for YAML.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"search_vec":"'4.0.25':19 'api':44 'cli':41 'convert':5 'current':15 'differenti':23 'focus':24 'full':34 'generat':26 'graphql':2,7,31,49 'graphql-to-openapi':1 'includ':40 'javascript':48 'key':22 'map':39 'openapi':4,13,27,50 'programmat':43 'provid':36 'queri':10,32 'regular':21 'releas':20 'schema':8,35 'ship':45 'specif':14,30 'stabl':16 'target':38 'type':47 'typescript':46,51 'version':17","created_at":"2026-06-07T16:54:10.614470+00:00","updated_at":"2026-06-07T16:54:10.614470+00:00","problems":[{"fix":"Add a name to the query, e.g., 'query MyQuery { ... }'.","cause":"The input query string does not specify a name for the operation.","error":"Error: GraphQL query must be named"},{"fix":"Ensure the schema is a valid GraphQL schema object (use buildSchema or similar).","cause":"The schema object passed is not valid or is undefined.","error":"TypeError: Cannot read properties of undefined (reading 'definitions')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/schwer/graphql-to-openapi#readme","github":"https://github.com/schwer/graphql-to-openapi","docs":null,"changelog":null,"pypi":null,"npm":"graphql-to-openapi","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}