This file contains hidden or 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
{ | |
"name": "kit", | |
"version": "1.0.0", | |
"description": "Starting point for the Apollo GraphQL Server tutorial.", | |
"main": "src/server.ts", | |
"dependencies": { | |
"apollo-server": "^2.0.0-beta.2", | |
"express": "^4.16.3", | |
"graphql": "0.13.2", | |
"graphql-tools": "^3.0.0-beta.0", |
This file contains hidden or 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
const MONGO_PORT = 27017; | |
const MONGO_URL = "localhost"; | |
const dbName = "graphExample"; | |
// help to debug mongoose | |
mongoose.set("debug", true); | |
mongoose.connect(`mongodb://${MONGO_URL}:${MONGO_PORT}/${dbName}`); | |
const app = express(); |
This file contains hidden or 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 helloSchema from "./hello.schema"; | |
import userSchema from "./user.schema"; | |
const schemas = [userSchema, helloSchema]; | |
export default schemas; |
This file contains hidden or 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 { | |
addMockFunctionsToSchema, | |
gql, | |
makeExecutableSchema | |
} from "apollo-server"; | |
import { GraphQLSchema } from "graphql"; | |
const helloSchema: GraphQLSchema = makeExecutableSchema({ | |
typeDefs: gql` | |
type Query { |
This file contains hidden or 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 { | |
addMockFunctionsToSchema, | |
gql, | |
makeExecutableSchema | |
} from "apollo-server"; | |
import { GraphQLSchema } from "graphql"; | |
const userSchema: GraphQLSchema = makeExecutableSchema({ | |
typeDefs: gql` | |
type Query { |
This file contains hidden or 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 helloResolver from "./hello.resolver"; | |
import userResolver from "./users.resolver"; | |
const resolvers = [userResolver, helloResolver]; | |
export default resolvers; |
This file contains hidden or 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
const helloResolver = { | |
Query: { | |
hello: () => { | |
return "Hello world!"; | |
} | |
} | |
}; | |
export default helloResolver; |
This file contains hidden or 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 { userController } from "../controllers/controllers"; | |
import { AuthenticationError } from "apollo-server"; | |
const userResolver = { | |
Mutation: { | |
addUser(root: any, args: any) { | |
return userController.addUser(root, args); | |
}, | |
deleteUser(root: any, args: any) { | |
return userController.deleteUser(root, args); |
This file contains hidden or 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
export { userController } from "./user.controller"; |
This file contains hidden or 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 { User } from "../models/users"; | |
import { Types } from "mongoose"; | |
const userController = { | |
addUser: (root: any, args: any) => { | |
const user = new User(args); | |
return user.save(); | |
}, | |
deleteUser: (root: any, args: any) => User.deleteOne({ _id: args.id }), | |
updateUser: (root: any, args: any) => { |