Schema Stitching扩展Mutation传递参数报错求助
Schema Stitching扩展Mutation参数传递错误解决
问题代码
extend type Mutation { space(value: SpaceInput): Int! @delegate(schema: "matterport", path: "space(value: $arguments:value)") }
错误信息
{ "errors": [ { "message": "The variable `__arguments_value` is not compatible with the type of the current location.", "locations": [ { "line": 2, "column": 5 } ], "path": [ "space" ], "extensions": { "variable": "__arguments_value", "variableType": "SpaceInput", "locationType": "SpaceInput!", "specifiedBy": "http://spec.graphql.org/October2021/#sec-All-Variable-Usages-are-Allowed", "remote": { "message": "The variable `__arguments_value` is not compatible with the type of the current location.", "path": [ "space" ], "extensions": { "variable": "__arguments_value", "variableType": "SpaceInput", "locationType": "SpaceInput!", "specifiedBy": "http://spec.graphql.org/October2021/#sec-All-Variable-Usages-are-Allowed" } }, "schemaName": "matterport" } } ] }
问题根源
- 参数必填性不匹配:远程
matterportschema中,spacemutation的value参数是必填类型SpaceInput!,但本地扩展的Mutation里定义的value是可选类型SpaceInput,导致传递的变量可能为null,不符合远程的非空要求。 - @delegate变量引用语法错误:路径中的变量引用应该用
$arguments.value而非$arguments:value,冒号是错误语法,会导致变量映射异常。
修复后的代码
extend type Mutation { space(value: SpaceInput!): Int! @delegate(schema: "matterport", path: "space(value: $arguments.value)") }
验证要点
- 确保本地定义的参数类型(包括必填性)和远程schema完全一致
- 检查@delegate指令的path参数中,变量引用的语法符合你使用的Schema Stitching工具规范(比如GraphQL Tools中使用
$arguments.参数名引用当前字段的参数)
内容的提问来源于stack exchange,提问作者Patrik Urban
相关产品推荐
相关产品推荐

