{"record":{"id":"78f2d4681762572a","repo":"refinedev/refine","slug":"code-operation-is-required","errorCode":null,"errorMessage":"[Code] Operation is required.","messagePattern":"\\[Code\\] Operation is required\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/graphql/src/dataProvider/index.ts","lineNumber":37,"sourceCode":"\n    if (error?.graphQLErrors && error?.graphQLErrors.length > 0) {\n      const message = error.graphQLErrors\n        .map(({ message }) => message)\n        .join(\", \");\n      errorMsg = `[GraphQL] ${message}`;\n    }\n\n    return errorMsg;\n  };\n\n  return {\n    create: async (params) => {\n      const { meta } = params;\n\n      const gqlOperation = meta?.gqlMutation ?? meta?.gqlQuery;\n\n      if (!gqlOperation) {\n        throw new Error(\"[Code] Operation is required.\");\n      }\n\n      const response = await client\n        .mutation(gqlOperation, options.create.buildVariables(params))\n        .toPromise();\n\n      if (response?.error) {\n        throw new Error(errorHandler(response?.error));\n      }\n\n      const data = options.create.dataMapper(response, params);\n\n      return {\n        data,\n      };\n    },\n    createMany: async (params) => {\n      const { meta } = params;","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/refinedev/refine/blob/779d52a20e29b0307ac0df04d135beba434370dc/packages/graphql/src/dataProvider/index.ts#L19-L55","documentation":"The GraphQL data provider requires every create() call to carry a GraphQL document in params.meta (meta.gqlMutation preferred, or meta.gqlQuery). Without a document there is no operation to send, so it throws before contacting the client.","triggerScenarios":"Calling dataProvider.create({ resource, variables }) without setting meta: { gqlMutation: gql`...` } — e.g. relying on a default mutation like in REST providers, or using useCreate without meta.","commonSituations":"Switching a resource from a REST/other data provider to graphql without adding meta to mutation hooks; forgetting meta in useCreate/useModalForm; type generation setup where gql documents are imported lazily.","solutions":["Pass the mutation document: useCreate({ meta: { gqlMutation: CREATE_POST } })","If using codegen, ensure the generated document is actually passed via meta","For automatic documents, consider the live provider/strapi-graphql presets that inject operations"],"exampleFix":"// before\nuseForm({ refetchActionsAfterUpdate: false }); /* create without meta */\n// after\nconst CREATE_POST = gql`mutation CreatePost($input: PostInput!) { createPost(input: $input) { id } }`;\nuseCreate({ meta: { gqlMutation: CREATE_POST } });","handlingStrategy":"validation","validationCode":"const meta = { gqlMutation: CREATE_POST } satisfies Meta;\nif (!meta.gqlMutation && !meta.gqlQuery) throw new Error('missing operation');","typeGuard":"const hasOperation = (m?: Meta) => !!m && (!!m.gqlMutation || !!m.gqlQuery);","tryCatchPattern":null,"preventionTips":["Create a shared const per resource for its documents and always pass it via meta","Type-check meta with a helper so TS flags missing documents"],"tags":["graphql","data-provider","meta","mutation"],"backgroundTag":"missing-graphql-operation","analyzedSha":"779d52a20e29b0307ac0df04d135beba434370dc","analyzedAt":"2026-08-27T11:15:25.854Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}