-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29bef81
commit 505076d
Showing
85 changed files
with
19,489 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
packages/**/node_modules | ||
.gitignore | ||
.git | ||
*.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
NODE_ENV=development | ||
FRONTEND_PORT=5173 | ||
BACKEND_PORT=4000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/**/node_modules/ | ||
/**/build/ | ||
/**/dist/ | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,42 @@ | ||
# GraphQL-Crud | ||
CRUD using GraphQL on the frontend and a GraphQL server configured on the backend | ||
# GraphQL Crud | ||
|
||
## Application Demo | ||
|
||
The purpose of this project was to create a CRUD using GraphQL on the frontend and set up a GraphQL server on the backend. The frontend uses React JS + Typescript with Vite. Vitest was also used for testing. | ||
The backend uses node + express as the base for the GraphQL configuration. | ||
MongoDB is used as the database and an instance is created through Docker. | ||
|
||
 | ||
|
||
|
||
## Local execution with Docker | ||
The command will build the API developed in Node, will create a MongoDB instance and will build the frontend project developed in React JS with Vite. | ||
`docker-compose stop && docker-compose up --build -d --remove-orphans` | ||
|
||
 | ||
|
||
This is the final result of the services that you should see if everything works as expected. | ||
|
||
## Application access | ||
To access the application you can do it through: `http://localhost:5173` | ||
|
||
 | ||
|
||
|
||
## Database Access | ||
To MongoDB database can be accessed through the extension MongoDB for VScode: | ||
|
||
 | ||
|
||
The connection string should be for this case `mongodb://localhost:27017/`. After we stablish the connection, we should have access to the database: | ||
|
||
 | ||
|
||
|
||
## Testing | ||
To execute the tests locally, we need to install the libraries dependencies for the service with `npm i`. After that we can run the command: | ||
`npm run test` | ||
|
||
The tests are working with Vitest and Testing Library | ||
|
||
 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM node:16-alpine AS development | ||
RUN mkdir -p /svr/app | ||
WORKDIR /svr/app | ||
COPY package*.json ./ | ||
|
||
RUN npm install glob rimraf | ||
|
||
RUN npm install | ||
|
||
COPY . . | ||
|
||
RUN npm run build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import express from 'express'; | ||
import { ApolloServer } from 'apollo-server-express'; | ||
import cors from 'cors'; | ||
import mongoose from 'mongoose'; | ||
import { resolvers } from './resolvers'; | ||
import { typeDefs } from './typeDefs'; | ||
const dbContext = process.argv[2] == 'mongodb' ? 'mongodb' : 'localhost'; | ||
async function startServer() { | ||
const app = express(); | ||
app.use(cors()); | ||
|
||
const server = new ApolloServer({ typeDefs, resolvers }); | ||
|
||
mongoose.connect(`mongodb://${dbContext}:27017/myapp`); | ||
|
||
await server.start(); | ||
|
||
server.applyMiddleware({ app }); | ||
|
||
app.listen({ port: 4000 }, () => | ||
console.log(`Server ready at http://localhost:4000${server.graphqlPath}`) | ||
); | ||
} | ||
|
||
startServer(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import mongoose from 'mongoose'; | ||
|
||
export interface UserDocument extends mongoose.Document { | ||
name: string; | ||
email: string; | ||
} | ||
|
||
export interface ProductDocument extends mongoose.Document { | ||
name: string; | ||
description: string; | ||
price: number; | ||
} | ||
|
||
const UserSchema = new mongoose.Schema({ | ||
name: { type: String, required: true }, | ||
email: { type: String, required: true }, | ||
}); | ||
|
||
export const User = mongoose.model<UserDocument>('User', UserSchema); | ||
|
||
const ProductSchema = new mongoose.Schema({ | ||
name: { type: String, required: true }, | ||
description: { type: String, required: true }, | ||
price: { type: Number, required: true }, | ||
}); | ||
|
||
export const Product = mongoose.model<ProductDocument>('Product', ProductSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"watch": ["src"], | ||
"ext": "ts", | ||
"exec": "ts-node src/index.ts" | ||
} | ||
|
Oops, something went wrong.