{"record":{"id":"ce683f020e4391de","repo":"facebook/relay","slug":"metadata-directive-expect-only-constant-argumen","errorCode":null,"errorMessage":"@__metadata directive expect only constant argument values.","messagePattern":"@__metadata directive expect only constant argument values\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/crates/relay-codegen/src/build_ast.rs","lineNumber":396,"sourceCode":"    fn array(&mut self, array: Vec<Primitive>) -> AstKey {\n        self.ast_builder.intern(Ast::Array(array))\n    }\n\n    fn build_internal_metadata_directives(&mut self, directives: &[Directive]) -> Vec<ObjectEntry> {\n        directives\n            .iter()\n            .filter_map(|directive| {\n                if directive.name.item == *INTERNAL_METADATA_DIRECTIVE {\n                    if directive.arguments.len() != 1 {\n                        panic!(\"@__metadata directive should have only one argument!\");\n                    }\n\n                    let arg = &directive.arguments[0];\n                    let key = arg.name.item;\n                    let value = match &arg.value.item {\n                        Value::Constant(value) => self.build_constant_value(value),\n                        _ => {\n                            panic!(\"@__metadata directive expect only constant argument values.\");\n                        }\n                    };\n\n                    Some(ObjectEntry { key: key.0, value })\n                } else {\n                    None\n                }\n            })\n            .collect()\n    }\n\n    fn use_exec_time_resolvers(&self, context: &ContextualMetadata) -> bool {\n        let feature_flags = &self.project_config.feature_flags;\n        feature_flags.enable_resolver_normalization_ast\n            || (feature_flags.enable_exec_time_resolvers_directive\n                && context.has_exec_time_resolvers_directive\n                && !context.has_exec_time_resolvers_enabled_provider)\n    }","sourceCodeStart":378,"sourceCodeEnd":414,"githubUrl":"https://github.com/facebook/relay/blob/668b1b85e06261aa3b58dabfc51f8b5524a70955/compiler/crates/relay-codegen/src/build_ast.rs#L378-L414","documentation":"The @__metadata directive's single argument value must be a GraphQL constant (string, enum, etc.). build_internal_metadata_directives panics when the value is a variable or other non-constant Value, because metadata must be fully resolvable at compile time.","triggerScenarios":"Writing `@__metadata(parentType: $someVar)` or any variable/inline non-constant value; the match on Value::Constant falls through to the panic arm during build_fragment_metadata or build_request_parameters.","commonSituations":"Copy-pasting an argument with a variable from an operation into a @__metadata directive; tooling that injects variable references into metadata; misunderstanding that GraphQL variables aren't allowed in compiler-internal directives.","solutions":["Replace the variable with a literal constant value in the @__metadata argument.","Regenerate the fragment/operation through the compiler rather than hand-writing metadata.","If tooling generates these directives, fix the generator to emit Value::Constant values only.","Review Relay docs for the exact expected @__metadata argument shape (constant, single argument)."],"exampleFix":"// before\nfragment FooResolver on Query @__metadata(parentType: $parent) { ... }\n// after\nfragment FooResolver on Query @__metadata(parentType: \"Query\") { ... }\n","handlingStrategy":"validation","validationCode":"fn metadata_args_are_constant(d: &Directive) -> bool {\n    d.arguments.iter().all(|a| matches!(a.value.item, Value::Constant(_)))\n}\n","typeGuard":"fn is_constant(v: &Value) -> bool { matches!(v.item, Value::Constant(_)) }\n","tryCatchPattern":"let result = std::panic::catch_unwind(|| build_internal_metadata_directives(&directives));\nif result.is_err() { report(\"@__metadata argument must be a constant value\"); }\n","preventionTips":["Only use literal values in @__metadata arguments, never GraphQL variables.","Add a lint rejecting variables inside compiler-internal directives.","Fix code generators to emit constant values only."],"tags":["graphql","directive","metadata","constant-value"],"backgroundTag":"invalid-directive-argument","analyzedSha":"668b1b85e06261aa3b58dabfc51f8b5524a70955","analyzedAt":"2026-09-02T19:57:20.783Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}