Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
hfpp2012
/
merng
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 8fa8779d
authored
Sep 12, 2019
by
qiuzhi99
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
post model
1 parent
0f154540
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
2 deletions
index.js
models/Post.js
models/User.js
index.js
View file @
8fa8779
...
...
@@ -4,15 +4,31 @@ const gql = require("graphql-tag");
const
mongoose
=
require
(
"mongoose"
);
const
Post
=
require
(
"./models/Post"
);
const
typeDefs
=
gql
`
type Post {
id: ID!
body: String!
createdAt: String!
username: String!
}
type Query {
sayHi: String!
getPosts: [Post]
}
`
;
const
resolvers
=
{
Query
:
{
sayHi
:
()
=>
"hello world"
async
getPosts
()
{
try
{
const
posts
=
await
Post
.
find
();
return
posts
;
}
catch
(
err
)
{
throw
new
Error
(
err
);
}
}
}
};
...
...
models/Post.js
0 → 100644
View file @
8fa8779
const
{
model
,
Schema
}
=
require
(
"mongoose"
);
const
postSchema
=
new
Schema
({
body
:
String
,
username
:
String
,
createdAt
:
String
,
comments
:
[
{
body
:
String
,
username
:
String
,
createdAt
:
String
}
],
likes
:
[
{
username
:
String
,
createdAt
:
String
}
],
user
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
"users"
}
});
module
.
exports
=
model
(
"Post"
,
postSchema
);
models/User.js
0 → 100644
View file @
8fa8779
const
{
model
,
Schema
}
=
require
(
"mongoose"
);
const
userSchema
=
new
Schema
({
username
:
String
,
password
:
String
,
email
:
String
,
createdAt
:
String
});
module
.
exports
=
model
(
"User"
,
userSchema
);
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment