How to use the graphql-jit.compileQuery function in graphql-jit

To help you get started, we’ve selected a few graphql-jit 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 mcollina / fastify-gql / index.js View on Github external
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) {
github boopathi / try-graphql-jit / src / worker.ts View on Github external
// 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 }
      ),

graphql-jit

GraphQL JIT Compiler to JS

MIT
Latest version published 2 months ago

Package Health Score

87 / 100
Full package analysis

Similar packages