Output Extensions
ข้อกำหนด GraphQL อธิบายรายละเอียดวิธีการจัดรูปแบบการตอบสนอง ซึ่งรวมถึงการกำหนดว่าควรใช้ entry ระดับบนสุดใดในแผนที่ที่ส่งกลับ: ข้อมูลที่ถูก queries จะถูกเพิ่มภายใต้ entry data และข้อผิดพลาดภายใต้ entry errors
แต่บางครั้งเราจำเป็นต้องแสดงข้อมูลเพิ่มเติม เช่น บันทึก คำเตือน หรือข้อเสนอแนะ entry เหล่านี้ไม่ได้ถูกครอบคลุมในข้อกำหนด และเราไม่สามารถเพิ่มภายใต้ entry ระดับบนสุดของตัวเองได้ แต่ข้อกำหนด GraphQL ได้จัดเตรียมตำแหน่งพิเศษที่เราสามารถใช้ได้ตามต้องการ เพื่อส่งผ่านข้อมูลแบบกำหนดเองที่ต้องการ: entry ระดับบนสุด extensions
ตามที่อธิบายไว้ใน ส่วน Response Format:
The response map may also contain an entry with key
extensions. This entry, if set, must have a map as its value. This entry is reserved for implementors to extend the protocol however they see fit, and hence there are no additional restrictions on its contents.
ฟีเจอร์ "Proactive Feedback" ของ Gato GraphQL ใช้ความสามารถนี้เพื่อขยายการตอบสนองของ GraphQL API และให้ข้อมูลเพิ่มเติม:
- Deprecations
- Warnings
จากนั้นเราสามารถให้ข้อมูลเพิ่มเติมแก่ผู้ใช้เพื่อระบุการปรับปรุง queries ที่เป็นไปได้:
{
"extensions": {
"warnings": [
{
"message": "Dynamic variable with name 'props' had already been set, had its value overridden",
"locations": [
{
"line": 4,
"column": 25
}
]
}
]
},
"data": {
"posts": {
"excerpt": "Hello world!",
"Content": "<p>Hello world!</p>"
}
}
}