Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
document = cached.document
}
if (reply && reply.request.raw.method === 'GET') {
// let's validate we cannot do mutations here
const operationAST = getOperationAST(document, operationName)
if (operationAST.operation !== 'query') {
const err = new MethodNotAllowed()
err.errors = [new Error('Operation cannot be perfomed via a GET request')]
throw err
}
}
// minJit is 0 by default
if (cached && cached.count++ === minJit) {
cached.jit = compileQuery(schema, document, operationName)
}
if (cached && cached.jit !== null) {
const res = await cached.jit.query(root, context, variables || {})
return res
}
const execution = await execute(
schema,
document,
root,
context,
variables,
operationName
)
if (execution.errors) {
// TODO
// DANGEROUS
// UNSAFE
// Never save user's query.
// This is only for demonstration
const resolvers = new Function(...args, body).call({});
const execSchema = makeExecutableSchema({
typeDefs: schema,
resolvers
});
const compileStart = performance.now();
const compiledQuery = compileQuery(execSchema, parse(query), undefined, {debug: true} as any);
if (!isCompiledQuery(compiledQuery)) {
return {
compiledQuery: "",
executionResult: JSON.stringify(compiledQuery, null, 2)
};
}
const compileTime = performance.now() - compileStart;
const execStart = performance.now();
const executionResult = await compiledQuery.query({}, {}, {});
const executeTime = performance.now() - execStart;
return {
compiledQuery: prettier.format((compiledQuery as any).__DO_NOT_USE_THIS_OR_YOU_WILL_BE_FIRED_compilation,
{ parser: "babel", plugins: [babylonParser], printWidth: 80 }
),
// TODO
// DANGEROUS
// UNSAFE
// Never save user's query.
// This is only for demonstration
const resolvers = new Function(...args, body).call({});
const execSchema = makeExecutableSchema({
typeDefs: schema,
resolvers
});
const compileStart = performance.now();
const compiledQuery = compileQuery(execSchema, parse(query), undefined, {debug: true} as any);
if (!isCompiledQuery(compiledQuery)) {
return {
compiledQuery: "",
executionResult: JSON.stringify(compiledQuery, null, 2)
};
}
const compileTime = performance.now() - compileStart;
const execStart = performance.now();
const executionResult = await compiledQuery.query({}, {}, {});
const executeTime = performance.now() - execStart;
return {
compiledQuery: prettier.format((compiledQuery as any).__DO_NOT_USE_THIS_OR_YOU_WILL_BE_FIRED_compilation,
{ parser: "babel", plugins: [babylonParser], printWidth: 80 }
),
executionResult: JSON.stringify(