自定义字段未保存

问题描述

我尝试通过使用WPGraphQL向用户添加自定义用户字段。因此,我尝试在官方WPGraphQL文档https://docs.wpgraphql.com/extending/fields/#register-fields-to-the-schema中重新创建示例:

add_action('graphql_init',function () {
  $hobbies = [
    'type'        => ['list_of' => 'String'],'description' => __('Custom field for user mutations','your-textdomain'),'resolve'     => function ($user) {
      $hobbies = get_user_meta($user->userId,'hobbies',true);
      return !empty($hobbies) ? $hobbies : [];
    },];

  register_graphql_field('User',$hobbies);
  register_graphql_field('CreateUserInput',$hobbies);
  register_graphql_field('UpdateUserInput',$hobbies);
});

我已经将类型从\WPGraphQL\Types::list_of( \WPGraphQL\Types::string() )更改为['list_of' => 'String']

如果我现在执行updateUser突变,我的兴趣爱好就不会更新。我在干什么错?

突变:

mutation MyMutation {
  __typename
  updateUser(input: {clientMutationId: "tempId",id: "dXNlcjox",hobbies: ["football","gaming"]}) {
    clientMutationId
    user {
      hobbies
    }
  }
}

输出:

{
  "data": {
    "__typename": "RootMutation","updateUser": {
      "clientMutationId": "tempId","user": {
        "hobbies": []
      }
    }
  }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)