Postgresql 为什么我';m我使用graphql获取保存日期时出错>;哈苏拉>;博士后
我使用react、apollo、graphql、hasura、postgres作为堆栈与数据库交互。我认为我的问题很小,所以我只关注不起作用的部分,而不是发布整个代码。 谢谢 如果我删除了生日,查询就会工作 下面是函数Postgresql 为什么我';m我使用graphql获取保存日期时出错>;哈苏拉>;博士后,postgresql,graphql,hasura,Postgresql,Graphql,Hasura,我使用react、apollo、graphql、hasura、postgres作为堆栈与数据库交互。我认为我的问题很小,所以我只关注不起作用的部分,而不是发布整个代码。 谢谢 如果我删除了生日,查询就会工作 下面是函数 const onUpdateUser = (options) => { updateUser({ variables: Object.assign({ id: userId }, options), optimisticResponse:
const onUpdateUser = (options) => {
updateUser({
variables: Object.assign({ id: userId }, options),
optimisticResponse: {
__typename: "mutation_root",
update_users: {
__typename: "users_mutation_response",
affected_rows: 1,
returning: [
{
__typename: "users",
id: userId,
...options,
},
],
},
},
});
};
输入
{birth:'1991-01-11'}
因此,如果不查看graphql查询,我想您可能会有点不太清楚
不能将不存在的变量动态添加到graphql查询中。错误是告诉您正在尝试添加查询中不存在的变量
i、 因为你还没有定义生日,所以这与工作无关
mutation updateUser(
$userId: Int!
$birthday (UNDEFINED)
) {
rest of query...
}
如果您需要添加动态数量的变量,您可以这样做
反应码
const onUpdateUser = (options) => {
updateUser({
variables: {
userId,
userVariables: options
},
optimisticResponse: {
__typename: "mutation_root",
update_users: {
__typename: "users_mutation_response",
affected_rows: 1,
returning: [
{
__typename: "users",
id: userId,
...options,
},
],
},
},
});
};
GraphQL突变
mutation updateUser(
$userId: Int!
$userVariables: user_set_input!
) {
update_user(
where: { id: { _eq: $userId} }
_set: $userVariables
) {
affected_rows
}
}
请提供更多导致此错误的javascript/Apollo代码-这不是Hasura问题,因为“1991-01-11”是Postgres规定的有效日期格式(在Heroku实例中使用相同模式进行测试)。我添加了函数代码。谢谢,请提供与updateUser对应的gql变体。看起来这个错误是由Hasura在进一步检查时报告的:,但这并不意味着它在上游是不可预防的。嘿,谢谢。我已经能够解决这个问题并超越这个:)
const onUpdateUser = (options) => {
updateUser({
variables: {
userId,
userVariables: options
},
optimisticResponse: {
__typename: "mutation_root",
update_users: {
__typename: "users_mutation_response",
affected_rows: 1,
returning: [
{
__typename: "users",
id: userId,
...options,
},
],
},
},
});
};
mutation updateUser(
$userId: Int!
$userVariables: user_set_input!
) {
update_user(
where: { id: { _eq: $userId} }
_set: $userVariables
) {
affected_rows
}
}