{"record":{"id":"6a3056d8ab3a667e","repo":"marmelab/react-admin","slug":"unable-to-determine-the-query-operation","errorCode":null,"errorMessage":"Unable to determine the query operation","messagePattern":"Unable to determine the query operation","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/ra-data-graphql/src/index.ts","lineNumber":273,"sourceCode":"};\n\nconst handleError = (error: ApolloError) => {\n    if (error?.networkError as ServerError) {\n        throw new HttpError(\n            (error?.networkError as ServerError)?.message,\n            (error?.networkError as ServerError)?.statusCode\n        );\n    }\n\n    throw new HttpError(error.message, 200, error);\n};\n\nconst getQueryOperation = query => {\n    if (query && query.definitions && query.definitions.length > 0) {\n        return query.definitions[0].operation;\n    }\n\n    throw new Error('Unable to determine the query operation');\n};\n\nexport type GetIntrospection = () => Promise<IntrospectionResult>;\nexport type GraphqlDataProvider = DataProvider & {\n    getIntrospection: GetIntrospection;\n    client: ApolloClient<unknown>;\n};\n\nexport default buildGraphQLProvider;\n","sourceCodeStart":255,"sourceCodeEnd":283,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-data-graphql/src/index.ts#L255-L283","documentation":"getQueryOperation extracts operation ('query' or 'mutation') from a parsed GraphQL document's first definition. If the document is null/undefined, has no definitions array, or is empty, the operation cannot be determined and the helper throws.","triggerScenarios":"Passing a null/empty/invalid parsed query (DocumentNode) to the provider machinery — e.g. a gql`` template producing an empty document, or a variable holding undefined instead of a parsed document — flowing into operation()/getQueryOperation.","commonSituations":"Typo in gql tag usage, conditional query building that yields an empty string, a custom buildQuery returning undefined query for a fetch type, or corrupted cached documents.","solutions":["Ensure the query passed is a valid non-empty gql document: check it with console.log(query).","Fix conditional template strings so they always produce at least one definition.","Verify your custom buildQuery/buildGqlQuery returns a query for every fetch type.","Validate the document parses: gql`query { ... }` instead of an empty string."],"exampleFix":"// before\nconst query = condition ? gql`query { ... }` : '';\n// after\nconst query = condition ? gql`query { ... }` : gql`query { noop }`;","handlingStrategy":"type-guard","validationCode":"const isValidDoc = (q: unknown): boolean =>\n  !!q && typeof q === 'object' &&\n  Array.isArray((q as any).definitions) &&\n  (q as any).definitions.length > 0;\nif (!isValidDoc(query)) throw new Error('Query must be a non-empty DocumentNode');","typeGuard":"const isDocumentNode = (q: unknown): q is DocumentNode =>\n  typeof q === 'object' && q !== null &&\n  'definitions' in q && Array.isArray((q as DocumentNode).definitions) &&\n  (q as DocumentNode).definitions.length > 0;","tryCatchPattern":"try {\n  return await dataProvider.getList(resource, params);\n} catch (e) {\n  if (e.message === 'Unable to determine the query operation') {\n    console.error('Invalid/empty GraphQL document passed to provider', e);\n  }\n  throw e;\n}","preventionTips":["Always build queries with gql`` template literals, never raw strings or conditionals yielding empty strings.","Unit-test custom buildQuery implementations for every fetch type.","Assert documents are non-empty DocumentNodes in dev builds."],"tags":["graphql","query-parsing","ra-data-graphql"],"backgroundTag":"invalid-graphql-document","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}