Removed commented code
This commit is contained in:
@@ -1,12 +1,10 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Header from './layout/Header';
|
import Header from './layout/Header';
|
||||||
import Login from './Login';
|
|
||||||
import AppointmentList from './appointment/AppointmentList';
|
import AppointmentList from './appointment/AppointmentList';
|
||||||
import CreateAppointment from './appointment/CreateAppointment';
|
import CreateAppointment from './appointment/CreateAppointment';
|
||||||
import UpdateAppointemnt from './appointment/UpdateAppointment';
|
import UpdateAppointemnt from './appointment/UpdateAppointment';
|
||||||
import Calendar from './Calendar';
|
import Calendar from './Calendar';
|
||||||
import { Switch, Route } from 'react-router-dom';
|
import { Switch, Route } from 'react-router-dom';
|
||||||
// import ProductList from './ProductList';
|
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
return (
|
return (
|
||||||
@@ -14,11 +12,9 @@ const App = () => {
|
|||||||
<Header />
|
<Header />
|
||||||
<div className="ph3 pv1 background-gray">
|
<div className="ph3 pv1 background-gray">
|
||||||
<Switch>
|
<Switch>
|
||||||
{/* <Route exact path="/" component={ProductList} /> */}
|
|
||||||
<Route exact path="/" component={AppointmentList} />
|
<Route exact path="/" component={AppointmentList} />
|
||||||
<Route exact path="/create" component={CreateAppointment} />
|
<Route exact path="/create" component={CreateAppointment} />
|
||||||
<Route exact path="/update/:_id" component={UpdateAppointemnt} />
|
<Route exact path="/update/:_id" component={UpdateAppointemnt} />
|
||||||
<Route exact path="/login" component={Login} />
|
|
||||||
<Route exact path="/calendar" component={Calendar} />
|
<Route exact path="/calendar" component={Calendar} />
|
||||||
</Switch>
|
</Switch>
|
||||||
</div>
|
</div>
|
||||||
@@ -27,42 +23,3 @@ const App = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default App;
|
export default App;
|
||||||
|
|
||||||
|
|
||||||
// // import logo from './../logo.svg';
|
|
||||||
// // import './../styles/App.css';
|
|
||||||
|
|
||||||
// import React, { Component } from 'react';
|
|
||||||
// import AppointmentList from './AppointmentList';
|
|
||||||
// import CreateAppointment from './CreateAppointment'
|
|
||||||
// // import Header from './Header';
|
|
||||||
// import Login from './Login'
|
|
||||||
// import Search from './Search';
|
|
||||||
// import { Redirect, Route, Switch } from 'react-router-dom';
|
|
||||||
|
|
||||||
// const App = () => {
|
|
||||||
// return (
|
|
||||||
// <div className="center w85">
|
|
||||||
// <Header />
|
|
||||||
// <div className="ph3 pv1 background-gray">
|
|
||||||
// <Switch>
|
|
||||||
// <Route exact path="/" component={AppointmentList} />
|
|
||||||
// <Route
|
|
||||||
// exact
|
|
||||||
// path="/create"
|
|
||||||
// component={CreateAppointment}
|
|
||||||
// />
|
|
||||||
// <Route exact path="/login" component={Login} />
|
|
||||||
// <Route exact path="/search" component={Search} />
|
|
||||||
// <Route
|
|
||||||
// exact
|
|
||||||
// path="/new/:page"
|
|
||||||
// component={AppointmentList}
|
|
||||||
// />
|
|
||||||
// </Switch>
|
|
||||||
// </div>
|
|
||||||
// </div>
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
|
|
||||||
// export default App;
|
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { useMutation } from '@apollo/client';
|
|
||||||
import { useLazyQuery } from '@apollo/client';
|
import { useLazyQuery } from '@apollo/client';
|
||||||
import gql from 'graphql-tag';
|
import gql from 'graphql-tag';
|
||||||
import Appointment from './Appointment';
|
|
||||||
import { Link } from 'react-router-dom';
|
|
||||||
|
|
||||||
const FEED_SEARCH_QUERY = gql`
|
const FEED_SEARCH_QUERY = gql`
|
||||||
query FeedSearchQuery($filter: String!) {
|
query FeedSearchQuery($filter: String!) {
|
||||||
@@ -18,12 +15,6 @@ const FEED_SEARCH_QUERY = gql`
|
|||||||
id
|
id
|
||||||
username
|
username
|
||||||
}
|
}
|
||||||
# follows {
|
|
||||||
# id
|
|
||||||
# user {
|
|
||||||
# id
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,10 +43,6 @@ const Search = () => {
|
|||||||
OK
|
OK
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{/* {data &&
|
|
||||||
data.feed.appointments.map((appointment, index) => (
|
|
||||||
<Link key={appointment.id} link={appointment} index={index} />
|
|
||||||
))} */}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -36,100 +36,3 @@ const Appointment = (props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default Appointment;
|
export default Appointment;
|
||||||
|
|
||||||
// import { AUTH_TOKEN, APPOINTMENTS_PER_PAGE } from '../constants';
|
|
||||||
// import { timeDifferenceForDate } from '../utils'
|
|
||||||
// import { FEED_QUERY } from './AppointmentList'
|
|
||||||
|
|
||||||
// const FOLLOW_MUTATION = gql`
|
|
||||||
// mutation FollowMutation($appointmentId: ID!) {
|
|
||||||
// follow(followId: $followId) {
|
|
||||||
// id
|
|
||||||
// appointment {
|
|
||||||
// id
|
|
||||||
// follows {
|
|
||||||
// id
|
|
||||||
// user {
|
|
||||||
// id
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// user {
|
|
||||||
// id
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// `;
|
|
||||||
|
|
||||||
// const take = APPOINTMENTS_PER_PAGE;
|
|
||||||
// const skip = 0;
|
|
||||||
// const orderBy = { createdAt: 'desc' };
|
|
||||||
|
|
||||||
// const Appointment = (props) => {
|
|
||||||
// const { appointment } = props;
|
|
||||||
// const authToken = localStorage.getItem(AUTH_TOKEN);
|
|
||||||
// const take = APPOINTMENTS_PER_PAGE;
|
|
||||||
// const skip = 0;
|
|
||||||
// const orderBy = { createdAt: 'desc' };
|
|
||||||
|
|
||||||
// const [follow] = useMutation(FOLLOW_MUTATION, {
|
|
||||||
// variables: {
|
|
||||||
// appointmentId: appointment.id
|
|
||||||
// },
|
|
||||||
// update(cache, { data: { follow } }) {
|
|
||||||
// const { feed } = cache.readQuery({
|
|
||||||
// query: FEED_QUERY
|
|
||||||
// });
|
|
||||||
|
|
||||||
// const updatedAppointments = feed.follows.map((feedFollow) => {
|
|
||||||
// if (feedFollow.id === appointment.id) {
|
|
||||||
// return {
|
|
||||||
// ...feedFollow,
|
|
||||||
// follows: [...feedFollow.follows, follow]
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
// return feedFollow;
|
|
||||||
// });
|
|
||||||
|
|
||||||
// cache.writeQuery({
|
|
||||||
// query: FEED_QUERY,
|
|
||||||
// data: {
|
|
||||||
// feed: {
|
|
||||||
// appointments: updatedAppointments
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// return (
|
|
||||||
// <div className="flex mt2 items-start">
|
|
||||||
// <div className="flex items-center">
|
|
||||||
// <span className="gray">{props.index + 1}.</span>
|
|
||||||
// {authToken && (
|
|
||||||
// <div
|
|
||||||
// className="ml1 gray f11"
|
|
||||||
// style={{ cursor: 'pointer' }}
|
|
||||||
// onClick={follow}
|
|
||||||
// >
|
|
||||||
// ▲
|
|
||||||
// </div>
|
|
||||||
// )}
|
|
||||||
// </div>
|
|
||||||
// <div className="ml1">
|
|
||||||
// <div>
|
|
||||||
// {appointment.title} ({appointment.description})
|
|
||||||
// </div>
|
|
||||||
// {authToken && (
|
|
||||||
// <div className="f6 lh-copy gray">
|
|
||||||
// {appointment.follows.length} follows | by{' '}
|
|
||||||
// {follow.createdBy ? follow.createdBy.name : 'Unknown'}{' '}
|
|
||||||
// {timeDifferenceForDate(appointment.createdAt)}
|
|
||||||
// </div>
|
|
||||||
// )}
|
|
||||||
// </div>
|
|
||||||
// </div>
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
|
|
||||||
// export default Appointment;
|
|
||||||
@@ -39,175 +39,3 @@ const AppointmentList = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default AppointmentList;
|
export default AppointmentList;
|
||||||
|
|
||||||
// import { useHistory } from 'react-router';
|
|
||||||
// import { APPOINTMENTS_PER_PAGE } from '../constants';
|
|
||||||
// import { Link } from 'react-router-dom';
|
|
||||||
|
|
||||||
// export const FEED_QUERY = gql`
|
|
||||||
// query AppointmentManyQuery(
|
|
||||||
// $take: Int
|
|
||||||
// $skip: Int
|
|
||||||
// $orderBy: AppointmentOrderByInput
|
|
||||||
// ) {
|
|
||||||
// appointmentMany(take: $take, skip: $skip, orderBy: $orderBy) {
|
|
||||||
// id
|
|
||||||
// appointments {
|
|
||||||
// id
|
|
||||||
// createdAt
|
|
||||||
// title
|
|
||||||
// # start
|
|
||||||
// # end
|
|
||||||
// description
|
|
||||||
// # createdBy {
|
|
||||||
// # id
|
|
||||||
// # name
|
|
||||||
// # }
|
|
||||||
// # follows {
|
|
||||||
// # id
|
|
||||||
// # user {
|
|
||||||
// # id
|
|
||||||
// # }
|
|
||||||
// # }
|
|
||||||
// }
|
|
||||||
// count
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// `;
|
|
||||||
|
|
||||||
// // const NEW_APPOINTMENTS_SUBSCRIPTION = gql`
|
|
||||||
// // subscription {
|
|
||||||
// // newAppointment {
|
|
||||||
// // id
|
|
||||||
// // url
|
|
||||||
// // description
|
|
||||||
// // createdAt
|
|
||||||
// // createdBy {
|
|
||||||
// // id
|
|
||||||
// // name
|
|
||||||
// // }
|
|
||||||
// // follows {
|
|
||||||
// // id
|
|
||||||
// // user {
|
|
||||||
// // id
|
|
||||||
// // }
|
|
||||||
// // }
|
|
||||||
// // }
|
|
||||||
// // }
|
|
||||||
// // `;
|
|
||||||
|
|
||||||
// const getQueryVariables = (isNewPage, page) => {
|
|
||||||
// const skip = isNewPage ? (page - 1) * APPOINTMENTS_PER_PAGE : 0;
|
|
||||||
// const take = isNewPage ? APPOINTMENTS_PER_PAGE : 100;
|
|
||||||
// const orderBy = { createdAt: 'desc' };
|
|
||||||
|
|
||||||
// return { take, skip, orderBy };
|
|
||||||
// };
|
|
||||||
|
|
||||||
// const AppointmentList = () => {
|
|
||||||
// const history = useHistory();
|
|
||||||
// const isNewPage = history.location.pathname.includes(
|
|
||||||
// 'new'
|
|
||||||
// );
|
|
||||||
// const pageIndexParams = history.location.pathname.split(
|
|
||||||
// '/'
|
|
||||||
// );
|
|
||||||
|
|
||||||
// const page = parseInt(
|
|
||||||
// pageIndexParams[pageIndexParams.length - 1]
|
|
||||||
// );
|
|
||||||
|
|
||||||
// const pageIndex = page ? (page - 1) * APPOINTMENTS_PER_PAGE : 0;
|
|
||||||
|
|
||||||
// const {
|
|
||||||
// data,
|
|
||||||
// loading,
|
|
||||||
// error,
|
|
||||||
// subscribeToMore
|
|
||||||
// } = useQuery(FEED_QUERY, {
|
|
||||||
// variables: getQueryVariables(isNewPage, page)
|
|
||||||
// });
|
|
||||||
|
|
||||||
// // const { data } = useQuery(FEED_QUERY);
|
|
||||||
|
|
||||||
// const getAppointmentsToRender = (isNewPage, data) => {
|
|
||||||
// if (isNewPage) {
|
|
||||||
// return data.feed.appointments;
|
|
||||||
// }
|
|
||||||
// const rankedAppointments = data.feed.appointments.slice();
|
|
||||||
// rankedAppointments.sort(
|
|
||||||
// (l1, l2) => l2.follows.length - l1.follows.length
|
|
||||||
// );
|
|
||||||
// return rankedAppointments;
|
|
||||||
// };
|
|
||||||
|
|
||||||
// // subscribeToMore({
|
|
||||||
// // document: NEW_APPOINTMENTS_SUBSCRIPTION,
|
|
||||||
// // updateQuery: (prev, { subscriptionData }) => {
|
|
||||||
// // if (!subscriptionData.data) return prev;
|
|
||||||
// // const newAppointment = subscriptionData.data.newAppointment;
|
|
||||||
// // const exists = prev.feed.appointments.find(
|
|
||||||
// // ({ id }) => id === newAppointment.id
|
|
||||||
// // );
|
|
||||||
// // if (exists) return prev;
|
|
||||||
|
|
||||||
// // return Object.assign({}, prev, {
|
|
||||||
// // feed: {
|
|
||||||
// // appointments: [newAppointment, ...prev.feed.appointments],
|
|
||||||
// // count: prev.feed.appointments.length + 1,
|
|
||||||
// // __typename: prev.feed.__typename
|
|
||||||
// // }
|
|
||||||
// // });
|
|
||||||
// // }
|
|
||||||
// // });
|
|
||||||
|
|
||||||
// return (
|
|
||||||
// <>
|
|
||||||
// {loading && <p>Loading...</p>}
|
|
||||||
// {error && <pre>{JSON.stringify(error, null, 2)}</pre>}
|
|
||||||
// {data && (
|
|
||||||
// <>
|
|
||||||
// {getAppointmentsToRender(isNewPage, data).map(
|
|
||||||
// (appointment, index) => (
|
|
||||||
// <Link
|
|
||||||
// key={appointment.id}
|
|
||||||
// link={appointment}
|
|
||||||
// index={index + pageIndex}
|
|
||||||
// />
|
|
||||||
// )
|
|
||||||
// )}
|
|
||||||
// {isNewPage && (
|
|
||||||
// <div className="flex ml4 mv3 gray">
|
|
||||||
// <div
|
|
||||||
// className="pointer mr2"
|
|
||||||
// onClick={() => {
|
|
||||||
// if (page > 1) {
|
|
||||||
// history.push(`/new/${page - 1}`);
|
|
||||||
// }
|
|
||||||
// }}
|
|
||||||
// >
|
|
||||||
// Previous
|
|
||||||
// </div>
|
|
||||||
// <div
|
|
||||||
// className="pointer"
|
|
||||||
// onClick={() => {
|
|
||||||
// if (
|
|
||||||
// page <=
|
|
||||||
// data.feed.count / APPOINTMENTS_PER_PAGE
|
|
||||||
// ) {
|
|
||||||
// const nextPage = page + 1;
|
|
||||||
// history.push(`/new/${nextPage}`);
|
|
||||||
// }
|
|
||||||
// }}
|
|
||||||
// >
|
|
||||||
// Next
|
|
||||||
// </div>
|
|
||||||
// </div>
|
|
||||||
// )}
|
|
||||||
// </>
|
|
||||||
// )}
|
|
||||||
// </>
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
|
|
||||||
// export default AppointmentList;
|
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { useHistory } from 'react-router';
|
import { useHistory } from 'react-router';
|
||||||
import { useMutation, gql } from '@apollo/client';
|
import { useMutation, gql } from '@apollo/client';
|
||||||
import { APPOINTMENTS_PER_PAGE } from '../../constants';
|
|
||||||
import { APPOINTMENTS_QUERY } from './AppointmentList';
|
|
||||||
import Datetime from 'react-datetime';
|
import Datetime from 'react-datetime';
|
||||||
import "react-datetime/css/react-datetime.css";
|
import "react-datetime/css/react-datetime.css";
|
||||||
|
|
||||||
@@ -43,34 +41,6 @@ const CreateAppointment = () => {
|
|||||||
start: formState.start,
|
start: formState.start,
|
||||||
end: formState.end
|
end: formState.end
|
||||||
},
|
},
|
||||||
// update: (cache, { data: { createAppointment } }) => {
|
|
||||||
// const take = APPOINTMENTS_PER_PAGE;
|
|
||||||
// const skip = 0;
|
|
||||||
// const orderBy = { createdAt: 'desc' };
|
|
||||||
|
|
||||||
// const data = cache.readQuery({
|
|
||||||
// query: APPOINTMENTS_QUERY,
|
|
||||||
// variables: {
|
|
||||||
// take,
|
|
||||||
// skip,
|
|
||||||
// orderBy
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// cache.writeQuery({
|
|
||||||
// query: APPOINTMENTS_QUERY,
|
|
||||||
// data: {
|
|
||||||
// allAppointments: {
|
|
||||||
// appointments: [createAppointment, ...data.allAppointments]
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// variables: {
|
|
||||||
// take,
|
|
||||||
// skip,
|
|
||||||
// orderBy
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// },
|
|
||||||
onCompleted: () => history.push('/')
|
onCompleted: () => history.push('/')
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { useHistory } from 'react-router';
|
import { useHistory } from 'react-router';
|
||||||
import { useMutation, gql, useQuery } from '@apollo/client';
|
import { useMutation, gql, useQuery } from '@apollo/client';
|
||||||
import { APPOINTMENTS_PER_PAGE } from '../../constants';
|
|
||||||
import { APPOINTMENTS_QUERY } from './AppointmentList';
|
|
||||||
import Datetime from 'react-datetime';
|
import Datetime from 'react-datetime';
|
||||||
import "react-datetime/css/react-datetime.css";
|
import "react-datetime/css/react-datetime.css";
|
||||||
|
|
||||||
@@ -74,10 +72,6 @@ const UpdateAppointment = ({ match: { params: { _id } } }) => {
|
|||||||
if (data === undefined) {
|
if (data === undefined) {
|
||||||
return <div>Loading...</div>
|
return <div>Loading...</div>
|
||||||
} else {
|
} else {
|
||||||
// setFormState({
|
|
||||||
// formState.title= data.oneAppointment.title
|
|
||||||
// })
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<form
|
<form
|
||||||
@@ -95,16 +89,10 @@ const UpdateAppointment = ({ match: { params: { _id } } }) => {
|
|||||||
type="text"
|
type="text"
|
||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
|
readOnly
|
||||||
className="mb2"
|
className="mb2"
|
||||||
value={formState.title}
|
value={data.oneAppointment.title}
|
||||||
onChange={(e) =>
|
|
||||||
setFormState({
|
|
||||||
...formState,
|
|
||||||
title: e.target.value
|
|
||||||
})
|
|
||||||
}
|
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Input title"
|
|
||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
className="mb2"
|
className="mb2"
|
||||||
|
|||||||
@@ -17,18 +17,6 @@ const Header = () => {
|
|||||||
<div className="flex flex-fixed">
|
<div className="flex flex-fixed">
|
||||||
<Link to="/create" className="ml1 no-underline black">New</Link>
|
<Link to="/create" className="ml1 no-underline black">New</Link>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-fixed">
|
|
||||||
{authToken ? (
|
|
||||||
<div className="ml1 pointer black"
|
|
||||||
onClick={() => {
|
|
||||||
localStorage.removeItem(AUTH_TOKEN);
|
|
||||||
history.push(`/`);
|
|
||||||
}}
|
|
||||||
>Logout</div>
|
|
||||||
) : (
|
|
||||||
<Link to="/login" className="ml1 no-underline black">Login</Link>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import { AUTH_TOKEN } from './constants';
|
|||||||
import App from './components/App';
|
import App from './components/App';
|
||||||
import { BrowserRouter } from 'react-router-dom';
|
import { BrowserRouter } from 'react-router-dom';
|
||||||
import { setContext } from '@apollo/client/link/context';
|
import { setContext } from '@apollo/client/link/context';
|
||||||
// import * as serviceWorker from './serviceWorker';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ApolloProvider,
|
ApolloProvider,
|
||||||
ApolloClient,
|
ApolloClient,
|
||||||
@@ -41,37 +39,3 @@ ReactDOM.render(
|
|||||||
</BrowserRouter>,
|
</BrowserRouter>,
|
||||||
document.getElementById('root')
|
document.getElementById('root')
|
||||||
);
|
);
|
||||||
// serviceWorker.unregister();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// import { split } from '@apollo/client';
|
|
||||||
// import { WebSocketLink } from '@apollo/client/link/ws';
|
|
||||||
// import { getMainDefinition } from '@apollo/client/utilities';
|
|
||||||
// // import AppointmentList from './components/AppointmentList';
|
|
||||||
|
|
||||||
// // export default App;
|
|
||||||
|
|
||||||
// const wsLink = new WebSocketLink({
|
|
||||||
// uri: `ws://localhost:4000/graphql`,
|
|
||||||
// options: {
|
|
||||||
// reconnect: true,
|
|
||||||
// connectionParams: {
|
|
||||||
// authToken: localStorage.getItem(AUTH_TOKEN)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// const link = split(
|
|
||||||
// ({ query }) => {
|
|
||||||
// const { kind, operation } = getMainDefinition(query);
|
|
||||||
// return (
|
|
||||||
// kind === 'OperationDefinition' &&
|
|
||||||
// operation === 'subscription'
|
|
||||||
// );
|
|
||||||
// },
|
|
||||||
// wsLink,
|
|
||||||
// authLink.concat(httpLink)
|
|
||||||
// );
|
|
||||||
|
|
||||||
// // reportWebVitals();
|
|
||||||
|
|||||||
@@ -9,10 +9,8 @@ import './utils/db.js';
|
|||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import cors from 'cors';
|
import cors from 'cors';
|
||||||
// import getUserId from './utils';
|
|
||||||
|
|
||||||
|
|
||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
|
|
||||||
const APP_SECRET = 'GraphQL-is-aw3some';
|
const APP_SECRET = 'GraphQL-is-aw3some';
|
||||||
|
|
||||||
function getTokenPayload(token) {
|
function getTokenPayload(token) {
|
||||||
@@ -60,19 +58,9 @@ const server = new ApolloServer({
|
|||||||
path.join(__dirname, 'schema.graphql'),
|
path.join(__dirname, 'schema.graphql'),
|
||||||
'utf8'
|
'utf8'
|
||||||
),
|
),
|
||||||
// schema,
|
|
||||||
cors: true,
|
cors: true,
|
||||||
playground: process.env.NODE_ENV === 'development' ? true : false,
|
playground: process.env.NODE_ENV === 'development' ? true : false,
|
||||||
context: ({ req }) => {
|
context: ({ req }) => {
|
||||||
// if (!db) {
|
|
||||||
// try {
|
|
||||||
// if (!dbClient.isConnected()) await dbClient.connect()
|
|
||||||
// mongo = dbClient.db('Calendar') // database name
|
|
||||||
// console.log(db);
|
|
||||||
// } catch (e) {
|
|
||||||
// console.log('--->error while connecting with graphql context (db)', e)
|
|
||||||
// }
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...req,
|
...req,
|
||||||
mongoose,
|
mongoose,
|
||||||
@@ -83,23 +71,6 @@ const server = new ApolloServer({
|
|||||||
: null
|
: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// subscriptions: {
|
|
||||||
// onConnect: (connectionParams) => {
|
|
||||||
// if (connectionParams.authToken) {
|
|
||||||
// return {
|
|
||||||
// mongoose,
|
|
||||||
// userId: getUserId(
|
|
||||||
// null,
|
|
||||||
// connectionParams.authToken
|
|
||||||
// )
|
|
||||||
// };
|
|
||||||
// } else {
|
|
||||||
// return {
|
|
||||||
// mongoose
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
introspection: true,
|
introspection: true,
|
||||||
tracing: true,
|
tracing: true,
|
||||||
path: '/',
|
path: '/',
|
||||||
@@ -110,7 +81,6 @@ server.applyMiddleware({
|
|||||||
path: '/',
|
path: '/',
|
||||||
cors: true,
|
cors: true,
|
||||||
onHealthCheck: () =>
|
onHealthCheck: () =>
|
||||||
// eslint-disable-next-line no-undef
|
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
if (mongoose.connection.readyState > 0) {
|
if (mongoose.connection.readyState > 0) {
|
||||||
resolve();
|
resolve();
|
||||||
@@ -124,36 +94,3 @@ app.listen({ port: process.env.PORT }, () => {
|
|||||||
console.log(`🚀 Server listening on port ${process.env.PORT}`);
|
console.log(`🚀 Server listening on port ${process.env.PORT}`);
|
||||||
console.log(`😷 Health checks available at ${process.env.HEALTH_ENDPOINT}`);
|
console.log(`😷 Health checks available at ${process.env.HEALTH_ENDPOINT}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// const { graphqlHTTP } = require('express-graphql');
|
|
||||||
// const mongoose = require("mongoose");
|
|
||||||
// const graphqlSchema = require("./graphql/schema/schema")
|
|
||||||
// const appointmentResolvers = require("./graphql/resolvers/appointment")
|
|
||||||
// const userResolvers = require("./graphql/resolvers/user")
|
|
||||||
|
|
||||||
// var MongoClient = require('mongodb', { useUnifiedTopology: true }).MongoClient;
|
|
||||||
// // import { MongoClient } from 'mongodb'
|
|
||||||
// const Query = require('./resolvers/Query');
|
|
||||||
// const Mutation = require('./resolvers/Mutation');
|
|
||||||
// const Subscription = require('./resolvers/Subscription');
|
|
||||||
// const User = require('./resolvers/User');
|
|
||||||
// const Appointment = require('./resolvers/Appointment');
|
|
||||||
// const Follow = require('./resolvers/Follow');
|
|
||||||
// const fs = require('fs');
|
|
||||||
// const path = require('path');
|
|
||||||
// const { getUserId } = require('./utils');
|
|
||||||
|
|
||||||
// const graphqlResolvers = {
|
|
||||||
// appointmentResolvers,
|
|
||||||
// userResolvers
|
|
||||||
// };
|
|
||||||
|
|
||||||
// // const resolvers = {
|
|
||||||
// // Query,
|
|
||||||
// // Mutation,
|
|
||||||
// // Subscription,
|
|
||||||
// // User,
|
|
||||||
// // Appointment,
|
|
||||||
// // Follow
|
|
||||||
// // };
|
|
||||||
|
|||||||
@@ -1,17 +1,12 @@
|
|||||||
// import Appointment from '../../client/src/components/Appointment.js';
|
|
||||||
import Product from './models/product.js';
|
import Product from './models/product.js';
|
||||||
import Appointment from './models/appointment.js';
|
import Appointment from './models/appointment.js';
|
||||||
import User from './models/user.js'
|
import User from './models/user.js'
|
||||||
// import { createAppointment } from './resolvers/Mutation.js';
|
|
||||||
import bcrypt from 'bcrypt';
|
|
||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
import dotenv from 'dotenv';
|
|
||||||
|
|
||||||
export const resolvers = {
|
export const resolvers = {
|
||||||
Query: {
|
Query: {
|
||||||
async allAppointments() {
|
async allAppointments() {
|
||||||
return await Appointment.find({ deleted: false })
|
return await Appointment.find({ deleted: false })
|
||||||
// return await Appointment.find();
|
|
||||||
},
|
},
|
||||||
async oneAppointment(root, args, context, info) {
|
async oneAppointment(root, args, context, info) {
|
||||||
return await Appointment.findOne({
|
return await Appointment.findOne({
|
||||||
@@ -81,7 +76,6 @@ export const resolvers = {
|
|||||||
},
|
},
|
||||||
async deleteAppointment(parent, args, context, info) {
|
async deleteAppointment(parent, args, context, info) {
|
||||||
return await Appointment.findOneAndUpdate({ _id: args._id }, { deleted: true })
|
return await Appointment.findOneAndUpdate({ _id: args._id }, { deleted: true })
|
||||||
// return await Appointment.deleteOne({ _id: args._id });
|
|
||||||
},
|
},
|
||||||
async createProduct(root, {
|
async createProduct(root, {
|
||||||
input
|
input
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
// const mongoose = require("mongoose");
|
|
||||||
import mongoose from 'mongoose';
|
import mongoose from 'mongoose';
|
||||||
|
|
||||||
// const dotenv = require("../../.env");
|
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|||||||
Reference in New Issue
Block a user