10月8日至10日,与我们在纽约市一起参加活动,了解关于GraphQL联盟和API平台工程的最新的技巧、趋势和新闻。加入我们,一起参加2024年在纽约市的GraphQL峰会
文档
免费开始

服务器驱动UI模式设计

使用枚举、合约和接口实现SDUI

模式设计服务器驱动UI

💡 提示

如果您是企业客户,想了解更多关于这个主题的信息,请尝试企业最佳实践:模式设计课程.

不是企业客户? 了解GraphOS Enterprise。

这些模式提供了服务器驱动UI(SDUI)的示例以及如何构建 's方案结构以编码和表示UI元素。然后客户端可以使用平台特定的渲染引擎来解释该方案并生成UI组件。

💡 提示

有关SDUI一般信息的更多信息,请参阅服务器驱动UI基础知识

基于设备的枚举SDUI

不同的设备(例如,移动,网页,Roku,Apple TV)可能需要不同的UI布局或组件。您可以使用枚举来声明设备类型列表,以获取哪个UI类型。

enum UIDeviceType {
MOBILE
WEB
ROKU
APPLETV
}
interface UIApp {}
type WebApp implements UIApp {}
type IOSApp implements UIApp {}
type AndroidApp implements UIApp {}
type AppleTVApp implements UIApp {}
type RokuApp implements UIApp {}
type Query {
app(type: UIDeviceType! = WEB): UIApp!
}

在以下示例中,UIDeviceType 枚举允许您指定要获取 UIApp 的设备类型。

基于设备的 SDUI 与合约

您可以使用类似基于设备的 SDUI 与 合约 从您的模式中移除与目标平台无关的 UI 组件。

type UIApp {
spotlight: UISpotlightComponent @tag(name: "DESKTOP")
dashboard: UIDashboardComponent
mobileMenu: UIMenuComponent @tag(name: "MOBILE")
menu: UIMenuComponent @tag(name: "WEB")
}
type Query {
app: UIApp!
}

💡 提示

更多关于 合约使用模式 的信息。

SDUI 网页仪表板

以下示例展示了一个静态结构的模式,客户端可以使用它来创建网页仪表板 UI。

type AppLogo {
url: String
alt: String
}
type AppLink {
icon: String
label: String
path: String
}
type AppUserMenu {
user: User
}
type AppNavbar {
logo: AppLogo
items: [AppLink]
user: AppUserMenu
}
type AppMobileMenu {
items: [AppLink]
user: AppUserMenu
}
type AppHomePage {
recommended: [AppLink]
}
type WebApp {
navbar: AppNavbar
menu: AppMobileMenu
home: AppHomePage
settings: AppSettingsPage
profile: AppProfilePage
}
type Query {
app: WebApp!
}

使用接口的 SDUI 网页仪表板

以下示例模式也是针对网页仪表板 UI 的,但它使用 接口 来构造动态响应 UI。通过使用接口,子图 “体验” 可以动态返回不同的 UI 组件。

interface UIComponent {
id: ID
}
type UILogo implements UIComponent {
id: ID
url: String
alt: String
}
interface UINavbarItem implements UIComponent {
id: ID
label: String
path: String
icon: String
}
interface UINavbar implements UIComponent {
id: ID
logo: UILogo
items: [UINavbarItem]
}
interface UIMenuItem implements UIComponent {
id: ID
label: String
path: String
icon: String
}
interface UIMenu implements UIComponent {
id: ID
logo: UILogo
items: [UIMenuItem]
}
interface UISidebar implements UIComponent {
id: ID
title: String
content: [UIComponent]
}
interface UILayout implements UIComponent {
id: ID
content: [UIComponent]
}
interface UIScreen implements UIComponent {
id: ID
current: UIPage
navbar: UINavbar
menu: UIMenu
main: UILayout
sidebar: UISidebar
}
enum UIPage {
HOME
DASHBOARD
SETTINGS
}
type Query {
app(page: UIPage!): UIScreen!
}
下一步
首页
评分文章评分

©2024Apollo Graph Inc.,商号 Apollo GraphQL。

隐私政策

公司