GraphQL

الويب

التعريف

لغة استعلام وبيئة تشغيل لواجهات برمجة التطبيقات طوّرتها Meta تتيح للعملاء طلب البيانات التي يحتاجونها تحديداً في طلب واحد. على خلاف REST، يستخدم GraphQL نقطة نهاية واحدة مع مخطط مُحدَّد الأنواع.

How GraphQL Differs from REST

Traditional REST APIRepresentational State Transfer Application Programming Interface. An architectural style for web services that uses standard HTTP methods (GET, POST, PUT, DELETE) and stateless communication to manipulate resources identified by URLs. endpoints return fixed data shapes — you get what the server decides to give you. GraphQL flips this model: the client sends a query describing exactly the fields it needs, and the server returns only those fields. A single GraphQL endpoint replaces dozens of REST routes, eliminating over-fetching (receiving unused data) and under-fetching (requiring multiple round trips).

Queries, Mutations, and Subscriptions

GraphQL operations fall into three types. Queries read data. Mutations write or modify data. Subscriptions open a persistent connection — often over WebSocketA communication protocol that provides full-duplex, persistent connections between a browser and server over a single TCP connection. Ideal for real-time applications like chat, live dashboards, and multiplayer games. — to receive real-time updates when server-side data changes. This makes GraphQL well suited to collaborative tools, dashboards, and live feeds.

Performance and Caching Considerations

Because all requests hit a single POST endpoint, traditional CachingThe practice of storing copies of frequently accessed data closer to the requester to reduce latency and server load. Web caching occurs at multiple layers: browser, CDN edge, reverse proxy, and application. strategies based on URL patterns break down. GraphQL APIs must implement field-level caching, persisted queries, or a CDNContent Delivery Network. A geographically distributed network of servers that caches and serves content from locations close to end users, reducing latency and improving load times. Major providers include Cloudflare, AWS CloudFront, and Akamai. layer that understands GraphQL semantics. HTTP Status CodesThree-digit codes returned by a web server indicating the result of a request. Organized into classes: 1xx (informational), 2xx (success), 3xx (redirection), 4xx (client error), and 5xx (server error). still apply to the transport layer, but GraphQL errors are returned inside the response body with HTTP 200, requiring clients to inspect the errors array separately. Schema introspection — a built-in feature — lets tooling auto-generate documentation and validate queries at development time.

المصطلحات ذات الصلة

المزيد في الويب