-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotes.txt
More file actions
82 lines (58 loc) · 3.35 KB
/
Copy pathNotes.txt
File metadata and controls
82 lines (58 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
THreads App Backend Using GraphQL
GraphQL
Rest API
Client ----> Server
User needs some resource does a GET request on an API Route, Server Gives the Data
Problem:
1.Only a Specific Part of data is required , but we need to fetch all if using REST API, Bandwidth reduces , unnecessary data is being transfered
2.We need to fo a seperate call for more data from the first requiest , then server sends more unnecessary data
Need to do 2 API Calls and more unnecessary data.
GraphQL
Solution for the REST API Problems
1.Client can specify the exact data required and not the entire respnse is sent.
2. Instead of calling 2 API's we can have Nested queries , that solves the problem of repeated calling
Threads Backend Architecture
GraphQL server has queries and mutrations
Query - to get something from server , to the client , fetch data
Mutation - to add data into our backend -- we use mutation to add data
there is a schema layer , that is graphql server scheam and not database schema
We need to specify what type fo data is required , this is given by cleint adn the structure is before hand told in schema layer
There are resolvers for queries and mutations where it ahs the actual code of what it has ti be done, typeDefs adn query and names of the actions
reolcer has actual code implemetnation of fn name in qury and then does the actual code
We get back data in same format we asked or queried for .
we can use db operations in resolcvers also it is not a good practice as we have coupled it tightly , to change some data, then we need ot change it everywhere and coupled it that is hardcoded , and express or any other cant use it
We create a service layer for CRUD Operations , there are multiple operations
THese layers interact with the database , all teh business logic insid ethe service layer
using a DAO data access object .
Any Data layer is in an isolated envirmnet , created by ORM's and its client will interact witht the database and is in connction with our databse.
Service layer interacts with the DAO Layer
Any thrid party express or trpc all these are interacted with servcice alyyer , these are better for good reusability adn more
Tech Stack
ExpressJS - -Server
GraphQL - Apollo
Postgress
Docker
TypeScript
We ahve used docekr for our developement process to setup postgresql
whenever we update db prisma we need to migrate the databse and the migrations are created
npx prisma migrate dev --name description_of_migration
Docker Compose up
It is used to run teh psotgresql ont he containewr instaead of downloading it to the computer
docker-compose up -d -- runs the container in teh background, need to login to docker and do it
docker exec -it c_id bash -- opens a bash of the container and can use postfresql inside the container
then we can start using it
su user_name
psql -- enter into postgresql
\l -- lists the databses
\c name -- switches to the databse
\d - to lists tthe tables
\d table_name - lists the columns
\x - to dispaly in column wise
If there is already a filder being tracked by git then there is a cache so need to clear it before addingot ignore filder
git rm -r --cached build/
git add .gitignore
git commit -m "Ignore build folder"
git push origin master
git rm -r --cached build/
git commit -m "Remove build folder from repository"
git push origin master