learning-graphql-and-relay
learning-graphql-and-relay copied to clipboard
chapter 1: setting up mongodb
If you are using mongodb version >= 3, then you need to tweak this section a little bit: /index.js
MongoClient.connect(MONGO_URL, (err, client) => {
assert.equal(null, err)
console.log('Connection Approved')
const collection = client.db('test').collection('users')
const rli = readline.createInterface({
input: process.stdin,
output: process.stdout
})
rli.question('Client Request: ', inputQuery => {
graphql(schema, inputQuery, {}, { collection })
.then(result => {
console.log('Server Response: ', result.data)
client.close(() => rli.close())
})
})
})
/schema/main.js
usersCount: {
type: GraphQLInt,
resolve: (_, args, { collection }) => collection.count()
}
Reference this: https://stackoverflow.com/a/47694265/8876839
Just change 'schema' and use 'mySchema' here:
graphql(mySchema, inputQuery, {}, { collection })