<commit_before>import {graphql} from 'graphql';

import todoSchema from './graphql/schema';

function handlePost(req, res) {
  graphql(todoSchema, req.body).then((result) => {
    res.send(result);
  });
}

export default (app) => {
  app.post('/api', handlePost)
};<commit_msg>Add basic Auth token presence check<commit_after>import {graphql} from 'graphql';

import todoSchema from './graphql/schema';

function ensureAuthTokenPresent(req, res, next) {
	const authToken = req.get('Auth');
	if(authToken && authToken.length) {
		req.authToken = authToken;
		return next();
	}
	return res.status(403).json({ error: 'Auth token not found in request' });
}

function handlePost(req, res) {
	const context = { authToken: req.authToken }
	const query = req.body;
  graphql(todoSchema, query, context).then((result) => {
    res.send(result);
  });
}

export default (app) => {
  app.post('/api', ensureAuthTokenPresent, handlePost)
};
{'fraction_non_alphanumeric': 0.16021505376344086, 'fraction_numerical': 0.0032258064516129032, 'mean_word_length': 4.81875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '61684', 'n_tokens_mistral': 310, 'n_tokens_neox': 305, 'n_words': 74}