zalando-incubator / graphql-jit

GraphQL execution using a JIT compiler
https://try-graphql-jit.boopathi.in/
Other
1.05k stars 57 forks source link

Error: Must provide Source. Received: null on using grpahql-jit0.4.2 #87

Open chopraapooja opened 4 years ago

chopraapooja commented 4 years ago

After adding grapqhql-jit to running express-graphql it started giving above error. I am using Peer Dependency graphql version 14.6.0

chopraapooja commented 4 years ago


const express = require('express')
const graphqlHTTP = require('express-graphql')
const bodyParser = require('body-parser')
const { createSchema } = require('./OTG');
const cors = require('cors');
const { compileQuery } = require("graphql-jit");
const { parse } = require('graphql');

// TODO: use better cache with invalidation 
const cache = {};

async function startServer() {
  const schema = await createSchema();
  const app = express()
  app.use(bodyParser.json())
  app.use(cors());

  app.use('/', graphqlHTTP((_, __, { query }) => {
    if (!(query in cache)) {
      const document = parse(query);
      cache[query] = compileQuery(schema, document);
    }

    return {
      graphiql: true,
      schema,
      customExecuteFn: ({ rootValue, variableValues, contextValue }) => {
        return cache[query].query(rootValue, contextValue, variableValues);
      }
    }

  }))

  app.listen(8080, () => {
    console.log(`Access graphql at http://localhost:8080`);
  })
}

// Kick things off:
startServer()```