0Pricing
GraphQL APIs with Spring Boot · บทเรียน

คำค้นที่บันทึกไว้และคำค้นที่บันทึกไว้อัตโนมัติ

ลดขนาดข้อมูลคำขอและเพิ่มประสิทธิภาพด้วยการลงทะเบียนคำค้นล่วงหน้า เรียนรู้วิธีทำงานของ Automatic Persisted Queries (APQ) และวิธีเปิดใช้ใน Spring Boot GraphQL

คำค้นที่บันทึกไว้และคำค้นที่บันทึกไว้อัตโนมัติ เป็นบทเรียน GraphQL APIs with Spring Boot ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน GraphQL APIs with Spring Boot และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส GraphQL APIs with Spring Boot มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

The Cost of Sending Full Queries

Every GraphQL request normally carries the entire query string. Large queries mean larger payloads, more bandwidth, and repeated parsing and validation on the server.

Persisted queries reduce this overhead by sending a short hash instead.

What Is a Persisted Query?

A persisted query is a query string the server already knows, stored under a unique ID (usually a SHA-256 hash). Clients send the ID, and the server looks up the full query.

Automatic Persisted Queries (APQ)

APQ automates registration. The client first sends only the hash. If the server does not recognize it, the client resends with the full query, which the server then caches under that hash.

The APQ Handshake

The flow has two possible steps:

  • Client sends hash only -> if known, server responds
  • If unknown, server returns PersistedQueryNotFound
  • Client resends hash + full query -> server caches and responds

The Request Extension

APQ travels in the request's extensions field, carrying the hash and protocol version.

{
  "extensions": {
    "persistedQuery": { "version": 1, "sha256Hash": "abc123..." }
  }
}

Performance Benefits

Once a query is persisted, the server can skip parsing and validating its document, and the network carries only a small hash. This lowers latency and CPU for hot queries.

GET Requests and CDN Caching

Because a persisted query is just a hash, it fits in a URL. Sending it as a GET request lets a CDN cache the response, offloading the server entirely for repeated reads.

GET /graphql?extensions={"persistedQuery":{"sha256Hash":"abc123"}}

Enabling APQ in Spring

Add an AutomaticPersistedQueriesProvider backed by a cache (such as Caffeine) when building the GraphQL source.

PreparsedDocumentProvider provider =
    new ApolloPersistedQuerySupport(cacheStore);
GraphQL.newGraphQL(schema)
    .preparsedDocumentProvider(provider)
    .build();

Security as a Bonus

You can run APQ in safelist mode: only pre-approved queries are allowed, and unknown hashes are rejected outright. This blocks arbitrary client queries, shrinking your attack surface.

When Not to Use APQ

APQ shines for stable, repeated queries from your own apps. For ad-hoc tooling, exploratory queries, or constantly changing documents, the handshake overhead may outweigh the savings.

Best Practices

Get the most from persisted queries:

  • Size the cache to hold your hot queries
  • Use GET + CDN for cacheable reads
  • Consider safelist mode for production security
  • Monitor cache hit rates to tune

Quick Check

Test your persisted query knowledge.

Recap

You optimized with persisted queries:

  • Send a hash instead of the full query string
  • APQ registers queries automatically via a handshake
  • Skips re-parsing and enables GET + CDN caching
  • Safelist mode adds security; enable via a document provider

Persisted queries cut payload, latency, and attack surface for hot queries.

คำถามที่พบบ่อย

บทเรียน “คำค้นที่บันทึกไว้และคำค้นที่บันทึกไว้อัตโนมัติ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “คำค้นที่บันทึกไว้และคำค้นที่บันทึกไว้อัตโนมัติ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส GraphQL APIs with Spring Boot ให้อัปเกรดเป็น CoddyKit PRO คอร์ส GraphQL APIs with Spring Boot มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “คำค้นที่บันทึกไว้และคำค้นที่บันทึกไว้อัตโนมัติ”

ลดขนาดข้อมูลคำขอและเพิ่มประสิทธิภาพด้วยการลงทะเบียนคำค้นล่วงหน้า เรียนรู้วิธีทำงานของ Automatic Persisted Queries (APQ) และวิธีเปิดใช้ใน Spring Boot GraphQL คุณปฏิบัติ GraphQL APIs with Spring Boot ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน GraphQL APIs with Spring Boot หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน GraphQL APIs with Spring Boot บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “คำค้นที่บันทึกไว้และคำค้นที่บันทึกไว้อัตโนมัติ” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน GraphQL APIs with Spring Boot นี้ได้ไหม

ได้ บทเรียน GraphQL APIs with Spring Boot ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การวิเคราะห์ความซับซ้อนของคิวรี
  2. กลยุทธ์การแคชสำหรับ GraphQL
  3. การตรวจสอบและติดตาม GraphQL
  4. คำค้นที่บันทึกไว้และคำค้นที่บันทึกไว้อัตโนมัติ
← กลับไปที่ GraphQL APIs with Spring Boot