Skip to content

Instantly share code, notes, and snippets.

@jancorg
Created January 15, 2020 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jancorg/4da593e3e6a5ad2a062b5abfa187e7d3 to your computer and use it in GitHub Desktop.
Save jancorg/4da593e3e6a5ad2a062b5abfa187e7d3 to your computer and use it in GitHub Desktop.
'use strict';
const modelList = [ 'oneModel',
'anotherModel' ]
let modelClasses = modelList.map((c,i,a) => require(`../models/${c}`))
// let datetime = require('../lib/graphQl-dateTime')
const graphql = require('graphql').graphql
const graphQlBuilder = require('objection-graphql').builder
const graphQlSchema = graphQlBuilder().allModels(modelClasses)
.build()
module.exports.graphQl = async (event) => {
let query = JSON.parse(event.body)
let result = graphql(graphQlSchema, query )
.catch(e => undefined)
return {
statusCode: result == undefined ? 404 : 200,
body: JSON.stringify(result)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment