Skip to content

Latest commit

 

History

History
41 lines (23 loc) · 1.87 KB

1.What Is Graphql.md

File metadata and controls

41 lines (23 loc) · 1.87 KB

--> [ What Is GraphQL ? ]

  • Graphql Is Not A Database Which Most People Think Of.
  • Graphql Is A Query Language. QueryLanguage Are Used To Get Data From An Api Endpoint Or From Database.
  • GraphQL Exist Between Client And Backend As A Layer. And We Request This Query Language From Client Side To Get Data.
  • GraphQl Takes Our Request In Consideration And Decide What To Do And What To Return Based On That.

--> [Query An API,Not Database]

  • In GraphQL There Is Two Types Of Request(Types) Technically.

    Query -- Exists For The Data We Want To Req. /GET

       Example -> /pet/{petId} (Think As GET Request)
    

    Mutation -- Changing The Data. /POST, /UPDATE, /DELETE

      Example -> /pet - Update Existing Pet.
                 /pet/{petId} - Delete A Pet By PetID
    
  • So If Want To GET Data We Use Query And If We Want To POST , UPDATE Or DELETE Data We Use Mutation. So Thats Why We Dont Need To Specify Want Kind Of HTTP Req We Are Making From Our Fronted. We Just Specify Query Or Mutation And GraphQL Knows How To Handle It.

--> [GraphQL Existence In Two Approach]

  • CLIENT -> GraphQL (As Middle Layer) -> BACKEND

    Here Fronted Only Communicate With GraphQL. And GraphQL Makes A Request To Backend. So Here Frontend Never Makes A Request To The Backend. So Client Always Will Be Communicating With GraphQL.

  • CLIENT -> GraphQL (As Backend Layer)

    Creating A Express API Which Incorporate With GraphQL.

--> [ Difference Between GraphQL And Rest ]

  • One Endpoint

    /user, /followers, /posts --> /graphql

  • Overfetching / Underfetching

    We Fetch Extra Data With Request Which We Dont Need Is Called OverFetching And Sometime We Need Extra Data From Another Endpoint And Its Became Tricky Sometime in Rest API Also Called Underfetching. Because One Of The Costly Thing In A Webapp is Fetching The Data And Downloading The Data In Frontend.