refinedev/refine · error · Error
[Code] Operation is required.
Error message
[Code] Operation is required.
What it means
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.
Source
Thrown at packages/graphql/src/dataProvider/index.ts:37
if (error?.graphQLErrors && error?.graphQLErrors.length > 0) {
const message = error.graphQLErrors
.map(({ message }) => message)
.join(", ");
errorMsg = `[GraphQL] ${message}`;
}
return errorMsg;
};
return {
create: async (params) => {
const { meta } = params;
const gqlOperation = meta?.gqlMutation ?? meta?.gqlQuery;
if (!gqlOperation) {
throw new Error("[Code] Operation is required.");
}
const response = await client
.mutation(gqlOperation, options.create.buildVariables(params))
.toPromise();
if (response?.error) {
throw new Error(errorHandler(response?.error));
}
const data = options.create.dataMapper(response, params);
return {
data,
};
},
createMany: async (params) => {
const { meta } = params;View on GitHub (pinned to 779d52a20e)
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
Example fix
// before
useForm({ refetchActionsAfterUpdate: false }); /* create without meta */
// after
const CREATE_POST = gql`mutation CreatePost($input: PostInput!) { createPost(input: $input) { id } }`;
useCreate({ meta: { gqlMutation: CREATE_POST } }); Defensive patterns
Strategy: validation
Validate before calling
const meta = { gqlMutation: CREATE_POST } satisfies Meta;
if (!meta.gqlMutation && !meta.gqlQuery) throw new Error('missing operation'); Type guard
const hasOperation = (m?: Meta) => !!m && (!!m.gqlMutation || !!m.gqlQuery);
Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- @packages/hasura: multiple filters present. Group multiple p
- [Code] Not implemented on refine-graphql data provider.
- GraphQL operation name required.
- GraphQL need to operation, fields and variables values in me
- GraphQL operation name required.
AI-assisted analysis of refinedev/refine@779d52a20e (2026-08-27).
Data as JSON: /api/errors/78f2d4681762572a.
Report an issue: GitHub.