learning-graphql-and-relay icon indicating copy to clipboard operation
learning-graphql-and-relay copied to clipboard

chapter 1: setting up mongodb

Open cdrani opened this issue 7 years ago • 1 comments

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

cdrani avatar Jan 12 '18 21:01 cdrani

Just change 'schema' and use 'mySchema' here:

graphql(mySchema, inputQuery, {}, { collection })

gerpollo2000 avatar Mar 24 '20 14:03 gerpollo2000