Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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({
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
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
}));
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) {