Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function fromFile(
file: string
): Promise {
let result;
try {
result = fs.readFileSync(file, {
encoding: "utf-8"
});
} catch (err) {
throw new Error(`Unable to read file ${file}. ${err.message}`);
}
const ext = path.extname(file);
// an actual introspectionQuery result
if (ext === ".json") {
const parsed = JSON.parse(result);
const schemaData = parsed.data
? parsed.data.__schema
: parsed.__schema
? parsed.__schema
: parsed;
file: string,
defaultEndpoint: boolean,
defaultSchema: boolean
): ApolloConfig {
if (file.endsWith(".js")) {
const filepath = resolve(file);
delete require.cache[require.resolve(filepath)];
return loadConfig(
require(filepath),
filepath,
dirname(filepath),
defaultEndpoint,
defaultSchema
);
} else if (file.endsWith("package.json")) {
const apolloKey = JSON.parse(fs.readFileSync(file).toString()).apollo;
if (apolloKey) {
return loadConfig(
apolloKey,
file,
dirname(file),
defaultEndpoint,
defaultSchema
);
} else {
return loadConfig(
{},
file,
dirname(file),
defaultEndpoint,
defaultSchema
);