Skip to content

Commit 2b2c254

Browse files
committed
add query and mutation
1 parent 1bc5049 commit 2b2c254

File tree

9 files changed

+4922
-0
lines changed

9 files changed

+4922
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

config/connection.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import mongoose from 'mongoose';
2+
mongoose.connect('mongodb://localhost/test');
3+
mongoose.Promise = global.Promise;
4+
var Schema = mongoose.Schema;
5+
export default {
6+
User : mongoose.model('User', { firstName: String ,lastName: String}),
7+
Post : mongoose.model('Post', { title: String ,description: String, user: { type: Schema.Types.ObjectId, ref: 'User', required:true }})
8+
}

index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import express from 'express';
2+
import bodyParser from 'body-parser';
3+
import { graphiqlExpress, graphqlExpress } from 'apollo-server-express';
4+
import { makeExecutableSchema } from 'graphql-tools';
5+
import mongoose from 'mongoose';
6+
7+
import typeDefs from './schema/user';
8+
import resolvers from './resolver/user';
9+
10+
const schema = makeExecutableSchema({
11+
typeDefs,
12+
resolvers,
13+
});
14+
15+
console.log('typeDefs',typeDefs)
16+
console.log('resolvers',resolvers)
17+
mongoose.connect('mongodb://localhost/test');
18+
19+
const User = mongoose.model('User', { name: String });
20+
21+
const PORT = 3000;
22+
23+
const app = express();
24+
25+
app.use('/graphql', bodyParser.json(), graphqlExpress({ schema, context: { User } }));
26+
27+
app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }));
28+
29+
app.listen(PORT);

0 commit comments

Comments
 (0)