0Pricing
GraphQL APIs with Spring Boot · Pelajaran

Kueri Tersimpan dan Kueri Tersimpan Otomatis

Kurangi muatan permintaan dan tingkatkan kinerja dengan mendaftarkan kueri terlebih dahulu. Pelajari cara kerja Automatic Persisted Queries (APQ) dan cara mengaktifkannya di Spring Boot GraphQL.

Kueri Tersimpan dan Kueri Tersimpan Otomatis adalah pelajaran GraphQL APIs with Spring Boot gratis di CoddyKit. Ini adalah pelajaran 4 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar GraphQL APIs with Spring Boot, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus GraphQL APIs with Spring Boot mencakup 4 pelajaran total.

Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.

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.

Pertanyaan yang Sering Diajukan

Apakah pelajaran “Kueri Tersimpan dan Kueri Tersimpan Otomatis” gratis?

Ya — teks lengkap “Kueri Tersimpan dan Kueri Tersimpan Otomatis” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus GraphQL APIs with Spring Boot, upgrade ke CoddyKit PRO. Kursus GraphQL APIs with Spring Boot mencakup 4 pelajaran total.

Apa yang akan aku pelajari di “Kueri Tersimpan dan Kueri Tersimpan Otomatis”?

Kurangi muatan permintaan dan tingkatkan kinerja dengan mendaftarkan kueri terlebih dahulu. Pelajari cara kerja Automatic Persisted Queries (APQ) dan cara mengaktifkannya di Spring Boot GraphQL. Kamu berlatih GraphQL APIs with Spring Boot dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.

Apakah aku perlu pengalaman untuk memulai GraphQL APIs with Spring Boot?

Tidak diperlukan pengalaman sebelumnya. GraphQL APIs with Spring Boot di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 4 dari 4.

Berapa lama pelajaran “Kueri Tersimpan dan Kueri Tersimpan Otomatis” memakan waktu?

Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.

Bisakah aku menulis dan menjalankan kode dalam pelajaran GraphQL APIs with Spring Boot ini?

Ya. Setiap pelajaran GraphQL APIs with Spring Boot menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.

Semua pelajaran dalam kursus ini

  1. Analisis Kompleksitas Kueri
  2. Strategi Penyimpanan Sementara untuk GraphQL
  3. Pemantauan dan Pelacakan GraphQL
  4. Kueri Tersimpan dan Kueri Tersimpan Otomatis
← Kembali ke GraphQL APIs with Spring Boot