This commit is contained in:
Riccardo
2021-08-16 11:06:02 +02:00
parent 78db95aa5f
commit 2f119e43bd
12 changed files with 68 additions and 101 deletions

View File

@@ -10,8 +10,8 @@ import fs from 'fs';
import path from 'path';
import cors from 'cors';
import jwt from 'jsonwebtoken';
const { APP_SECRET } = require('../utils');
const APP_SECRET = 'GraphQL-is-aw3some';
const moduleURL = new URL(import.meta.url);
const __dirname = path.dirname(moduleURL.pathname);
const app = express();
@@ -76,7 +76,7 @@ const server = new ApolloServer({
req && req.headers.authorization
? getUserId(req)
: null
}
};
},
// subscriptions: {
// onConnect: (connectionParams) => {

View File

@@ -24,6 +24,11 @@ const AppointmentSchema = new Schema({
deleted: {
type: Boolean,
required: false
},
user: {
type: mongoose.Schema.Types.ObjectId,
ref: "user",
required: false
}
});
export default mongoose.model('appointment', AppointmentSchema);

View File

@@ -1,5 +1,5 @@
import Appointment from './models/appointment.js';
import User from './models/user.js'
import User from './models/user.js';
import jwt from 'jsonwebtoken';
export const resolvers = {

View File

@@ -2,7 +2,7 @@ const bcrypt = require('bcryptjs');
const jwt = require('jsonwebtoken');
const { APP_SECRET } = require('../utils');
function createAppointment(parent, args, context, info) {
function createAppointment(parent, args, context) {
const { userId } = context;
const newAppointment = context.mongo.appointment.create({
@@ -16,7 +16,7 @@ function createAppointment(parent, args, context, info) {
return newAppointment;
}
async function signup(parent, args, context, info) {
async function signup(parent, args, context) {
const password = await bcrypt.hash(args.password, 10);
const user = await context.mongo.user.create({
data: { ...args, password }
@@ -30,7 +30,7 @@ async function signup(parent, args, context, info) {
};
}
async function login(parent, args, context, info) {
async function login(parent, args, context) {
const user = await context.mongo.user.findUnique({
where: { email: args.email }
});
@@ -54,18 +54,18 @@ async function login(parent, args, context, info) {
};
}
async function follow(parent, args, context, info) {
async function follow(parent, args, context) {
const { userId } = context;
const follow = await context.mongo.follow.findUnique({
where: {
linkId_userId: {
linkId: Number(args.linkId),
userId: userId
userId
}
}
});
if (Boolean(follow)) {
if (follow) {
throw new Error(
`Already followed the appointment: ${args.linkId}`
);

View File

@@ -1,4 +1,4 @@
async function feed(parent, args, context, info) {
async function feed(parent, args, context) {
const where = args.filter
? {

View File

@@ -1,26 +1,22 @@
function newLinkSubscribe(parent, args, context, info) {
return context.pubsub.asyncIterator("NEW_LINK")
function newAppointmentSubscribe(parent, args, context) {
return context.pubsub.asyncIterator("NEW_APPOINTMENT");
}
const newAppointment = {
subscribe: newLinkSubscribe,
resolve: payload => {
return payload
},
}
subscribe: newAppointmentSubscribe,
resolve: payload => payload,
};
function newFollowSubscribe(parent, args, context, info) {
return context.pubsub.asyncIterator("NEW_FOLLOW")
function newFollowSubscribe(parent, args, context) {
return context.pubsub.asyncIterator("NEW_FOLLOW");
}
const newFollow = {
subscribe: newFollowSubscribe,
resolve: payload => {
return payload
},
}
resolve: payload => payload,
};
module.exports = {
newAppointment,
newFollow
}
};

View File

@@ -7,9 +7,7 @@ type Query {
orderBy: AppointmentOrderByInput
): Feed!
allAppointments: [Appointment]
oneAppointment(
_id: ID!
): Appointment
oneAppointment(_id: ID!): Appointment
allUsers: [User]
users: [User!]!
}
@@ -30,7 +28,7 @@ type Mutation {
deleted: Boolean
): Appointment!
updateAppointment(
_id: ID!,
_id: ID!
title: String!
description: String
type: String!
@@ -38,21 +36,10 @@ type Mutation {
end: DateTime!
deleted: Boolean
): Appointment
deleteAppointment(
_id: ID!
) : Appointment
signup(
email: String!
password: String!
username: String!
): AuthPayload
login(
email: String!,
password: String!
): AuthPayload
follow(
appointmentId: ID!
): Follow
deleteAppointment(_id: ID!): Appointment
signup(email: String!, password: String!, username: String!): AuthPayload
login(email: String!, password: String!): AuthPayload
follow(appointmentId: ID!): Follow
}
type Subscription {
@@ -66,13 +53,13 @@ type User {
username: String!
email: String!
password: String!
# appointments: [Appointment!]!
appointments: [Appointment!]!
}
input UserInput{
input UserInput {
username: String!
email: String!
password: String!
# appointments: [Appointment!]!
appointments: [Appointment!]!
}
type AuthPayload {
token: String
@@ -88,9 +75,8 @@ type Appointment {
start: DateTime!
end: DateTime!
deleted: Boolean
createdBy: User
user: User
# follows: [Follow!]!
# createdAt: DateTime!
}
input AppointmentInput {
title: String!
@@ -99,11 +85,10 @@ input AppointmentInput {
start: DateTime!
end: DateTime!
deleted: Boolean
}
}
input AppointmentOrderByInput {
title: Sort
desc: Sort
# createdAt: Sort
}
# Follow schemas