Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const graphql = require('graphql');
- const tablesFactory = require('./dynamodb/tables');
- const MoistureService = require('./services/moisture');
- const tables = tablesFactory();
- const moistureService = MoistureService({ moistureTable: tables.Moisture });
- const MoistureType = new graphql.GraphQLObjectType({
- name: 'MoistureType',
- fields: {
- date: { type: graphql.GraphQLString },
- moisture: { type: graphql.GraphQLFloat },
- }
- });
- const schema = new graphql.GraphQLSchema({
- query: new graphql.GraphQLObjectType({
- name: 'Root',
- description: 'Root of the Schema',
- fields: {
- moisture:
- name: 'MoistureQuery',
- description: 'Retrieve moisture levels',
- type: new graphql.GraphQLList(MoistureType),
- args: {
- clientId: {
- type: graphql.GraphQLString,
- },
- hours: {
- type: graphql.GraphQLInt,
- defaultValue: 1
- },
- },
- resolve: (_, args, ast) => {
- const hours = args.hours > 0 ? args.hours : 1;
- return moistureService.getLastHours(args.clientId, hours);
- }
- }
- }
- })
- });
- module.exports.handler = function(event, context, cb) {
- console.log('Received event', event);
- const query = event.body.query;
- return graphql.query(event.body.query)
- .then((response) => {
- cb(null, response)
- })
- .catch((error) => {
- cb(error)
- });
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement