Skip to content

Instantly share code, notes, and snippets.

View vraj291's full-sized avatar
🎯
Focusing

Vraj Parikh vraj291

🎯
Focusing
View GitHub Profile
const { GraphQLScalarType } = require('graphql');
const dateScalar = new GraphQLScalarType({
name: 'Date',
parseValue(value) {
return new Date(value);
},
serialize(value) {
return value.toString();
},
@vraj291
vraj291 / CreatePost.js
Created August 23, 2021 08:04
GraphQL-Social Create Post
import { useMutation } from '@apollo/react-hooks'
import React, { useContext, useState } from 'react'
import { CREATE_POST } from '../queries/PostQuery'
import {useHistory} from 'react-router-dom'
import { AuthContext } from '../context/auth'
export const CreatePost = () => {
const {user} = useContext(AuthContext)
const history = useHistory()
@vraj291
vraj291 / Home.js
Created August 23, 2021 08:02
GraphQL-Social Home Component
import { useQuery } from '@apollo/react-hooks'
import React from 'react'
import { Post } from '../components/Post'
import { GET_POSTS } from '../queries/PostQuery'
export const Home = () => {
const {loading, error, data} = useQuery(GET_POSTS,{
pollInterval: 500
@vraj291
vraj291 / postQuery.js
Created August 23, 2021 07:59
GraphQL-Social Post Client Queries
import { gql } from 'apollo-boost';
export const GET_POSTS = gql`
{
getPosts{
id
userName
createdAt
text
likeCount
@vraj291
vraj291 / server.js
Created August 23, 2021 07:39
GraphQL-Social Server
const {ApolloServer} = require('apollo-server')
const {typeDefs} = require('./schema/index.js')
const {resolvers} = require('./resolvers/index.js')
const mongoose = require('mongoose')
const config = require('../config.js')
const server = new ApolloServer({
typeDefs,
resolvers
})
@vraj291
vraj291 / index.js
Created August 23, 2021 07:33
GraphQL-Social Schema
const {gql} = require('apollo-server')
const typeDefs = gql`
scalar Date
type Post{
id: ID!
userName: String!
createdAt: Date!