Design and Implementation of a GraphQL Model Management Platform for Frontend‑Backend Collaboration
The article presents a comprehensive solution for improving interface reuse, domain‑model abstraction, and front‑back collaboration by building a GraphQL‑based Model Management Platform (GMP) that supports data‑model management, service orchestration, request generation, caching, authentication, and monitoring, complete with tooling and workflow integration.
The current system suffers from tightly coupled page‑specific APIs, missing domain models, and a cumbersome front‑back collaboration process, leading to high development cost and low reusability.
To address these issues, the proposed goals are to enable reusable business interfaces, establish a GraphQL Model Management Platform (GMP) for unified data‑model management, service orchestration, and request handling, and to streamline collaboration through GraphQL‑based tooling such as request management, code generation, and VSCode/Chrome plugins.
GraphQL is chosen for its field‑level customization, aggregation, version‑free APIs, strong type checking, and naming flexibility, while acknowledging its higher learning curve and the need for careful tool selection.
The framework includes Apollo Client DevTools, Altair, GraphQL Editor, graphql‑code‑generator, and custom CLI tools that generate TypeScript types and request code, allowing developers to configure models and requests directly in GMP.
Three front‑end workflow stages are defined: (1) GMP configuration – focusing on model selection and request setup; (2) Project usage – generating request code and types via CLI, importing them into the project, and using mock data for local debugging; (3) CI/CD – deploying the front‑end with existing pipelines.
The GMP architecture consists of three core modules: data‑model management (project, data source, and schema definition handling), service orchestration (combining data sources into GraphQL requests), and GraphQL request management (online debugging, saving, editing, and CLI‑driven code generation).
Authentication is implemented by attaching @auth directives to schema types and mutations, enabling permission checks based on the bound keyword during request resolution, and supporting gray‑release strategies through permission points.
Client‑side caching leverages Apollo Client's normalization and reactive cache; challenges with create/delete operations are mitigated by smart cache invalidation strategies and selective refetching, with optional use of community solutions like smart‑cache.
Model and request reuse are achieved via GraphQL fragments stored in GMP; developers import fragments using generated code, for example:
type User @auth(keyword: xxx) {
name: String
banned: Boolean
canPost: Boolean
products: [Product]
}
type Product @auth(keyword: xxx) {
name: String
banned: Boolean
canPost: Boolean
user: User
}
fragment AnchorField on Anchor {
anchor_uid
aweme_display_id
hotsoon_display_id
xigua_display_id
anchor_nickname
anchor_avatar
}
export const GET_ANCHOR_INFO = gql`
${FRAGMENT_DEMO}
query getAnchorInfo($postId: ID!) {
anchor(postId: $postId) {
...AnchorField
faction { ...FactionField }
}
}
`;Debugging is supported both in the GMP request creation UI and via Chrome extensions that display GraphQL network traffic and allow mock data injection.
Error handling distinguishes GraphQL syntax/validation errors, resolver errors, and network failures, recommending onError links for GraphQL errors, retry links for network issues, and unified toast notifications for user feedback.
Monitoring uses a front‑end SDK to report custom events, tagging GraphQL queries by name to differentiate them in alerting systems.
Typical business scenarios include a workbench that splits initial and secondary data loads, pagination using fetchMore with offset‑limit caching, and polling with no‑cache policies for live data streams, illustrated by code snippets such as:
const FEED_QUERY = gql`
query Feed($offset: Int, $limit: Int) {
feed(offset: $offset, limit: $limit) {
id
# ...
}
}
`;
const PaginationDemo = () => {
const { loading, data, fetchMore } = useQuery(FEED_QUERY, {
variables: { offset: 0, limit: 10 },
});
if (loading) return 'Loading...';
return (
fetchMore({ variables: { offset: data.feed.length } })}
/>
);
};
const defaultOptions = {
pollingQuery: { pollingFollow: 'no-cache' },
};
const client = new ApolloClient({
link: concat(authMiddleware, httpLink),
cache: new InMemoryCache(),
defaultOptions,
});Overall, the GMP platform provides a standardized, reusable, and observable GraphQL ecosystem that enhances development efficiency and product quality for the front‑end team.
TikTok Frontend Technology Team
We are the TikTok Frontend Technology Team, serving TikTok and multiple ByteDance product lines, focused on building frontend infrastructure and exploring community technologies.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.