rust-best-practices

tarafından apollographql

Apollo GraphQL'in en iyi uygulamalar el kitabına dayalı, doğal Rust kodlama standartları. Dokuz temel alanı kapsar: kodlama stilleri ve deyimler, clippy linting, performans optimizasyonu, hata yönetimi, test desenleri, generics ve dispatch, tip durumu deseni, dokümantasyon ve işaretçi güvenliği. Kopyalama yerine ödünç almayı, thiserror/anyhow ile Result tabanlı hata yönetimini ve release build'lerle performans profillemesini vurgular. Sahiplik desenleri, panic'ten kaçınma konularında hızlı başvuru rehberliği içerir,...

npx skills add https://github.com/apollographql/skills --skill rust-best-practices

Rust Best Practices

Apply these guidelines when writing or reviewing Rust code. Based on Apollo GraphQL's Rust Best Practices Handbook.

Best Practices Reference

Before reviewing, familiarize yourself with Apollo's Rust best practices. Read ALL relevant chapters in the same turn in parallel. Reference these files when providing feedback:

Quick Reference

Borrowing & Ownership

  • Prefer &T over .clone() unless ownership transfer is required
  • Use &str over String, &[T] over Vec<T> in function parameters
  • Small Copy types (≤24 bytes) can be passed by value
  • Use Cow<'_, T> when ownership is ambiguous

Error Handling

  • Return Result<T, E> for fallible operations; avoid panic! in production
  • Never use unwrap()/expect() outside tests
  • Use thiserror for library errors, anyhow for binaries only
  • Prefer ? operator over match chains for error propagation

Performance

  • Always benchmark with --release flag
  • Run cargo clippy -- -D clippy::perf for performance hints
  • Avoid cloning in loops; use .iter() instead of .into_iter() for Copy types
  • Prefer iterators over manual loops; avoid intermediate .collect() calls

Linting

Run regularly: cargo clippy --all-targets --all-features --locked -- -D warnings

Key lints to watch:

  • redundant_clone - unnecessary cloning
  • large_enum_variant - oversized variants (consider boxing)
  • needless_collect - premature collection

Use #[expect(clippy::lint)] over #[allow(...)] with justification comment.

Testing

  • Name tests descriptively: process_should_return_error_when_input_empty()
  • One assertion per test when possible
  • Use doc tests (///) for public API examples
  • Consider cargo insta for snapshot testing generated output

Generics & Dispatch

  • Prefer generics (static dispatch) for performance-critical code
  • Use dyn Trait only when heterogeneous collections are needed
  • Box at API boundaries, not internally

Type State Pattern

Encode valid states in the type system to catch invalid operations at compile time:

struct Connection<State> { /* ... */ _state: PhantomData<State> }
struct Disconnected;
struct Connected;

impl Connection<Connected> {
    fn send(&self, data: &[u8]) { /* only connected can send */ }
}

Documentation

  • // comments explain why (safety, workarounds, design rationale)
  • /// doc comments explain what and how for public APIs
  • Every TODO needs a linked issue: // TODO(#42): ...
  • Enable #![deny(missing_docs)] for libraries

apollographql tarafından daha fazla skill

apollo-client
apollographql
Apollo Client, JavaScript için kapsamlı bir durum yönetimi kütüphanesidir ve GraphQL ile hem yerel hem de uzak verileri yönetmenizi sağlar. 4.x sürümü, geliştirilmiş önbellekleme, daha iyi TypeScript desteği ve React 19 uyumluluğu sunar.
official
apollo-client
apollographql
We need to translate the given text from English to Turkish, preserving the name "apollo-client" and any technical terms like "queries", "mutations", "caching", "state management", "React", "Apollo Client 4.x", "Vite", "CRA", "Next.js App Router", "React Server Components", "React Router 7", "streaming SSR", "TanStack Start", "useQuery", "useLazyQuery", "useMutation", "useSuspenseQuery", "useBackgroundQuery", "Suspense", "React 18+", "19". Also preserve URLs if any (none here). Do not add any extra commentary or labels. Just output the translated text. The text: "Comprehensive guide for building React applications with Apollo Client 4.x, covering queries, mutations, caching, and state management. Supports multiple React frameworks and setups: client-side apps (Vite, CRA), Next.js App Router with React Server Components, React Router 7 with streaming SSR, and TanStack Start Includes hooks
official
apollo-connectors
apollographql
REST API'lerini @source ve @connect yönergelerini kullanarak GraphQL süper grafiklerine entegre eder. Yapılandırılmış 5 adımlı bir süreç sunar: API yapısını araştırma, yönergelerle şema uygulama, rover supergraph compose ile doğrulama, bağlayıcıları çalıştırma ve test kapsamı. Başlıklar, gövde yükleri, N+1 desenleri için toplu işleme ve $env aracılığıyla ortam değişkeni enjeksiyonu dahil olmak üzere istek yapılandırmasını destekler. Alan seçimi, takma adlandırma, iç içe veriler için alt seçimler ve varlık... ile yanıt eşlemesini yönetir.
official
apollo-federation
apollographql
Apollo Federation, birden fazla GraphQL API'sini (alt grafikler) birleşik bir süper grafik halinde oluşturmayı sağlar.
official
apollo-ios
apollographql
We need to translate the given English text into Turkish, preserving the name "apollo-ios" and technical terms like GraphQL, Swift, async/await, SQLite, HTTP, WebSocket, graphql-transport-ws. The instruction says to translate only the text inside <text>, and not include the name unless it appears in the source text. The name "apollo-ios" does not appear in the source text; the source says "Apollo iOS" (with a space). The instruction says "Name to preserve: apollo-ios" but the source has "Apollo iOS". We should preserve the exact name as given? The instruction says "preserve product names" and the name to preserve is "apollo-ios". However, the source text uses "Apollo iOS". I think we should keep "Apollo iOS" as is because that's the product name in the source. But the instruction says "Name to preserve: apollo-ios" - that might be a key. To be safe, I'll keep "Apollo iOS
official
apollo-kotlin
apollographql
Apollo Kotlin, GraphQL işlemlerinizden ve şemanızdan Kotlin modelleri oluşturan, Android, JVM ve Kotlin Multiplatform projelerinde kullanılabilen, güçlü türde bir GraphQL istemcisidir.
official
apollo-mcp-server
apollographql
AI ajanlarını, Model Context Protokolü aracılığıyla yerleşik içgözlem ve işlem araçlarıyla GraphQL API'lerine bağlayın. GraphQL işlemlerini MCP araçları olarak sunar; üç işlem kaynağını destekler: yerel dosyalar, GraphOS Studio koleksiyonları ve kalıcı sorgu bildirimleri. Şema keşfi ve geçici sorgu testi için dört içgözlem aracı (introspect, search, validate, execute) sağlar; küçültme modu, kompakt notasyonla token kullanımını azaltır. Statik başlıklar aracılığıyla yapılandırılabilir kimlik doğrulama,...
official
apollo-router
apollographql
Apollo Router, Apollo Federation 2 süper grafiklerini çalıştırmak için Rust dilinde yazılmış yüksek performanslı bir grafik yönlendiricisidir. Alt grafiklerinizin önünde yer alır ve sorgu planlaması, yürütme ve yanıt birleştirme işlemlerini yönetir.
official