跳至内容

ApolloSSR

用法

参见 SSR 指南.

方法

getStates

将 apollo 存储状态作为 JavaScript 对象返回。

js
const states = ApolloSSR.getStates(clientsObject, options)

options 默认值为

js
{
  // Prefix for the keys of each apollo client state
  exportNamespace: '',
}

exportStates

将 apollo 存储状态作为 JavaScript 代码返回,代码包含在字符串中。此代码可以直接注入到页面 HTML 中的 <script> 标签内。

js
const js = ApolloSSR.exportStates(clientsObject, options)

options 默认值为

js
{
  // Global variable name
  globalName: '__APOLLO_STATE__',
  // Global object on which the variable is set
  attachTo: 'window',
  // Prefix for the keys of each apollo client state
  exportNamespace: '',
  // By default we use sanitize js library to prevent XSS 
  //  pass true here will perform a standard JSON.stringify on the states
  useUnsafeSerializer: false,
}