<commit_before>const Koa = require('koa')
const onerror = require('koa-onerror')
const logger = require('koa-logger')
const bodyParser = require('koa-bodyparser')
const cors = require('kcors')
const Router = require('koa-router')
const static = require('koa-static')
const { graphqlKoa, graphiqlKoa } = require('graphql-server-koa')
const { apolloUploadKoa } = require('apollo-upload-server')
const schema = require('./schema')
const { user, post, video, img, userPosts, userVideos, userImgs } = require('./dataloader')

const ENV = process.env.NODE_ENV
const app = new Koa()
const router = new Router()

app.use(cors())
onerror(app)
if (process.env.NODE_ENV !== 'test') {
  app.use(logger())
}

app.use(static('static'))

// app.use(bodyParser({
//   enableTypes: ['json', 'text', 'form'],
//   extendTypes: {
//     text: ['application/graphql']
//   }
// }))

const mws = [
  bodyParser({
    enableTypes: ['json', 'text', 'form'],
    extendTypes: {
      text: ['application/graphql'],
      json: ['application/json']
    }
  }),
  async (ctx, next) => {
    if (ctx.request.is('application/graphql')) {
      ctx.request.body = { query: ctx.request.body }
    }
    console.log(ctx.request.body)
    await next()
  },
  apolloUploadKoa({
    uploadDir: './static/imgs'
  })
]

router.post(
  '/graphql',
  ...mws,
  graphqlKoa({<commit_msg>tweak<commit_after>const Koa = require('koa')
const onerror = require('koa-onerror')
const logger = require('koa-logger')
const bodyParser = require('koa-bodyparser')
const cors = require('kcors')
const Router = require('koa-router')
const static = require('koa-static')
const { graphqlKoa, graphiqlKoa } = require('graphql-server-koa')
const { apolloUploadKoa } = require('apollo-upload-server')
const schema = require('./schema')
const { user, post, video, img, userPosts, userVideos, userImgs } = require('./dataloader')

const ENV = process.env.NODE_ENV
const app = new Koa()
const router = new Router()

app.use(cors())
onerror(app)
if (process.env.NODE_ENV !== 'test') {
  app.use(logger())
}

app.use(static('static'))

app.use(bodyParser({
  enableTypes: ['json', 'text', 'form'],
  extendTypes: {
    text: ['application/graphql'],
    json: ['application/json']
  }
}))

const mws = [
  async (ctx, next) => {
    if (ctx.request.is('application/graphql')) {
      ctx.request.body = { query: ctx.request.body }
    }
    await next()
  },
  apolloUploadKoa({
    uploadDir: './static/imgs'
  })
]

router.post(
  '/graphql',
  ...mws,
  graphqlKoa({
{'fraction_non_alphanumeric': 0.18627842042281612, 'fraction_numerical': 0.0, 'mean_word_length': 3.9860834990059644, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6555101', 'n_tokens_mistral': 892, 'n_tokens_neox': 885, 'n_words': 182}