{"size": 1120, "ext": "js", "max_stars_repo_path": "schema/backendmutation/FeedbackMutation.js", "max_stars_repo_name": "Ricky-Nz/knocknock-server", "max_stars_repo_stars_event_min_datetime": "2016-05-17T16:09:53.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-18T22:17:52.000Z", "max_issues_repo_path": "schema/backendmutation/FeedbackMutation.js", "max_issues_repo_name": "Ricky-Nz/knocknock-server", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "schema/backendmutation/FeedbackMutation.js", "max_forks_repo_name": "Ricky-Nz/knocknock-server", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 21.1320754717, "max_line_length": 86, "alphanum_fraction": 0.6455357143}
import { GraphQLBoolean, GraphQLNonNull, GraphQLString, GraphQLFloat } from 'graphql';
import { mutationWithClientMutationId, offsetToCursor } from 'graphql-relay';
import { GraphQLViewer, GraphQLFeedbackEdge } from '../query';
import { UserFeedbacks } from '../../service/database';

// id      
// user_id     
// rating      
// comment     
// created

const createFeedback = mutationWithClientMutationId({
	name: 'CreateFeedback',
	inputFields: {
    userId: {
      type: new GraphQLNonNull(GraphQLString)
    },
    rating: {
      type: new GraphQLNonNull(GraphQLFloat)
    },
    comment: {
      type: GraphQLString
    }
	},
	outputFields: {
		feedbackEdge: {
			type: GraphQLFeedbackEdge,
			resolve: (feedback) => ({
				cursor: offsetToCursor(0),
				node: feedback
			})
		},
		viewer: {
			type: GraphQLViewer,
			resolve: () => ({})
		}
	},
	mutateAndGetPayload: ({userId, rating, comment}) => {
		const {id: localId} = fromGlobalId(userId);

		return UserFeedbacks.create({
			user_id: localId,
			rating,
			comment,
			created: new Date().toString()
		});
	}
});

export default {
	createFeedback
};
