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


TypeScript ApolloLink.split方法代碼示例

本文整理匯總了TypeScript中apollo-link.ApolloLink.split方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript ApolloLink.split方法的具體用法?TypeScript ApolloLink.split怎麽用?TypeScript ApolloLink.split使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在apollo-link.ApolloLink的用法示例。


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

示例1: it

  it('prints unhandled subscription errors to the console', done => {
    let latestResult: any = null;

    const wSLink = mockObservableLink(sub3);
    const httpLink = mockSingleLink(req1);

    const link = ApolloLink.split(isSub, wSLink, httpLink);

    let counter = 0;

    const client = new ApolloClient({
      link,
      cache: new InMemoryCache({ addTypename: false }),
    });

    const obsHandle = client.watchQuery({
      query,
    });
    const sub = obsHandle.subscribe({
      next(queryResult) {
        latestResult = queryResult;
        counter++;
      },
    });

    let errorCount = 0;
    const consoleErr = console.error;
    console.error = (_: Error) => {
      errorCount += 1;
    };

    obsHandle.subscribeToMore({
      document: gql`
        subscription newValues {
          name
        }
      `,
      updateQuery: () => {
        throw new Error('should not be called because of initial error');
      },
    });

    setTimeout(() => {
      sub.unsubscribe();
      expect(latestResult).toEqual({
        data: { entry: { value: 1 } },
        loading: false,
        networkStatus: 7,
        stale: false,
      });
      expect(counter).toBe(1);
      expect(errorCount).toBe(1);
      console.error = consoleErr;
      done();
    }, 15);

    for (let i = 0; i < 2; i++) {
      wSLink.simulateResult(results3[i]);
    }
  });
開發者ID:NewSpring,項目名稱:apollo-client,代碼行數:60,代碼來源:subscribeToMore.ts

示例2: getMainDefinition

const requestLink = (queryOrMutationLink: ApolloLink) => ApolloLink.split(
  ({ query }) => {
    const { kind, operation } = getMainDefinition(query);
    return kind === 'OperationDefinition' && operation === 'subscription';
  },
  subscriptionLink,
  queryOrMutationLink,
);
開發者ID:apollostack,項目名稱:GitHunt-angular2,代碼行數:8,代碼來源:graphql.module.ts

示例3: getMainDefinition

const requestLink = (queryOrMutationLink: ApolloLink) => {
  return ApolloLink.split(
    ({ query }) => {
      const { kind, operation } = getMainDefinition(query);
      queryOrMutationLink['options'].headers = new HttpHeaders({
        Authorization: localStorage.getItem('token') ? `Bearer ${localStorage.getItem('token')}` : ''
      });
      return kind === 'OperationDefinition' && operation === 'subscription';
    },
    subscriptionLink,
    queryOrMutationLink,
  );
}
開發者ID:Timmahh,項目名稱:questionable-bets,代碼行數:13,代碼來源:graphql.module.ts

示例4: it

  it('triggers new result from subscription data', done => {
    let latestResult: any = null;
    const wSLink = mockObservableLink();
    const httpLink = mockSingleLink(req1);

    const link = ApolloLink.split(isSub, wSLink, httpLink);
    let counter = 0;

    const client = new ApolloClient({
      cache: new InMemoryCache({ addTypename: false }),
      link,
    });

    const obsHandle = client.watchQuery<typeof req1['result']['data']>({
      query,
    });

    const sub = obsHandle.subscribe({
      next(queryResult) {
        latestResult = queryResult;
        counter++;
      },
    });

    obsHandle.subscribeToMore<SubscriptionData>({
      document: gql`
        subscription newValues {
          name
        }
      `,
      updateQuery: (_, { subscriptionData }) => {
        return { entry: { value: subscriptionData.data.name } };
      },
    });

    setTimeout(() => {
      sub.unsubscribe();
      expect(counter).toBe(3);
      expect(stripSymbols(latestResult)).toEqual({
        data: { entry: { value: 'Amanda Liu' } },
        loading: false,
        networkStatus: 7,
        stale: false,
      });
      done();
    }, 15);

    for (let i = 0; i < 2; i++) {
      wSLink.simulateResult(results[i]);
    }
  });
開發者ID:apollostack,項目名稱:apollo-client,代碼行數:51,代碼來源:subscribeToMore.ts

示例5: beforeAll

beforeAll(async () => {


    const fetch = createApolloFetch({ uri: `http://localhost:${process.env['PORT']}/graphql` });
    const cache = new InMemoryCache();
    let link = ApolloLink.split(
        operation => {
            const operationAST = getOperationAST(operation.query, operation.operationName);
            return !!operationAST && operationAST.operation === 'subscription';
        },
        new WebSocketLink({
            uri: `ws://localhost:${process.env['PORT']}/graphql`,
            webSocketImpl: WebSocket,
        }) as any,
        new BatchHttpLink({ uri: `http://localhost:${process.env['PORT']}/graphql` }),
    );
    apollo = new ApolloClient({
        link: ApolloLink.from((true ? [new LoggingLink()] : []).concat([link])),
        cache,
    });
});
開發者ID:baotaizhang,項目名稱:fullstack-pro,代碼行數:21,代碼來源:integration_setup.ts

示例6: WebSocketLink

            reconnect: true,
            // connectionParams,
        },
    );

    wsClient.use([

    ]);

    wsClient.onDisconnected(() => { });
    wsClient.onReconnected(() => { });

    link = ApolloLink.split(
        operation => {
            const operationAST = getOperationAST(operation.query, operation.operationName);
            return !!operationAST && operationAST.operation === 'subscription';
        },
        new WebSocketLink(wsClient) as any,
        new BatchHttpLink({ uri: PUBLIC_SETTINGS.GRAPHQL_URL }),
    );
} else {
    link = new BatchHttpLink({ uri: PUBLIC_SETTINGS.LOCAL_GRAPHQL_URL });
}

// TODO Setup PersistQueries
// if (__PERSIST_GQL__) {
//     import('@sample-stack/graphql-gql/extracted_queries.json').then(queryMap => {
//         console.log(queryMap)
//     }).catch(() => {
//         console.warn('extracted_queries not found');
//     });
// }
開發者ID:baotaizhang,項目名稱:fullstack-pro,代碼行數:32,代碼來源:apollo-client.ts


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