Skip to content

Commit

Permalink
pr fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Assaf Milman authored and Assaf Milman committed Dec 5, 2016
1 parent 6ac351c commit 9ec76af
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/directives/date.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import { GraphQLString, GraphQLBoolean } from 'graphql';
import { DirectiveLocation } from 'graphql/type/directives';
import { GraphQLCustomDirective } from '../custom';
import { _ } from 'lodash';

const moment = require('moment');

const DEFAULT_DATE_FORMAT = 'DD MMM YYYY HH:mm';

const extractOffset = (context, offsetLocation) => {
let tempContext = Object.assign({}, context);
for (let path of offsetLocation.split('.')){
tempContext = tempContext[path];
}
return tempContext;
}

exports.GraphQLDateDirective = new GraphQLCustomDirective({
name: 'date',
description:
Expand Down Expand Up @@ -52,17 +45,16 @@ exports.GraphQLDateDirective = new GraphQLCustomDirective({

exports.GraphQLTimeOffsetDirective = new GraphQLCustomDirective({
name: 'timeOffset',
description: 'Format the date from resolving the field by moment module',
description: 'Add offset (in minutes) to a 13 digit unixtime',
locations: [DirectiveLocation.FIELD],
args: {
offsetLocation: {
type: GraphQLString,
description: 'Path of offset in context object. e.g - "req.shop.utcOffset"'
description: 'Path of offset in minutes within context object. e.g - "req.profile.utcOffset"'
}
},
resolve: function resolve(_resolve, source, _ref, context, info) {
var offsetLocation = _ref.offsetLocation;
var offsetMinutes = extractOffset(context, offsetLocation);
var offsetMinutes = _.get(context, _ref.offsetLocation);
var offsetMilliseconds = offsetMinutes * 60 * 1000;

return _resolve().then(function (input) {
Expand Down

0 comments on commit 9ec76af

Please sign in to comment.