Vue.js Assignment– 6
Vue with REST & GraphQL
Basic Questions
- Install Axios, configure a base URL and a default timeout in a Vue app.
- Create a service module that exposes getUsers() using Axios and render the list.
- Add a global Axios request interceptor to attach an Authorization header from localStorage.
- Add a global Axios response interceptor to log non-2xx responses to the console.
- Build a component that fetches on mounted() and shows loading/error/empty states.
- Implement a cancelable Axios request using AbortController and cancel on unmount.
- Create an Axios instance that automatically converts snake_case API fields to camelCase.
- Add an exponential backoff retry (max 3) for HTTP 429/5xx responses.
- Implement a simple in-memory cache for GET requests (keyed by URL + params).
- Build a “Retry” button that reissues the last failed Axios request.
- Install Apollo Client, set up a ApolloClient with HTTP link and InMemoryCache.
- Run a GraphQL query (listPosts) in a component using useQuery and render results.
- Show GraphQL loading and error states in the UI.
- Use GraphQL variables in a query (e.g., post(id: $id)) and display the record.
- Add a GraphQL mutation (createPost) and refetch the listPosts query on success.
- Configure Apollo cache typePolicies with a stable keyFields for Post.
- Add a button to manually refetch() a query and confirm UI updates.
- Create a simple GraphQL fragment and reuse it in two queries.
- Implement a REST paginated list with page and limit params and next/prev buttons.
- Add basic client-side rate limiting by delaying REST calls using setTimeout between requests.
Intermediate Questions
- Build a composable useAxios() that returns { data, error, loading, request } with cancellation support.
- Add Axios request deduplication: if the same GET is in flight, reuse the promise.
- Implement a 401 handler: intercept 401, refresh token via /auth/refresh, retry the original request.
- Add Axios per-request retry config (e.g., { retry: 2, retryDelay: 500 }) and honor it in the interceptor.
- Create a REST list with server-driven pagination (reads Link headers) and renders numbered pages.
- Implement infinite scroll for a REST endpoint using an IntersectionObserver.
- Enforce client-side rate limit for REST (token bucket: 5 req/second) using a small queue.
- Handle REST batch fetching: request multiple IDs in chunks and merge results in the store.
- Configure Apollo split link for HTTP queries/mutations and WebSocket for subscriptions.
- Implement a GraphQL subscription (onPostAdded) and append incoming items to the list.
- Use Apollo cache read/merge functions to do cursor-based pagination for listPosts.
- Implement optimistic UI for a GraphQL likePost mutation with rollback on error.
- Add a network status banner that reacts to Apollo’s networkStatus (loading, refetch, poll).
- Use Apollo pollInterval to refresh a query every 10s; pause/resume polling on tab visibility.
- Add per-operation error handling: map GraphQL errors to field messages in a form.
- Implement a useGraphQL() composable that wraps useQuery/useMutation with standardized error, retry, and toast hooks.
- Add a REST → GraphQL bridge: call REST, then write results into Apollo cache manually.
- Implement backoff and jitter for GraphQL WebSocket reconnect logic.
- Add a rate-limit-aware queue for GraphQL mutations (e.g., batching or spacing calls).
- Create a side-by-side demo comparing REST and GraphQL pagination (offset vs cursor) with identical UI.
Advanced Questions
- Build a request orchestration layer: REST (Axios) + GraphQL (Apollo) with unified caching keys and stale-while-revalidate logic.
- Implement circuit breaker for REST: open after N consecutive failures, half-open after delay, close on success.
- Add distributed tracing headers to Axios requests and GraphQL operations; verify they propagate.
- Implement server-sent events (SSE) fallback when WebSocket subscription fails and unify updates in the store.
- Build a rate-limit middleware that reads Retry-After/X-RateLimit-* headers and schedules retries accordingly.
- Implement GraphQL persisted queries and verify reduced payload size in devtools.
- Create a robust offline-first flow: cache queries, queue mutations, replay on reconnect for both REST and GraphQL.
- Add selective normalization in Apollo cache with custom merge for nested lists and compare perf with large datasets.
- Build a diagnostics panel showing: last 20 REST calls, last 20 GraphQL ops, retries, backoffs, cache hits, subscription events.
- Final Hands-on Project:
- REST: Axios instance with auth, retries, backoff, dedupe, cache, rate-limit queue, pagination (infinite + numbered)
- GraphQL: Apollo Client with HTTP+WS split, cache typePolicies, cursor pagination, optimistic mutations, subscriptions, persisted queries
- Unified composables (useAxios, useGraphQL) with standardized error/retry UX
- Offline + SWR strategy, diagnostics panel, and performance measurements on large lists