Server-Driven UI Schema Patterns
These patterns provide examples of server-driven ui and how you may structure your graph’s schema to encode and represent user-interface elements. A client would use a platform specific rendering engine to interpret the schema and generate interface components, for an example of a dynamic rendering client see TN32.
Device-based SDUI (with Enums)
Using a known device-type list can be useful in cases where a structured interface is provided through the graph on a per-device basis.
enum UIDeviceType {MOBILEWEBROKUAPPLETV}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!}
Device-based SDUI (with Contracts)
A similar device-based SDUI with Contracts could be used to remove interface components from the schema which are unrelated to the target platform.
type UIApp {spotlight: UISpotlightComponent @tag(name: "DESKTOP")dashboard: UIDashboardComponentmobileMenu: UIMenuComponent @tag(name: "MOBILE")menu: UIMenuComponent @tag(name: "WEB")}type Query {app: UIApp!}
SDUI Web Dashboard (static)
An example of a web application dashboard with a static structure encoded into the schema.
type AppLogo {url: Stringalt: String}type AppLink {icon: Stringlabel: Stringpath: String}type AppUserMenu {user: User}type AppNavbar {logo: AppLogoitems: [AppLink]user: AppUserMenu}type AppMobileMenu {items: [AppLink]user: AppUserMenu}type AppHomePage {recommended: [AppLink]}type WebApp {navbar: AppNavbarmenu: AppMobileMenuhome: AppHomePagesettings: AppSettingsPageprofile: AppProfilePage}type Query {app: WebApp!}
SDUI Web Dashboard using Interfaces
This example uses interfaces to construct dynamic responses. Using this pattern the “experience” subgraph can dynamically return different interface components.
interface UIComponent {id: ID}type UILogo implements UIComponent {id: IDurl: Stringalt: String}interface UINavbarItem implements UIComponent {id: IDlabel: Stringpath: Stringicon: String}interface UINavbar implements UIComponent {id: IDlogo: UILogoitems: [UINavbarItem]}interface UIMenuItem implements UIComponent {id: IDlabel: Stringpath: Stringicon: String}interface UIMenu implements UIComponent {id: IDlogo: UILogoitems: [UIMenuItem]}interface UISidebar implements UIComponent {id: IDtitle: Stringcontent: [UIComponent]}interface UILayout implements UIComponent {id: IDcontent: [UIComponent]}interface UIScreen implements UIComponent {id: IDcurrent: UIPagenavbar: UINavbarmenu: UIMenumain: UILayoutsidebar: UISidebar}enum UIPage {HOMEDASHBOARDSETTINGS}type Query {app(page: UIPage!): UIScreen!}