-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jasonhsieh
committed
Jan 9, 2019
0 parents
commit b96fbd2
Showing
8 changed files
with
9,686 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"plugins": ["@babel/plugin-proposal-object-rest-spread"], | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"node": 6 | ||
} | ||
} | ||
] | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
### Start the example | ||
|
||
`npm i` | ||
|
||
`npm run start:example1` | ||
|
||
`npm run start:example2` | ||
|
||
... | ||
|
||
### this repo is records for using graphql-compose-mongoose | ||
|
||
codes and examples from below links | ||
|
||
https://github.com/graphql-compose/graphql-compose-examples | ||
|
||
https://github.com/graphql-compose/graphql-compose-mongoose/issues/138 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ApolloServer } from "apollo-server"; | ||
import schema from "./userGqlSchema"; | ||
import mongoose from "mongoose"; | ||
import MongoMemoryServer from "mongodb-memory-server"; | ||
const mongod = new MongoMemoryServer(); | ||
|
||
(async () => { | ||
const uri = await mongod.getConnectionString(); | ||
const port = await mongod.getPort(); | ||
const dbPath = await mongod.getDbPath(); | ||
const dbName = await mongod.getDbName(); | ||
console.log(uri, port, dbPath, dbName); | ||
|
||
mongoose | ||
.connect( | ||
uri, | ||
{ useNewUrlParser: true } | ||
) | ||
.then(() => console.log("DB connected")); | ||
|
||
const server = new ApolloServer(schema); | ||
|
||
server.listen().then(({ url }) => { | ||
console.log("example1 is a working simple user schema"); | ||
console.log(`🚀 Server ready at ${url}`); | ||
}); | ||
})(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import mongoose from "mongoose"; | ||
import { composeWithMongoose } from "graphql-compose-mongoose"; | ||
import { schemaComposer } from "graphql-compose"; | ||
|
||
const UserSchema = new mongoose.Schema( | ||
{ | ||
firstName: String, | ||
lastName: String, | ||
pasword: String | ||
}, | ||
{ | ||
timestamps: true | ||
} | ||
); | ||
|
||
const User = mongoose.model("User", UserSchema); | ||
const customizationOptions = {}; | ||
const UserTC = composeWithMongoose(User, customizationOptions); | ||
|
||
schemaComposer.Query.addFields({ | ||
userById: UserTC.getResolver("findById"), | ||
userByIds: UserTC.getResolver("findByIds"), | ||
userOne: UserTC.getResolver("findOne") | ||
}); | ||
|
||
schemaComposer.Mutation.addFields({ | ||
userCreateOne: UserTC.getResolver("createOne"), | ||
userUpdateById: UserTC.getResolver("updateById"), | ||
userUpdateOne: UserTC.getResolver("updateOne") | ||
}); | ||
|
||
const schema = schemaComposer.buildSchema(); | ||
export default { schema }; |
Empty file.
Oops, something went wrong.