{"record":{"id":"84522eda888f699a","repo":"facebook/relay","slug":"fetchquery-invalid-fetchpolicy-fetchpolicy","errorCode":null,"errorMessage":"fetchQuery: Invalid fetchPolicy ${fetchPolicy}","messagePattern":"fetchQuery: Invalid fetchPolicy (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/relay-runtime/query/fetchQuery.js","lineNumber":178,"sourceCode":"        ).map(readData);\n      } else {\n        observable = getNetworkObservable<$FlowFixMe>(\n          environment,\n          operation,\n        ).map(readData);\n      }\n      environment.__log({\n        name: 'fetchquery.fetch',\n        operation,\n        fetchPolicy,\n        queryAvailability,\n        shouldFetch,\n      });\n      return observable;\n    }\n    default:\n      fetchPolicy as empty;\n      throw new Error('fetchQuery: Invalid fetchPolicy ' + fetchPolicy);\n  }\n}\n\nfunction getNetworkObservable<TQuery extends OperationType>(\n  environment: IEnvironment,\n  operation: OperationDescriptor,\n): RelayObservable<TQuery['response']> {\n  return fetchQueryInternal\n    .fetchQuery(environment, operation)\n    .map(() => environment.lookup(operation.fragment));\n}\n\nmodule.exports = fetchQuery;\n","sourceCodeStart":160,"sourceCodeEnd":192,"githubUrl":"https://github.com/facebook/relay/blob/668b1b85e06261aa3b58dabfc51f8b5524a70955/packages/relay-runtime/query/fetchQuery.js#L160-L192","documentation":"fetchQuery validates the fetchPolicy argument against a switch of known policies ('network-only', 'store-or-network', etc.). The default case is reached when the caller passes an unrecognized or misspelled policy, so Relay throws instead of silently falling back to a default.","triggerScenarios":"Calling environment.fetchQuery(query, variables, {fetchPolicy: '...'}) or environment.executeWithFetchPolicy with a policy string other than store-only, store-or-network, store-and-network, or network-only — e.g. a typo like 'network_first' or a policy copied from a different library like 'cache-first'.","commonSituations":"Copy-pasting Apollo Client fetch policies (cache-first, network-first) into Relay code; hand-rolled string variables typed loosely; version drift where an experimental policy was removed or renamed.","solutions":["Use one of the supported policies: 'store-only' | 'store-or-network' | 'store-and-network' | 'network-only'","Import the FetchPolicy type from relay-runtime and annotate the option so typos are caught at compile time","If porting from Apollo, map the old policy to the closest Relay equivalent (e.g. network-first -> store-or-network with network-only for forced refresh)","Check the installed relay version's fetchQuery.js switch to confirm the policy still exists"],"exampleFix":"// before\nfetchQuery(env, query, vars, {fetchPolicy: 'cache-first'});\n// after\nfetchQuery(env, query, vars, {fetchPolicy: 'store-or-network'});","handlingStrategy":"validation","validationCode":"const VALID = ['store-only','store-or-network','store-and-network','network-only'];\nif (fetchPolicy != null && !VALID.includes(fetchPolicy)) throw new TypeError(`Invalid fetchPolicy: ${fetchPolicy}`);\nfetchQuery(env, query, vars, {fetchPolicy});","typeGuard":"const isFetchPolicy = (p) => ['store-only','store-or-network','store-and-network','network-only'].includes(p);","tryCatchPattern":"try {\n  fetchQuery(env, q, vars, {fetchPolicy});\n} catch (e) {\n  if (String(e.message).startsWith('fetchQuery: Invalid fetchPolicy')) {\n    console.error('Bad fetchPolicy, falling back to store-or-network');\n  } else throw e;\n}","preventionTips":["Annotate options with the FetchPolicy type so typos fail at compile time","Never hand-write policy strings; use constants or literals checked by TS","Don't import Apollo policy names into Relay code","Re-check policies after Relay upgrades"],"tags":["relay","fetch-policy","invalid-argument","developer-error"],"backgroundTag":"invalid-enum-value","analyzedSha":"668b1b85e06261aa3b58dabfc51f8b5524a70955","analyzedAt":"2026-09-02T19:57:20.783Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}