变量“”已将NonNull类型'String!强制为Null值!” GraphQl错误

时间:2019-12-18 13:02:48

标签: react-native

我正在尝试将groupChatName保存为TextInput的值,并将该名称保存在后端,但是这样做时出现错误“可能未处理的承诺,数据:null,变量'groupChatName'已将NonNull的值强制为Null类型“字符串””,路径:空。

export const createGroupChat = `mutation createGroupChat($groupChatName:String! $messages:String $createdUser:String! $users:String) { createGroupChat(input:{ groupChatName:$groupChatName messages:$messages createdUser:$createdUser users:$users }){ groupChatName messages createdUser users } }`;

  const [currentUser, setCurrentUser] = useState('');
  const [value, setValue] = useState('');
  const [groupChatName, setGroupChatName] = useState('');


  useEffect(() => {
    Auth.currentAuthenticatedUser()
    .then(currentUser => setCurrentUser(currentUser)) 
    .catch (() => setUsername(null));
    }, []);

  GroupChat = () => {
    if (value.length > 0) {
      setValue('')
      setGroupChatName('')
      props.navigation.navigate('Message', { value });
    }
  };

  GroupChatMutation = async () => {
    const GroupChatDetails = { groupChatName, currentUser };
    const newGroupChat = await API.graphql(graphqlOperation(createGroupChat, { GroupChatDetails }));
    console.log(JSON.stringify(newGroupChat));

  };

  return (
    <View style={styles.container}>
            <Text style={styles.header}>Create GroupChat Name</Text> 
            <View style={styles.textInputContainer}>
                    <TextInput 
                            style={styles.textInput}
                            multiline={true}
                            placeholder={'Type in a GroupChatName'}
                            placeholderTextColor="#abbabb"
                            value={value}
                            onChangeText={value => setValue(value)}
                            onChange={value => setGroupChatName(value)}



                    />
.......```

0 个答案:

没有答案