- Docker
- Clone this repo to your local machine using
https://github.com/Neablis/user-messages
$ docker-compose up
$ docker-compose run --rm app npm run-script migrate
- Go to
http://localhost:3000/graphql
to test calls
- Graphql
- Node
- Postgres
- Caching
- Src/
- Modules/
- Users/
- Model.js
- Mutations.js
- Queries.js
- Resolvers.js
- Users/
- Services/
- Users/
- index.js
- utilsForUsers.js
- Users/
- Modules/
Contains endpoints, services, and models
Structured as
- General Functionality I.E. Users
- Model
- Database model of the feature
- Mutations
- Contains all Graphql Mutations
- Queries
- Contains all Graphql Queries
- Resolvers
- Contains all validations of inputs for Mutations and Queries
- Model
This structure focuses on separating http/Graphql concerns from system concerns. Modules validate inputs, deal with auth, and format inputs.
Pros:
- Strict rule system limiting necessary planning when adding new Functionality
- Extends to 100s of thousands of lines of code easily
- Simple to add new features to the code base, simple to debug, simple to search code due to the flat rather than deep code structure
Cons:
- Lots of boilerplate necessary to implement a few Feature
- Potentially ugly or difficult to write code for features that don't have clear lines of delineation between functionality
- Sequelize makes it difficult to write efficient queries, this structure + graphql can hide those performance hits because of nested resolvers
Contains business logic, this is where functionality is isolated, and composed between different services.
Structured as
- Service Name
- index.js - the root where logic will be exported from
- supporting.js - Where anything else that is needed for the service lives, these are private from other servicers.
mutation {
user (email : "<email>", password: "<password>") {
id
email
phoneNumber
}
}
mutation {
user (phoneNumber : "<phoneNumber>", password: "<password>") {
id
email
phoneNumber
}
}
{
user {
id
email
}
}
{
login (email: "<email>", password: "<password>") {
id
email
phoneNumber
}
}
{
users (limit: 0, offset: 0) {
id
email
phoneNumber
}
}
mutation {
message(message: "<message>") {
id
message
createdAt
}
}
mutation {
deleteMessage(id: 1)
}
mutation {
message(message: "<message>", id: <messageId>) {
id
message
createdAt
}
}
{
messages {
id
message
createdAt
}
}
mutation {
follow(userId: <userId>)
}
mutation {
unfollow(userId: <userId>)
}
{
follows {
id
email
phoneNumber
}
}
{
followedMessages {
id
message
createdAt
}
}
$ docker-compose run --rm app npm run-script test
- Get test coverage to 100% (Only happy paths ATM)
- Optimize some DB calls for getFollowedMessages
- Build out factories to clean up test suites
- Dynamically load models, queries, and mutations