الموارد · 37
تأمين واجهة برمجة تطبيقات GraphQL: التفويض، وتكلفة الاستعلام، والأدلة.
تطبيق حقوق الكائنات والحقول، وتقييد عمل الخادم، واختبار مسارات الرفض.
مُحدَّث · 7 min
ما يُساعد هذا الدليل على تحقيقه
- رسم خريطة المخطط المكشوف
- ممارسة الصلاحيات
- تكلفة الاستعلام المرتبط
- التحقق من حالات الرفض
فحص سريع
- هل يمكن لحساب قراءة كائن حساب آخر؟
- هل يتبع حقل حساس قرار الوصول الخاص بحسابه الأصل؟
- ما هي تكلفة العمق والأسماء المستعارة والترقيم معًا؟
- ما هي التفاصيل التي تتسرب من خلال الأخطاء؟
- من يراقب حالات الرفض وسوء الاستخدام؟
طريقة خطوة بخطوة
- 1
عمليات الجرد
سرد الأنواع والحقول والتعديلات والأدوار ومالكي الكائنات والبيانات الحساسة. تضمين استعلامات العميل الحالية والمسارات قليلة الاستخدام.
المخرج: المخرجات: مصفوفة العملية والدور والكائن والحقل.
- 2
اختبار كل قرار وصول
إنشاء حسابات اختبار منفصلة وتبديل معرّفات الكائنات، بما في ذلك الكائنات المتداخلة. يجب على المُحلِّلات فرض التفويض قبل إرجاع البيانات.
المُخرَج: حالات السماح والرفض القابلة للتكرار.
- 3
عمل الخادم المُقيَّد.
قياس التكلفة الفعلية للحقول والمجموعات. اختبار العمق، والنطاق، والأسماء المستعارة، والترقيم، والتجميع، والوقت معًا، ثم تحديد حدود مناسبة.
المُخرَج: سياسة التكلفة ومجموعة استعلامات معادية.
- 4
تقليل التعرض غير الضروري.
تحديد الاستبطان للسياق، وإخفاء تفاصيل الخطأ الداخلية، وإزالة الحقول التي تكشف أكثر مما يحتاجه العملاء.
المُخرَج: مراجعة التكوين العام واستجابات الخطأ.
- 5
المراقبة بضبط النفس.
تسجيل الهوية التقنية المفيدة، والعملية، والتكلفة، والرفض، والارتباط، مع استبعاد الأسرار والحجج الحساسة. تعيين مسؤولية التنبيه.
المُخرَج: لوحة المعلومات وإجراءات التحقيق.
- 6
إعادة التشغيل بعد التغيير.
عند تغيير حقل أو دور أو عميل، إعادة التفويض وحالات التحميل. راجع الاستعلامات القديمة التي تجتاز الآن الرسم البياني المُعدَّل.
المُخرَج: نتيجة اختبار التراجع وقرار الإصدار.
مؤشرات الإدارة
| المؤشر | ما يقيسه | الإجراء الأول |
|---|---|---|
| الوصول | حالات رفض الكائنات والحقول كما هو متوقع | إصلاح المُحلِّل |
| التكلفة | احتواء الاستعلامات المُكثَّفة بواسطة السياسة | تعديل الحقول والحدود |
| الأخطاء | الاستجابات العامة بدون تفاصيل داخلية | تقليل التفاصيل المُعرَضة |
| الانحدار | إعادة تنفيذ عمليات العميل بعد التغيير | منع الأعطال غير المقصودة |
الأخطاء الشائعة
- الاعتماد على الوصول إلى نقطة النهاية فقط
- تحديد العمق مع تجاهل النطاق
- نسيان تفويض الحقول المتداخلة
- تسجيل الوسائط التي تحتوي على بيانات حساسة
الأسئلة المتكررة
هل يُلغي GraphQL تفويض واجهة برمجة التطبيقات العادية؟
لا. لا يزال الوصول إلى كل كائن وحقل يتطلب قرارًا قائمًا على الهوية والسياق.
هل تعطيل الاستبطان كافٍ؟
لا. قد يُقلل من انكشاف المخطط، لكنه لا يُصلح تكلفة الوصول أو الاستعلام.
هل حد العمق كافٍ؟
لا. الأسماء المستعارة والنطاق والقوائم والتكلفة الخاصة بكل حقل مهمة أيضًا.
GraphQL: الأخطاء والقوائم والبيانات الجزئية
الملاحظات المرجعية المفصّلة متاحة باللغة الإنجليزية في هذه النسخة.
How should a client read a GraphQL response when part of the data fails? Start with the processing phase, then follow Non-Null constraints to the first position that permits null. A screen that displays success simply because transport returned can hide an incomplete record. This dossier connects schema, JSON result and interface decisions through a fictional evidence-viewing scenario.
Reference: the published September 2025 edition, reviewed on 23 October 2026. The eight rules below are a CIE editorial selection, not a conformance certification. All scenarios and sample data are fictional.
GraphQL Specification · September 2025 · Published edition · September 2025
Eight points for interpreting the result
| Point | Client consequence | Source |
|---|---|---|
Request error result | An error preventing execution yields errors and no data entry. Invalid variables follow this route even when the document parses. | GraphQL 2025 |
Execution result | After execution, data is present. Its value may be a partial object or null. With no raised error, errors must be absent rather than an empty list. | GraphQL 2025 |
errors[].message | Each error includes a developer-facing message. Give visitors useful wording without exposing internal details or sensitive identifiers. | GraphQL 2025 |
errors[].locations | When a document position can be associated with an error, locations should give line and column starting at 1. These are not data paths. | GraphQL 2025 |
errors[].path | The path uses response names, including aliases, and zero-based integer indices. It keeps the failing position even when a parent is subsequently replaced with null. | GraphQL 2025 |
List / Non-Null | Separate list nullability from item nullability. A failing non-null item nulls the list; a non-null list propagates the error further to its parent. | GraphQL 2025 |
extensions | Response and error extensions are metadata maps defined by implementations. A code in extensions is not a universal GraphQL error-code catalogue. | GraphQL 2025 |
GraphQL / HTTP | The GraphQL specification does not define transport. GraphQL over HTTP is identified here as a working draft; test its media-type negotiation separately. | HTTP draft |
Identify the phase before choosing the message
| Situation | Expected shape | Journey action |
|---|---|---|
| Request rejected before execution | Non-empty errors; data absent | Fix the operation or its variables. Keep an actionable error instead of automatically replaying an unchanged request. |
| Execution with no raised error | data present; errors absent | Display returned data. A schema-permitted null may be normal and alone does not diagnose failure. |
| Execution with partial result | Object data; non-empty errors | Separate retained fields from failing positions. Prevent confirmation that depends on unavailable evidence. |
| Propagation reaches the root | data: null; non-empty errors | Present an unavailable state for this operation. Do not silently recycle a response belonging to another case. |
محاكي قابلية null في GraphQL
The model fixes a query using affaire as the alias of dossier. The case contains reference: String! and preuves, a three-item String list. statut: String! is a root sibling. Items are A-01, A-02 and A-03 before the injected failure. Choose the preuves type, dossier nullability and failing item.
query Demo {
affaire: dossier { reference preuves }
statut
}Local simulation of one item-resolution error on this fixed schema. No API call, query parser, permission test, cost calculation or HTTP verdict. Nested types, subscriptions and incremental delivery are outside the model. The JSON illustrates propagation and contains no real investigation data.
نتيجة JSON خيالية
Four list types, two distinct constraints
| preuves type | Null list allowed | Null item allowed | Single item failure |
|---|---|---|---|
| [String] | Yes | Yes | One item becomes null. |
| [String!] | Yes | No | The list becomes null. |
| [String]! | No | Yes | One item becomes null; the list remains present. |
| [String!]! | No | No | Propagation reaches dossier, then the root depending on its type. |
Eight reference results, readable without JavaScript
G01 · [String] · affaire: Dossier
Only item 1 becomes null; the other two items and the case remain readable.
{
"data": {
"affaire": {
"reference": "DEMO-01",
"preuves": [
"A-01",
null,
"A-03"
]
},
"statut": "fictif"
},
"errors": [
{
"message": "Illustrative item resolution failure",
"path": [
"affaire",
"preuves",
1
]
}
]
}Acceptance check : Check the received JSON and retain errors[0].path = ["affaire", "preuves", 1], even when affaire is replaced by null.
G02 · [String!] · affaire: Dossier
The preuves list becomes null; the case reference and status remain readable.
{
"data": {
"affaire": {
"reference": "DEMO-01",
"preuves": null
},
"statut": "fictif"
},
"errors": [
{
"message": "Illustrative item resolution failure",
"path": [
"affaire",
"preuves",
1
]
}
]
}Acceptance check : Check the received JSON and retain errors[0].path = ["affaire", "preuves", 1], even when affaire is replaced by null.
G03 · [String]! · affaire: Dossier
Only item 1 becomes null; the other two items and the case remain readable.
{
"data": {
"affaire": {
"reference": "DEMO-01",
"preuves": [
"A-01",
null,
"A-03"
]
},
"statut": "fictif"
},
"errors": [
{
"message": "Illustrative item resolution failure",
"path": [
"affaire",
"preuves",
1
]
}
]
}Acceptance check : Check the received JSON and retain errors[0].path = ["affaire", "preuves", 1], even when affaire is replaced by null.
G04 · [String!]! · affaire: Dossier
The affaire case becomes null; the sibling statut field remains available.
{
"data": {
"affaire": null,
"statut": "fictif"
},
"errors": [
{
"message": "Illustrative item resolution failure",
"path": [
"affaire",
"preuves",
1
]
}
]
}Acceptance check : Check the received JSON and retain errors[0].path = ["affaire", "preuves", 1], even when affaire is replaced by null.
G05 · [String] · affaire: Dossier!
Only item 1 becomes null; the other two items and the case remain readable.
{
"data": {
"affaire": {
"reference": "DEMO-01",
"preuves": [
"A-01",
null,
"A-03"
]
},
"statut": "fictif"
},
"errors": [
{
"message": "Illustrative item resolution failure",
"path": [
"affaire",
"preuves",
1
]
}
]
}Acceptance check : Check the received JSON and retain errors[0].path = ["affaire", "preuves", 1], even when affaire is replaced by null.
G06 · [String!] · affaire: Dossier!
The preuves list becomes null; the case reference and status remain readable.
{
"data": {
"affaire": {
"reference": "DEMO-01",
"preuves": null
},
"statut": "fictif"
},
"errors": [
{
"message": "Illustrative item resolution failure",
"path": [
"affaire",
"preuves",
1
]
}
]
}Acceptance check : Check the received JSON and retain errors[0].path = ["affaire", "preuves", 1], even when affaire is replaced by null.
G07 · [String]! · affaire: Dossier!
Only item 1 becomes null; the other two items and the case remain readable.
{
"data": {
"affaire": {
"reference": "DEMO-01",
"preuves": [
"A-01",
null,
"A-03"
]
},
"statut": "fictif"
},
"errors": [
{
"message": "Illustrative item resolution failure",
"path": [
"affaire",
"preuves",
1
]
}
]
}Acceptance check : Check the received JSON and retain errors[0].path = ["affaire", "preuves", 1], even when affaire is replaced by null.
G08 · [String!]! · affaire: Dossier!
data becomes null: the chain of non-null response positions reaches the root.
{
"data": null,
"errors": [
{
"message": "Illustrative item resolution failure",
"path": [
"affaire",
"preuves",
1
]
}
]
}Acceptance check : Check the received JSON and retain errors[0].path = ["affaire", "preuves", 1], even when affaire is replaced by null.
Six business checks for a GraphQL viewing API
| CIE scenario | Evidence to collect | Decision criterion |
|---|---|---|
| G-ACC · Another tenant’s object | Two test identities and the same case ID, without production data. | The service enforces access on the object, relations and fields; possessing an ID grants no access. |
| G-ALIAS · Two aliases, one object | Two aliased selections and correlated traces in an authorized environment. | Aliases change neither access scope nor cost policy. The client links each error to the received response name. |
| G-CACHE · Account change | The sign-out journey followed by sign-in as another test account. | Cached data does not cross identity changes. Partial responses do not present an old proof as newly read. |
| G-COST · Volume and depth | Test measurements of cardinality, depth, time and service-specific quotas. | Depth alone is insufficient: bound list size, expensive fields and grouped operations. No universal threshold is invented. |
| G-ERROR · Public message | Examples of visitor-facing messages and operator-only traces. | Expose no stack, secret, table name or sensitive evidence. A non-sensitive correlation identifier supports troubleshooting. |
| G-SXO · Missing evidence blocks an action | Keyboard and screen-reader journey with a required field failing. | Announce the partial state, keep retained data readable, and explain then prevent confirmation that depends on the unavailable field. |
OWASP · GraphQL Cheat Sheet · Living guidance consulted 2026-10-23
A partial response proves neither a leak nor correct protection. Only service-side authorization tests can verify access. Link each acceptance case to the deployed schema, its version and client observations: data controls, interface resilience and transport need coordinated checks with distinct criteria.
Provenance, edition and licence
GraphQL Specification · September 2025 · reviewed 2026-10-23. CIE: original explanations, fictional scenarios and limited educational model.
GraphQL HTML SHA-256: 39fb3aeffd9b5acebb0830ddc6dcc243c1280a9f0e977897ae59c5cc165511d6
HTTP draft HTML SHA-256: 90a686f8251073b05e105697c6028288520d0c0fa6442924c0d1751cad3f14ac
GraphQL over HTTP · Current Working Draft · Working draft consulted 2026-10-23 · may change
GraphQL · Copyright and Licensing · Open Web Foundation Agreement 1.0
المراجع الرسمية
تدعم المراجع الطريقة. قم بتكييف عمليات التحقق مع سياقك؛ فهي ليست شهادة. قد تكون عناوين المراجع الأصلية والوثائق المصدرية بلغة أخرى.
تاريخ مراجعة المراجع .
