Skip to content

Commit dc62585

Browse files
committed
Wrap query checks in __DEV__
1 parent 874271e commit dc62585

File tree

1 file changed

+37
-35
lines changed

1 file changed

+37
-35
lines changed

src/core/ApolloClient.ts

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -474,48 +474,50 @@ export class ApolloClient implements DataProxy {
474474
options = mergeOptions(this.defaultOptions.query, options);
475475
}
476476

477-
invariant(
478-
(options.fetchPolicy as WatchQueryFetchPolicy) !== "cache-and-network",
479-
"The cache-and-network fetchPolicy does not work with client.query, because " +
480-
"client.query can only return a single result. Please use client.watchQuery " +
481-
"to receive multiple results from the cache and the network, or consider " +
482-
"using a different fetchPolicy, such as cache-first or network-only."
483-
);
477+
if (__DEV__) {
478+
invariant(
479+
(options.fetchPolicy as WatchQueryFetchPolicy) !== "cache-and-network",
480+
"The cache-and-network fetchPolicy does not work with client.query, because " +
481+
"client.query can only return a single result. Please use client.watchQuery " +
482+
"to receive multiple results from the cache and the network, or consider " +
483+
"using a different fetchPolicy, such as cache-first or network-only."
484+
);
484485

485-
invariant(
486-
(options.fetchPolicy as WatchQueryFetchPolicy) !== "standby",
487-
"The standby fetchPolicy does not work with client.query, because " +
488-
"standby does not fetch. Consider using a different fetchPolicy, such " +
489-
"as cache-first or network-only."
490-
);
486+
invariant(
487+
(options.fetchPolicy as WatchQueryFetchPolicy) !== "standby",
488+
"The standby fetchPolicy does not work with client.query, because " +
489+
"standby does not fetch. Consider using a different fetchPolicy, such " +
490+
"as cache-first or network-only."
491+
);
491492

492-
invariant(
493-
options.query,
494-
"query option is required. You must specify your GraphQL document " +
495-
"in the query option."
496-
);
493+
invariant(
494+
options.query,
495+
"query option is required. You must specify your GraphQL document " +
496+
"in the query option."
497+
);
497498

498-
invariant(
499-
options.query.kind === "Document",
500-
'You must wrap the query string in a "gql" tag.'
501-
);
499+
invariant(
500+
options.query.kind === "Document",
501+
'You must wrap the query string in a "gql" tag.'
502+
);
502503

503-
invariant(
504-
!(options as any).returnPartialData,
505-
"returnPartialData option only supported on watchQuery."
506-
);
504+
invariant(
505+
!(options as any).returnPartialData,
506+
"returnPartialData option only supported on watchQuery."
507+
);
507508

508-
invariant(
509-
!(options as any).pollInterval,
510-
"pollInterval option only supported on watchQuery."
511-
);
509+
invariant(
510+
!(options as any).pollInterval,
511+
"pollInterval option only supported on watchQuery."
512+
);
512513

513-
invariant(
514-
!(options as any).notifyOnNetworkStatusChange,
515-
"notifyOnNetworkStatusChange option only supported on watchQuery."
516-
);
514+
invariant(
515+
!(options as any).notifyOnNetworkStatusChange,
516+
"notifyOnNetworkStatusChange option only supported on watchQuery."
517+
);
517518

518-
checkDocument(options.query, OperationTypeNode.QUERY);
519+
checkDocument(options.query, OperationTypeNode.QUERY);
520+
}
519521

520522
return this.queryManager.query<TData, TVariables>(options);
521523
}

0 commit comments

Comments
 (0)