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


TypeScript ApolloClient.subscribe方法代碼示例

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


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

示例1: it

  it('supports subscriptions', done => {
    const query = gql`
      subscription {
        field
      }
    `;

    const link = new ApolloLink(() =>
      Observable.of({ data: { field: 1 } }, { data: { field: 2 } }),
    );
    const local = withClientState();

    const client = new ApolloClient({
      cache: new InMemoryCache(),
      link: local.concat(link),
    });

    let counter = 0;
    expect.assertions(2);
    return client.subscribe({ query }).forEach(item => {
      expect(item).toMatchObject({ data: { field: ++counter } });
      if (counter === 2) {
        done();
      }
    });
  });
開發者ID:petermichuncc,項目名稱:scanner,代碼行數:26,代碼來源:client.ts

示例2: createStore

const composeEnhancers =
  (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
export const store = createStore(reducer, {}, composeEnhancers(autoRehydrate()))

persistStore(store, {
  whitelist: ['mainScreen'],
})

// Subscribe to all status updates, Apollo will automatically update the store using the id.
client
  .subscribe({
    query: gql`
      subscription deviceUpdated {
        deviceUpdated {
          id
          name
          config
        }
      }
    `,
  })
  .subscribe({})
client
  .subscribe({
    query: gql`
      subscription deviceStatusUpdated {
        deviceStatusUpdated {
          id
          value
        }
      }
開發者ID:Pajn,項目名稱:RAXA,代碼行數:31,代碼來源:store.ts

示例3:

            fieldName: Object.keys(alternativeQueries)[0],
            id,
            action: "insert",
          };
        });
      },
      executeQuery: ({ query, variables }) => {
        return client.query({
          query,
          variables,
        });
      }
    }),
    link,
  ]),
});

client
  .subscribe<{ data: CommentAdded; }>({
    query: gql`
      subscription CommentAdded {
        commentAdded {
          id
          text
        }
      }
    `,
  }).subscribe(v => {
    console.log("client.subscribe", v.data);
  });
開發者ID:vvakame,項目名稱:til,代碼行數:30,代碼來源:index.ts


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