leebenson / reactql

Universal React+GraphQL starter kit: React 16, Apollo 2, MobX, Emotion, Webpack 4, GraphQL Code Generator, React Router 4, PostCSS, SSR
https://reactql.org
MIT License
1.82k stars 173 forks source link

Example for a MongoDB based server #180

Closed the-petrolhead closed 4 years ago

the-petrolhead commented 4 years ago

Hi,

I'm fairly new to JS/TS client-server development. Pardon my choice of words.

@leebenson ReactQL seems to be a great starter for client. Thanks for your efforts. I already started exploring it and wondering if there is an example of hooking up a MongoDB-GraphQL server?

I'm asking this since ReactQL as frontend starter has made some great choices in terms of developer productivity. I would want to ease the server development as well.

Any recommended starter projects exist for Mongo-GraphQL? I was able o find following but not sure how could I hook them in the ReactQL project. https://github.com/the-road-to-graphql/fullstack-apollo-react-boilerplate https://github.com/arackaf/mongo-graphql-starter

leebenson commented 4 years ago

There's no example of bolting on a GraphQL server in the kit, but you can add one to the router at https://github.com/leebenson/reactql/blob/master/src/runner/app.ts

You'd basically create a /graphql endpoint (or whatever you want to call it), and add in either the GraphQL reference implementation, or a more complete framework like Apollo Server to handle your queries.

Adding MongoDB would be a case of applying that logic inside the GraphQL resolver, based on whatever business rules make sense. You could use an ORM or the standard MongoDB lib for this.