當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript apollo-link-state.withClientState函數代碼示例

本文整理匯總了TypeScript中apollo-link-state.withClientState函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript withClientState函數的具體用法?TypeScript withClientState怎麽用?TypeScript withClientState使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了withClientState函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: createLinkWithCache

const stateLink = createLinkWithCache((cache: any) =>
  withClientState({
    defaults: defaultState,
    resolvers: { ...mutationResolvers },
    typeDefs,
    cache
  })
開發者ID:hanming2033,項目名稱:React-Starter-AWS-AppSync,代碼行數:7,代碼來源:AWSApolloClient.ts

示例2: compose

export function compose(): AppFrontendLibs {
  const cache = new InMemoryCache({
    dataIdFromObject: () => null,
    fragmentMatcher: new IntrospectionFragmentMatcher({
      introspectionQueryResultData,
    }),
  });

  const observableApi = new AppKibanaObservableApiAdapter({
    basePath: chrome.getBasePath(),
    xsrfToken: chrome.getXsrfToken(),
  });

  const graphQLOptions = {
    connectToDevTools: process.env.NODE_ENV !== 'production',
    cache,
    link: ApolloLink.from([
      errorLink,
      withClientState({
        cache,
        resolvers: {},
      }),
      new HttpLink({
        credentials: 'same-origin',
        headers: {
          'kbn-xsrf': chrome.getXsrfToken(),
        },
        uri: `${chrome.getBasePath()}/api/siem/graphql`,
      }),
    ]),
  };

  const apolloClient = new ApolloClient(graphQLOptions);

  const appModule = uiModules.get('app/siem');

  const framework = new AppKibanaFrameworkAdapter(appModule, uiRoutes, timezoneProvider);

  const libs: AppFrontendLibs = {
    apolloClient,
    framework,
    observableApi,
  };
  return libs;
}
開發者ID:,項目名稱:,代碼行數:45,代碼來源:

示例3: compose

export function compose(): InfraFrontendLibs {
  const cache = new InMemoryCache({
    addTypename: false,
    fragmentMatcher: new IntrospectionFragmentMatcher({
      introspectionQueryResultData,
    }),
  });

  const observableApi = new InfraKibanaObservableApiAdapter({
    basePath: chrome.getBasePath(),
    xsrfToken: chrome.getXsrfToken(),
  });

  const graphQLOptions = {
    cache,
    link: ApolloLink.from([
      withClientState({
        cache,
        resolvers: {},
      }),
      new HttpLink({
        credentials: 'same-origin',
        headers: {
          'kbn-xsrf': chrome.getXsrfToken(),
        },
        uri: `${chrome.getBasePath()}/api/infra/graphql`,
      }),
    ]),
  };

  const apolloClient = new ApolloClient(graphQLOptions);

  const infraModule = uiModules.get('app/infa');

  const framework = new InfraKibanaFrameworkAdapter(infraModule, uiRoutes, timezoneProvider);

  const libs: InfraFrontendLibs = {
    apolloClient,
    framework,
    observableApi,
  };
  return libs;
}
開發者ID:elastic,項目名稱:kibana,代碼行數:43,代碼來源:kibana_compose.ts

示例4: withClientState

const localStateLink = withClientState({
  cache,
  defaults: {
    auth: {
      __typename: "Auth",
      isLoggedIn: Boolean(localStorage.getItem("jwt"))
    }
  },
  resolvers: {
    Mutation: {
      logUserIn: (_, { token }, { cache: appCache }) => {
        localStorage.setItem("jwt", token);
        appCache.writeData({
          data: {
            auth: {
              __typename: "Auth",
              isLoggedIn: true
            }
          }
        });
        return null;
      },
      logUserOut: (_, __, { cache: appCache }) => {
        localStorage.removeItem("jwt");
        appCache.writeData({
          data: {
            auth: {
              __typename: "Auth",
              isLoggedIn: false
            }
          }
        });
        return null;
      }
    }
  }
});
開發者ID:piann,項目名稱:weber-client,代碼行數:37,代碼來源:apollo.ts

示例5: constructor

  constructor(config: PresetConfig) {
    const cache =
      config && config.cacheRedirects
        ? new InMemoryCache({ cacheRedirects: config.cacheRedirects })
        : new InMemoryCache();

    const stateLink =
      config && config.clientState
        ? withClientState({ ...config.clientState, cache })
        : false;

    const errorLink =
      config && config.onError
        ? onError(config.onError)
        : onError(({ graphQLErrors, networkError }) => {
            if (graphQLErrors)
              graphQLErrors.map(({ message, locations, path }) =>
                console.log(
                  `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`,
                ),
              );
            if (networkError) console.log(`[Network error]: ${networkError}`);
          });

    const requestHandler =
      config && config.request
        ? new ApolloLink((operation, forward) =>
            new Observable(observer => {
              let handle: any;
              Promise.resolve(operation)
                .then(oper => config.request(oper))
                .then(() => {
                  handle = forward(operation).subscribe({
                    next: observer.next.bind(observer),
                    error: observer.error.bind(observer),
                    complete: observer.complete.bind(observer),
                  });
                })
                .catch(observer.error.bind(observer));

              return () => {
                if (handle) handle.unsubscribe;
              };
            })
          )
        : false;

    const httpLink = new HttpLink({
      uri: (config && config.uri) || '/graphql',
      fetchOptions: (config && config.fetchOptions) || {},
      credentials: 'same-origin',
    });

    const link = ApolloLink.from([
      errorLink,
      requestHandler,
      stateLink,
      httpLink,
    ].filter(x => !!x) as ApolloLink[]);

    // super hacky, we will fix the types eventually
    super({ cache, link } as any);
  }
開發者ID:NewSpring,項目名稱:apollo-client,代碼行數:63,代碼來源:index.ts

示例6: constructor

  constructor(config: PresetConfig = {}) {
    if (config) {
      const diff = Object.keys(config).filter(
        key => PRESET_CONFIG_KEYS.indexOf(key) === -1,
      );

      if (diff.length > 0) {
        console.warn(
          'ApolloBoost was initialized with unsupported options: ' +
            `${diff.join(' ')}`,
        );
      }
    }

    const {
      request,
      uri,
      credentials,
      headers,
      fetch,
      fetchOptions,
      clientState,
      cacheRedirects,
      onError: errorCallback,
    } = config;

    let { cache } = config;

    if (cache && cacheRedirects) {
      throw new Error(
        'Incompatible cache configuration. If providing `cache` then ' +
          'configure the provided instance with `cacheRedirects` instead.',
      );
    }

    if (!cache) {
      cache = cacheRedirects
        ? new InMemoryCache({ cacheRedirects })
        : new InMemoryCache();
    }

    const stateLink = clientState
      ? withClientState({ ...clientState, cache })
      : false;

    const errorLink = errorCallback
      ? onError(errorCallback)
      : onError(({ graphQLErrors, networkError }) => {
          if (graphQLErrors) {
            graphQLErrors.map(({ message, locations, path }) =>
              // tslint:disable-next-line
              console.log(
                `[GraphQL error]: Message: ${message}, Location: ` +
                  `${locations}, Path: ${path}`,
              ),
            );
          }
          if (networkError) {
            // tslint:disable-next-line
            console.log(`[Network error]: ${networkError}`);
          }
        });

    const requestHandler = request
      ? new ApolloLink(
          (operation, forward) =>
            new Observable(observer => {
              let handle: any;
              Promise.resolve(operation)
                .then(oper => request(oper))
                .then(() => {
                  handle = forward(operation).subscribe({
                    next: observer.next.bind(observer),
                    error: observer.error.bind(observer),
                    complete: observer.complete.bind(observer),
                  });
                })
                .catch(observer.error.bind(observer));

              return () => {
                if (handle) {
                  handle.unsubscribe();
                }
              };
            }),
        )
      : false;

    const httpLink = new HttpLink({
      uri: uri || '/graphql',
      fetch,
      fetchOptions: fetchOptions || {},
      credentials: credentials || 'same-origin',
      headers: headers || {},
    });

    const link = ApolloLink.from([
      errorLink,
      requestHandler,
      stateLink,
//.........這裏部分代碼省略.........
開發者ID:petermichuncc,項目名稱:scanner,代碼行數:101,代碼來源:index.ts


注:本文中的apollo-link-state.withClientState函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。