{"record":{"id":"bb7c631540e284ee","repo":"floci-io/floci","slug":"badrequestexception-bb7c63","errorCode":"BadRequestException","errorMessage":"Missing operation name.","messagePattern":"Missing operation name\\.","errorType":"http","errorClass":"AppSyncTransportException","httpStatus":400,"severity":"error","filePath":"src/main/java/io/github/hectorvent/floci/services/appsync/graphql/QueryExecutor.java","lineNumber":40,"sourceCode":"public class QueryExecutor {\n\n    private final AppSyncErrorFormatter formatter;\n\n    @Inject\n    public QueryExecutor(AppSyncErrorFormatter formatter) {\n        this.formatter = formatter;\n    }\n\n    public Map<String, Object> execute(GraphQLSchema schema, String query,\n                                       Map<String, Object> variables, String operationName) {\n        return execute(SchemaRegistry.buildGraphQL(schema), query, variables, operationName);\n    }\n\n    public Map<String, Object> execute(GraphQL graphQL, String query,\n                                       Map<String, Object> variables, String operationName) {\n        List<OperationDefinition> operations = parseOperations(query);\n        if (operations.size() > 1 && (operationName == null || operationName.isBlank())) {\n            throw new AppSyncTransportException(400, \"BadRequestException\",\n                    AppSyncErrorFormatter.MSG_MISSING_OPERATION_NAME);\n        }\n\n        OperationDefinition selected = selectOperation(operations, operationName);\n        if (selected != null && selected.getOperation() == OperationDefinition.Operation.SUBSCRIPTION) {\n            ExecutionResult rejected = ExecutionResultImpl.newExecutionResult()\n                    .addError(GraphqlErrorBuilder.newError()\n                            .message(\"Subscriptions are not supported over HTTP\")\n                            .errorType(ErrorType.OperationNotSupported)\n                            .build())\n                    .build();\n            return formatter.format(rejected);\n        }\n\n        ExecutionInput.Builder inputBuilder = ExecutionInput.newExecutionInput().query(query);\n        if (variables != null) {\n            inputBuilder.variables(variables);\n        }","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/floci-io/floci/blob/62ff490619e7bd3554597c28c704081b4c15add5/src/main/java/io/github/hectorvent/floci/services/appsync/graphql/QueryExecutor.java#L22-L58","documentation":"A GraphQL execution request contained more than one operation definition (multiple anonymous or named operations) but no operationName was supplied, so the executor cannot know which one to run. Floci's QueryExecutor raises HTTP 400 BadRequestException 'Missing operation name.', matching AppSync's behavior for ambiguous documents.","triggerScenarios":"POSTing a document like 'query A { ... } query B { ... }' or 'query { ... } mutation { ... }' with no operationName field; also an anonymous query plus a named mutation in one document. Conversely, a single-operation document needs no operationName.","commonSituations":"Concatenating query fragments for convenience; shipping whole schema test documents; code that composes queries from multiple templates without selecting one.","solutions":["Add \"operationName\": \"NameOfOperation\" matching one top-level operation in the document.","Or split the document so the request contains exactly one operation.","If a library builds the request for you, set its operation-name option (e.g. graphql-request/mutation function name)."],"exampleFix":"// before\nfetch(url, { body: JSON.stringify({ query: 'query A { a } query B { b }' }) });\n\n// after\nfetch(url, { body: JSON.stringify({ query: 'query A { a } query B { b }', operationName: 'A' }) });","handlingStrategy":"validation","validationCode":"const ops = [...query.matchAll(/\\b(query|mutation|subscription)\\s+([A-Za-z]\\w*)/g)].map(m => m[2]);\nconst anon = /^\\s*(query|mutation|subscription)?\\s*[({]/m.test(query);\nif (ops.length + (anon ? 1 : 0) > 1 && !operationName) throw new Error('operationName required');","typeGuard":null,"tryCatchPattern":"catch (BadRequestException e) {\n    if (\"Missing operation name.\".equals(e.getMessage())) { /* set operationName to the intended op and retry */ }\n}","preventionTips":["One operation per request document; pass operationName whenever the document has more than one.","Let GraphQL client libraries manage operation selection.","Add a preflight check counting top-level operations in shared query documents."],"tags":["appsync","graphql","operation-selection","validation"],"backgroundTag":null,"analyzedSha":"62ff490619e7bd3554597c28c704081b4c15add5","analyzedAt":"2026-08-14T14:25:23.764Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}