Created
April 28, 2019 14:31
-
-
Save byurhannurula/ef6301c06cb350f8156136e3aad7c963 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mongoose, { Schema } from 'mongoose' | |
const userSchema = new Schema({ | |
name: String, | |
bio: String, | |
email: String, | |
password: String, | |
googleId: String, | |
githubId: String, | |
avatar: String, | |
sessions: [{ | |
type: Schema.Types.ObjectId, | |
ref: 'Session', | |
}], | |
socialLinks: [{ | |
type: String, | |
}], | |
}, | |
{ | |
timestamps: true, | |
}, | |
) | |
const sessionSchema = new Schema({ | |
name: String, | |
cardSet: String, | |
createdBy: { | |
type: Schema.Types.ObjectId, | |
ref: 'User', | |
}, | |
polls: [{ | |
type: Schema.Types.ObjectId, | |
ref: 'Poll', | |
}], | |
members: [{ | |
type: Schema.Types.ObjectId, | |
ref: 'User', | |
}], | |
}, | |
{ | |
timestamps: true, | |
}, | |
) | |
const User = mongoose.model('User', userSchema) | |
const Session = mongoose.model('Session', sessionSchema) | |
export default [User, Session] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { isAuthenticated } from '../utils' | |
export default { | |
Query: { | |
// Users | |
me: (parent, args, { req, models }, info) => {}, | |
getUser: (parent, { id }, { models }, info) => {}, | |
getUsers: async (parent, args, { req, models }, info) => {}, | |
// Sessions | |
getSession: (parent, { id }, { req, models }, info) => { | |
isAuthenticated(req) | |
return models.Session.findById(id) | |
}, | |
getSessions: async (parent, args, { req, models }, info) => { | |
isAuthenticated(req) | |
const sessions = await models.Session.find({}).populate({ | |
path: 'createdBy', | |
model: 'User', | |
}) | |
return sessions | |
}, | |
}, | |
Mutation: { | |
signUp: async (parent, args, { req, models }, info) => {}, | |
signIn: async (parent, args, { req, models }, info) => {}, | |
signOut: (parent, args, { req, res }, info) => {}, | |
// Sessions | |
startSession: async (parent, { name, cardSet }, { req, models }, info) => { | |
isAuthenticated(req) | |
const session = await new models.Session({ | |
name, | |
cardSet, | |
createdBy: req.session.userId, | |
}).save() | |
return session | |
}, | |
}, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { gql } from 'apollo-server-express' | |
const schema = gql` | |
type Query { | |
getSession(id: ID!): Session | |
getSessions: [Session] | |
} | |
type Mutation { | |
startSession(name: String!, cardSet: String): Session! | |
} | |
type User { | |
id: ID! | |
name: String! | |
bio: String | |
email: String! | |
avatar: String | |
password: String! | |
socialLinks: String | |
sessions: [Session!] | |
createdAt: String! | |
updatedAt: String! | |
} | |
type Session { | |
id: ID! | |
name: String! | |
cardSet: String! | |
createdBy: User! | |
polls: [Poll] | |
members: [User] | |
createdAt: String! | |
updatedAt: String! | |
} | |
` | |
export default schema |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment