How to use openapi-to-graphql - 4 common examples

To help you get started, we’ve selected a few openapi-to-graphql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github IBM / openapi-to-graphql / packages / openapi-to-graphql-cli / src / openapi-to-graphql.ts View on Github external
function startGraphQLServer(
  oas: Oas3 | Oas2 | (Oas3 | Oas2)[],
  options: Options,
  port: number
): void {
  // Create GraphQL interface
  createGraphQlSchema(oas, options)
    .then(({ schema, report }) => {
      console.log(JSON.stringify(report, null, 2))

      // Save local file if required
      if (program.save) {
        writeSchema(schema)
      } else {
        // Enable CORS
        if (program.cors) {
          app.use(cors())
        }

        // Mounting graphql endpoint using the middleware express-graphql
        app.use(
          '/graphql',
          graphqlHTTP({
github IBM / openapi-to-graphql / packages / openapi-to-graphql-cli / lib / openapi-to-graphql.js View on Github external
function startGraphQLServer(oas, port) {
    // Create GraphQL interface
    openapi_to_graphql_1.createGraphQlSchema(oas, {
        strict: program.strict,
        // Resolver options
        baseUrl: program.url,
        // Schema options
        operationIdFieldNames: program.operationIdFieldNames,
        fillEmptyResponses: program.fillEmptyResponses,
        addLimitArgument: program.addLimitArgument,
        // Authentication options
        viewer: program.viewer,
        // Logging options
        provideErrorExtensions: program.extensions,
        equivalentToMessages: program.equivalentToMessages
    })
        .then(({ schema, report }) => {
        console.log(JSON.stringify(report, null, 2));
        // Save local file if required
github IBM / openapi-to-graphql / packages / openapi-to-graphql-cli / lib / openapi-to-graphql.js View on Github external
function startGraphQLServer(oas, options, port) {
    // Create GraphQL interface
    openapi_to_graphql_1.createGraphQlSchema(oas, options)
        .then(({ schema, report }) => {
        console.log(JSON.stringify(report, null, 2));
        // Save local file if required
        if (program.save) {
            writeSchema(schema);
        }
        else {
            // Enable CORS
            if (program.cors) {
                app.use(cors());
            }
            // Mounting graphql endpoint using the middleware express-graphql
            app.use('/graphql', graphqlHTTP({
                schema: schema,
                graphiql: true
            }));
github aerogear / graphback / packages / graphback-cli / src / helpers / transformOpenApiSpec.ts View on Github external
async function processSingleDefinition(model: string, isYaml: boolean, openApiConfig: OpenApiConfig) {
    logInfo(`   Processing OpenAPI definition: ${model}`);
    const schemaText: string = readFileSync(`${model}`, 'utf8');
    let parsedObject;
    if (isYaml) {
        parsedObject = safeLoad(schemaText);
    } else {
        parsedObject = JSON.parse(schemaText);
    }
    try {
        let { schema } = await createGraphQlSchema(parsedObject, {
            strict: true,
            fillEmptyResponses: true,
            equivalentToMessages: false,

        });
        if (!openApiConfig.includeComments) {
            schema = removeCommentsFromSchema(schema)
        }
        if (!openApiConfig.includeQueriesAndMutations) {
            schema = removeOperationsFromSchema(schema);
        }

        const schemaString = printSchema(schema);

        writeFileSync(`${model}.graphql`, schemaString);
        if (!openApiConfig.reuseOpenAPIModel) {

openapi-to-graphql

Generates a GraphQL schema for a given OpenAPI Specification (OAS)

MIT
Latest version published 10 months ago

Package Health Score

60 / 100
Full package analysis

Popular openapi-to-graphql functions