"매 schema → typed client 의 자동화". .graphql schema + operation 으로부터 TypeScript types, hook, fragment 의 생성. 매 schema drift 의 compile-time 차단 — any 의 X, User.email typo 의 즉시 error.
// src/components/UserCard.tsx
import{graphql}from'../gql';import{useQuery}from'@apollo/client';constUSER_QUERY=graphql(`
query GetUser($id: ID!) {
user(id: $id) { id name email avatarUrl }
}
`);exportfunctionUserCard({id}:{id: string}){const{data}=useQuery(USER_QUERY,{variables:{id}});// 매 data?.user 의 type 의 fully inferred
return<div>{data?.user?.name}</div>;}
Fragment masking
constUSER_AVATAR_FRAGMENT=graphql(`
fragment UserAvatar on User { avatarUrl name }
`);functionAvatar({user}:{user: FragmentType<typeofUSER_AVATAR_FRAGMENT>}){constu=getFragmentData(USER_AVATAR_FRAGMENT,user);return<imgsrc={u.avatarUrl}alt={u.name}/>;}// parent — 매 user 의 email 의 access X (fragment 의 declare X)
functionParent({user}){return<Avataruser={user}/>;// user.email 의 access 시 TS error
}
// runtime — query string 의 X, hash 만 전송
import{createPersistedQueryLink}from'@apollo/client/link/persisted-queries';constlink=createPersistedQueryLink({generateHash: doc=>doc['__meta__']['hash']});
Custom scalar mapping
config:{scalars:{DateTime:'string',// ISO 8601
JSON:'Record<string, unknown>',BigInt:'string',},}