【发布时间】:2018-11-14 17:07:32
【问题描述】:
我是 react-native 和 appsync 的新手,graphql。我们正在尝试使用 react-native 实现一个 appsync 应用程序,当我尝试运行它时会抛出一个错误提示
14:16:38:必须包含查询定义。 * null:getQueryDefinition 中的 null - diffQueryAgainstStore 中的 node_modules/apollo-cache-inmemory/lib/bundle.umd.js:649:64 - readQueryFromStore 中的 node_modules/apollo-cache-inmemory/lib/bundle.umd.js:559:32 - 读取中的 node_modules/apollo-cache-inmemory/lib/bundle.umd.js:899:38 - readQuery 中的 node_modules/apollo-cache-inmemory/lib/bundle.umd.js:992:23 * null:null 在更新 - node_modules/apollo-client/bundle.umd.js:1609:0 在 - node_modules/apollo-utilities/lib/bundle.umd.js:818:21 在 tryFunctionOrLogError * 空:空在 - node_modules/apollo-cache-inmemory/lib/bundle.umd.js:961:22 在 performTransaction - node_modules/apollo-client/bundle.umd.js:1473:0 在 markMutationResult - 接下来的 node_modules/apollo-client/bundle.umd.js:797:20 - node_modules/zen-observable-ts/node_modules/zen-observable/lib/Observable.js:150:3 in notifySubscription - onNotify 中的 node_modules/zen-observable-ts/node_modules/zen-observable/lib/Observable.js:195:5 * null:null 在下一个 - node_modules/zen-observable-ts/node_modules/zen-observable/lib/Observable.js:150:3 in notifySubscription * null:flushSubscription 中的 null - node_modules/zen-observable-ts/node_modules/zen-observable/lib/Observable.js:190:26 in * 空:空在 - tryCallOne 中的 node_modules/promise/setimmediate/core.js:37:14 - node_modules/promise/setimmediate/core.js:123:25 在 - ... 来自框架内部的另外 10 个堆栈帧
我试图找出 apollo-cache 中的错误,但我找不到。当我按下发送按钮时,我得到了这个。
import React, { Component } from 'react';
import { KeyboardAvoidingView, Text, Button, TextInput, StyleSheet, Alert } from 'react-native';
export default class ChatInput extends Component {
constructor(props) {
super(props);
this.userid = props.userid;
this.state = {
text: ''
}
}
handleSend = () => {
if (this.state.text === '') {
return false;
}
const chat = {
userid: this.userid,
text: this.state.text,
createdAt: new Date().toISOString()
}
this.props.onSubmit(chat);
this.setState({
text: ''
})
this.textInput.clear();
}
render() {
return (
<KeyboardAvoidingView>
<TextInput ref={input => { this.textInput = input }} placeholder="Message.."
onChangeText={(text) => this.setState({text})} onSubmitEditing={this.handleSend}
autoFocus={true} blurOnSubmit={false} returnKeyType="send"></TextInput>
<Button title="Send" onPress={this.handleSend}></Button>
</KeyboardAvoidingView>
);
}
}
const ChatInputData = compose(
graphql(PostMessage, {
options: {
fetchPolicy: 'no-cache'
},props: (props) => ({
onSubmit: chat => {
props.mutate({
variables: chat,
optimisticResponse: {
__typename: 'Mutation',
post: {
__typename: ChatHistory,
id: chat.createdAt,
userid: chat.userid,
text: chat.text,
createdAt: chat.createdAt
}
},
update: (proxy, {data: {post}}) => {
const data = proxy.readQuery({ query: PostMessage });
data.listPostMessages.items.push(Object.assign({}, post));
proxy.writeData({query: listPostMessages, data});
}
})
}
})
})
)(ChatInput)
请帮帮我!提前谢谢
【问题讨论】:
-
你能给我们看看你的减速器的一部分吗?我认为错误可能发生在您的“onSubmit”操作中。因为在你的组件中你没有引用 apollo 缓存
-
刚刚更新了我的问题,请看一下
标签: reactjs react-native graphql react-apollo aws-appsync