当前位置: 首页>>代码示例>>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;未经允许,请勿转载。