--- title: Graphql Introduction tags: Graphql --- # GraphQL Introduction https://graphql.org/ - GraphQL was developed to rebuild Facebook's native mobile applications. - GraphQL is a query language. It provides a query in the form of a string that is sent to a server. - The server interprets the query and then returns the result in the form of JSON format to the client. ## Advantages of GraphQL Following is a list of major advantages of GraphQL: 1. GraphQL is faster 2. Best for complex systems and microservices 3. No over-fetching and under-fetching problems 4. Hierarchical Structure 5. Defines a data shape 6. Code-sharing 7. Strongly typed 8. Protocol, not a storage 9. Introspective 10. Latest version not required ## Disadvantages of GraphQL Although GraphQL has negligible disadvantages over its advantages, we are giving some disadvantages here. Following is the list of disadvantages of GraphQL: 1. GraphQL Query Complexity 2. GraphQL Caching 3. GraphQL Rate Limiting reference: https://www.javatpoint.com/graphql-advantages-and-disadvantages youtube: https://www.youtube.com/watch?v=8D9XnnjFGMs&ab_channel=Fireship https://www.youtube.com/watch?v=Y0lDGjwRYKw&ab_channel=TheNetNinja 中文youtube介紹: https://www.youtube.com/watch?v=00NKSvAraLQ&ab_channel=Bo-YiWu --- # (中文)GraphQL簡介 - 開發GraphQL是為了重建Facebook的本地移動應用程序。 - GraphQL是一種查詢語言。 它以字符串形式提供查詢,該查詢被發送到服務器。 - 服務器解釋查詢,然後將結果以JSON格式的形式返回給客戶端。 ## GraphQL的優點 以下是GraphQL的主要優點: 1. GraphQL更快 2. 最適合複雜的系統和微服務 3. 沒有過度獲取和不足獲取的問題 4. 層次結構 5. 定義數據形狀 6. 代碼共享 7. 強類型 8. 協議,而不是存儲 9. 內省 10. 不需要最新版本 ### 可以只抓自己要的資料 (包括mutation的回傳資料) - querry, mutation,... 可指定request想要的值(欄位) - 在 updateProfile 這個mutation執行時只回傳 id ![](https://i.imgur.com/FUDxTIJ.png =400x) ## GraphQL的缺點 儘管GraphQL的優點比其缺點可以忽略不計,但在此我們給出了一些缺點。 以下是GraphQL的缺點列表: 1. GraphQL查詢複雜度 2. GraphQL緩存 3. GraphQL速率限制 --- # apolloJS https://www.apollographql.com/ - 先打它想成一個用來幫助graphql開發的工具就好了 - Simplify app development by combining APIs, databases, and microservices into a single data graph that you can query with GraphQL