Apollo-link: apollo-link-batch-httpのユーザーに、バッチ処理するリクエストを決定させます

作成日 2018年01月07日  ·  2コメント  ·  ソース: apollographql/apollo-link

_apollo-link-batch-http_を使用する場合、特定の時間間隔のすべてのリクエストがバッチで呼び出されます。 私たちのアプリケーションでは、ほとんどのリクエストは高速ですが、時間のかかるリクエストもあります。 既知の遅いリクエストを他のリクエストとバッチ処理すると、すべてのリクエストの応答時間が最も遅いリクエストと同じになるため、ユーザーエクスペリエンスが低下します。 そのため、リクエストをすぐにバッチ処理するかどうかを決定できるコールバックがあれば便利です。

最も参考になるコメント

あなたは分割でそれを行うことができます
__links.js__

const batchHttpLink = new BatchHttpLink({
  fetch: createApolloFetch({
    constructOptions,
    uri: process.env.REACT_APP_API_ENDPOINT,
  }),
})

const normalHttpLink = createHttpLink({
  uri: '/graphql',
  credentials: 'same-origin',
})

export split(({getContext}) => getContext().noBatch, normalHttpLink, batchHttpLink)

バッチリンクを使用しないクエリを作成する

const ProfileWithData = graphql(CurrentUserForLayout, {
  options: { 
    context: { noBatch: true }
  },
})(Profile);

ここでは、コンテキストでnoBatchを使用して、クエリをバッチ処理するかどうかを制御します。 デフォルトでは、すべてのクエリがバッチ処理されます。

全てのコメント2件

あなたは分割でそれを行うことができます
__links.js__

const batchHttpLink = new BatchHttpLink({
  fetch: createApolloFetch({
    constructOptions,
    uri: process.env.REACT_APP_API_ENDPOINT,
  }),
})

const normalHttpLink = createHttpLink({
  uri: '/graphql',
  credentials: 'same-origin',
})

export split(({getContext}) => getContext().noBatch, normalHttpLink, batchHttpLink)

バッチリンクを使用しないクエリを作成する

const ProfileWithData = graphql(CurrentUserForLayout, {
  options: { 
    context: { noBatch: true }
  },
})(Profile);

ここでは、コンテキストでnoBatchを使用して、クエリをバッチ処理するかどうかを制御します。 デフォルトでは、すべてのクエリがバッチ処理されます。

@charleywをありがとう-質問は答えられたようですので、先に進んでこれを閉じます。

このページは役に立ちましたか?
0 / 5 - 0 評価