daily pastebin goal
51%
SHARE
TWEET

Untitled

a guest Sep 18th, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Mutation: {
  2.   addPost: async (parent, args) => {
  3.     // Add new post to dbPosts
  4.     const task = fawn.Task();
  5.     task.save(
  6.       dbPost,
  7.       {
  8.         _id: new mongoose.Types.ObjectId(),
  9.         title: args.title,
  10.         content: args.content,
  11.         created: args.created,
  12.         author: {
  13.           id: args.author_id,
  14.           first_name: args.author_first_name,
  15.           last_name: args.author_last_name,
  16.         }
  17.       }
  18.     );
  19.   }
  20. }
  21.    
  22. scalar DateTime
  23.  
  24. type Query {
  25.   posts: [Post],
  26.   post(id: ID!): Post,
  27. }
  28.  
  29. type Mutation {
  30.   addPost(
  31.     title: String!,
  32.     content: String!,
  33.     created: DateTime!,
  34.     author_id: String!,
  35.     author_first_name: String!
  36.      author_last_name: String!): Post,
  37. }
  38.  
  39. type Post {
  40.   id: ID!
  41.   title: String!,
  42.   content: String!,
  43.   author: Author!,
  44.   created: DateTime,
  45. }
  46.    
  47. const { GraphQLScalarType } = require('graphql/type');
  48.  
  49. const tmUTC = () => {
  50.   const tmLoc = new Date();
  51.   return tmLoc.getTime() + tmLoc.getTimezoneOffset() * 60000;
  52. };
  53.  
  54. DateTime = new GraphQLScalarType({
  55.   name: 'DateTime',
  56.   description: 'Date/Time custom scalar type',
  57.   parseValue: () => { // runs on mutation
  58.     return tmUTC();
  59.   },
  60.   serialize: (value) => { // runs on query
  61.     return new Date(value.getTime());
  62.   },
  63.   parseLiteral: () => {
  64.     return tmUTC();
  65.   },
  66. });
  67.  
  68. module.exports = DateTime;
  69.    
  70. mutation{
  71.   addPost(
  72.     title: "Ghostbusters",
  73.     content: "Lots and lots of ghosts here...",
  74.     created: "",
  75.     author_id: "5ba0c2491c9d440000ac8fc3",
  76.     author_first_name: "Bill",
  77.     author_last_name: "Murray"
  78.   ){
  79.     title
  80.     content
  81.     id
  82.     created
  83.   }
  84. }
  85.    
  86. type Mutation {
  87.   addPost(
  88.     title: String!,
  89.     content: String!,
  90.     // created: DateTime!, changed in next line
  91.     created: DateTime, // no ! means not required
  92.     author_id: String!,
  93.     author_first_name: String!
  94.      author_last_name: String!): Post,
  95. }
  96.    
  97. addPost: async (parent, args) => {
  98.     // if args does not have created, make it here
  99.     const task = fawn.Task();
  100.     task.save(
  101.       dbPost,
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top