Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default async function printSchemaFromIntrospectionResult(
schemaPath: string,
outputPath: string,
options?: PrinterOptions
) {
if (!fs.existsSync(schemaPath)) {
throw new ToolError(`Cannot find GraphQL schema file: ${schemaPath}`);
}
const schemaJSON = JSON.parse(fs.readFileSync(schemaPath, 'utf8'));
if (!schemaJSON.data) {
throw new ToolError(`No introspection query result data found in: ${schemaPath}`);
}
const schema = buildClientSchema(schemaJSON.data);
const schemaIDL = printSchema(schema, options);
if (outputPath) {
fs.writeFileSync(outputPath, schemaIDL);
} else {
console.log(schemaIDL);
}
}
body: JSON.stringify({ 'query': introspectionQuery }),
agent,
});
result = await response.json();
} catch (error) {
throw new ToolError(`Error while fetching introspection query result: ${error.message}`);
}
if (result.errors) {
throw new ToolError(`Errors in introspection query result: ${result.errors}`);
}
const schemaData = result;
if (!schemaData.data) {
throw new ToolError(`No introspection query result data found, server responded with: ${JSON.stringify(result)}`);
}
fs.writeFileSync(outputPath, JSON.stringify(schemaData, null, 2));
}
.fail(function(message, error) {
handleError(error ? error : new ToolError(message));
})
.help()
export default async function introspectSchema(schemaPath: string, outputPath: string) {
if (!fs.existsSync(schemaPath)) {
throw new ToolError(`Cannot find GraphQL schema file: ${schemaPath}`);
}
const schemaContents = fs.readFileSync(schemaPath).toString();
const result = await introspect(schemaContents);
if (result.errors) {
throw new ToolError(`Errors in introspection query result: ${result.errors}`);
}
fs.writeFileSync(outputPath, JSON.stringify(result, null, 2));
}
coerce: (arg) => {
let additionalHeaders: {
[key: string]: any
} = {};
for (const header of arg) {
const separator = header.indexOf(":");
const name = header.substring(0, separator).trim();
const value = header.substring(separator + 1).trim();
if (!(name && value)) {
throw new ToolError('Headers should be specified as "Name: Value"');
}
additionalHeaders[name] = value;
}
return additionalHeaders;
}
},