grand-stack-seed
grand-stack-seed copied to clipboard
GRAND (GraphQL, React, Apollo, Neo4j Database) Stack seed project with built in Auth and sample User GQL types/queries/mutations.
grand-stack-seed
GRAND (GraphQL, React, Apollo, Neo4j Database) Stack seed project with built in Local Auth and Facebook OAuth, and sample User GQL types/queries/mutations.
Seed project set-up
-
Create
.envfile in your./serverdirectory with the following env variables:NEO4J_URI= *example: bolt://localhost:8687*(this can be a local instance of neo4j or a neo4j sandbox URI)NEO4J_USER= *example: neo4j*NEO4J_PASSWORD= *example: password* -
Create a JWT encryption key using a service such as https://mkjwk.org/ this will be used for encryption in your username/password auth strategy. Once you have the key add it your your
./server's.envfile like so:JWT_SECRET= *example: generated secret* -
Install dependencies in the root and for both the server and client by running
npm (or yarn) installin the root directory, followed bynpm (or yarn) run install-allin the root directory. -
Start up both servers by running
npm startin the root of the project` -
Start dev-ing!
Project configuration
Enable Facebook OAuth:
Facebook OAuth by default is disabled, to allow for user's of this seed project without interest in OAuth to forego it all together. If you would like to enable it all you have to do is create a new app at https://developers.facebook.com and then add the app credentials to the .env file in the ./server directory.
FB_ID= * Get this from https://developers.facebook.com*
FB_SECRET= *Get this from https://developers.facebook.com*
If you plan to run this project locally (on localhost) then make sure to edit the Facebook App's settings and add localhost to the App Domains field and add http://localhost:8000/ as the Site Url in the Website list at the bottom of the settings.
Server configuration:
- There is a schema.graphql file that contains all of tha app's type definitions and is run through a schema generator that converts Cypher queries (indicated by the
@cypheror@relationshipdirectives) into valid computed properties. - You can turn on automatic mutation generation on
line 44of theserver/src/index.jsfile and mutation online 45(this will generate queries for all of your defined types, and add/update/delete mutations for all of your types as well) though I personally reccomend writing your own resolvers or computed properties using the directives mentioned above as it will give you more fine grained control over your application. - There is Local already built in to the application, you can see this in action in the
server/src/resolvers.jsfile. Facebook OAuth is also built in and can be seen in theserver/src/index.jsfile! - You can create even more complex queries and mutations by leverage in the
neo4jgraphqlmethod that is exposed byneo4j-graphql-jspackage by mutating data passed in to a query/mutation before it hits your neo4j database, you can see this inserver/src/resolvers.jsonlines 8-12where passwords are being hashed and salted bybcrypt
Client configuration:
- This is just a basic Create React App (with typescript) that can be configured to your heart's content. (If you're unfamiliar with how to do this there are many resources available online.
- The app is wrapped in an
ApolloProvidermaking your GraphQL server queriable throughout the app. (This happens inclient/src/components/App.tsx - The app is also wrapped in a
BrowserRouterfromreact-routerand you can define your routes as you see fit.- There is an authenticated route at
/that can only be accessed once a user is logged in. - There is a
/registerroute that has some default styled form fields that handle user registration and a/loginroute to authenticate a user.
- There is an authenticated route at