Skip to content

Commit

Permalink
fetchQueryDeduped accepts a RequestIdentifier instead of an Operation…
Browse files Browse the repository at this point in the history
…Descriptor

Reviewed By: jstejada

Differential Revision: D21717163

fbshipit-source-id: c880c058d284a9c953b9d9f53d2c9756b28ba9e8
  • Loading branch information
rbalicki2 authored and facebook-github-bot committed May 27, 2020
1 parent f512c9f commit 041c6ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
18 changes: 11 additions & 7 deletions packages/relay-experimental/usePreloadedQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,17 @@ function usePreloadedQuery<TQuery: OperationType>(
const data = useLazyLoadQueryNode({
componentDisplayName: 'usePreloadedQuery()',
fetchKey,
fetchObservable: fetchQueryDeduped(environment, operation.request, () => {
if (environment === preloadedQuery.environment && source != null) {
return environment.executeWithSource({operation, source});
} else {
return environment.execute({operation});
}
}),
fetchObservable: fetchQueryDeduped(
environment,
operation.request.identifier,
() => {
if (environment === preloadedQuery.environment && source != null) {
return environment.executeWithSource({operation, source});
} else {
return environment.execute({operation});
}
},
),
fetchPolicy,
query: operation,
renderPolicy: options?.UNSTABLE_renderPolicy,
Expand Down
5 changes: 2 additions & 3 deletions packages/relay-runtime/query/fetchQueryInternal.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function fetchQuery(
networkCacheConfig?: CacheConfig,
|},
): Observable<GraphQLResponse> {
return fetchQueryDeduped(environment, operation.request, () =>
return fetchQueryDeduped(environment, operation.request.identifier, () =>
environment.execute({
operation,
cacheConfig: options?.networkCacheConfig,
Expand All @@ -127,12 +127,11 @@ function fetchQuery(
*/
function fetchQueryDeduped(
environment: IEnvironment,
request: RequestDescriptor,
identifier: RequestIdentifier,
fetchFn: () => Observable<GraphQLResponse>,
): Observable<GraphQLResponse> {
return Observable.create(sink => {
const requestCache = getRequestCache(environment);
const identifier = request.identifier;
let cachedRequest = requestCache.get(identifier);

if (!cachedRequest) {
Expand Down

0 comments on commit 041c6ec

Please sign in to comment.