Я новичок в response-native и appsync, graphql. Мы пытаемся реализовать приложение appsync с использованием response-native, когда я пытался запустить его, выдает сообщение об ошибке
14:16:38: Must contain a query definition. * null:null in getQueryDefinition - node_modules/apollo-cache-inmemory/lib/bundle.umd.js:649:64 in diffQueryAgainstStore - node_modules/apollo-cache-inmemory/lib/bundle.umd.js:559:32 in readQueryFromStore - node_modules/apollo-cache-inmemory/lib/bundle.umd.js:899:38 in read - node_modules/apollo-cache-inmemory/lib/bundle.umd.js:992:23 in readQuery * null:null in update - node_modules/apollo-client/bundle.umd.js:1609:0 in - node_modules/apollo-utilities/lib/bundle.umd.js:818:21 in tryFunctionOrLogError * null:null in - node_modules/apollo-cache-inmemory/lib/bundle.umd.js:961:22 in performTransaction - node_modules/apollo-client/bundle.umd.js:1473:0 in markMutationResult - node_modules/apollo-client/bundle.umd.js:797:20 in next - node_modules/zen-observable-ts/node_modules/zen-observable/lib/Observable.js:150:3 in notifySubscription - node_modules/zen-observable-ts/node_modules/zen-observable/lib/Observable.js:195:5 in onNotify * null:null in next - node_modules/zen-observable-ts/node_modules/zen-observable/lib/Observable.js:150:3 in notifySubscription * null:null in flushSubscription - node_modules/zen-observable-ts/node_modules/zen-observable/lib/Observable.js:190:26 in * null:null in - node_modules/promise/setimmediate/core.js:37:14 in tryCallOne - node_modules/promise/setimmediate/core.js:123:25 in - ... 10 more stack frames from framework internals
Я попытался отследить ошибку в 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)
Пожалуйста, помогите мне!. Заранее спасибо
Только что обновил мой вопрос, пожалуйста, посмотрите





В этой строке:
const data = proxy.readQuery({ query: PostMessage });
Я не вижу ссылки на PostMessage, где вы хотите определить свой запрос.
пожалуйста, убедитесь, что у меня уже была ссылка, но все равно выдает ту же ошибку
Ошибка означает, что в импортированном PostMessage запрос найти не удалось. Убедитесь, что это выглядит так: (а не сокращенный эквивалент)
query postMessage($id: ID!) {
postMessage(id: $id) {
id
title
}
}
Спасибо за то, что @Karens помог мне исправить определение мутации.
Я решил эту ошибку, исправив мою мутацию, то есть PostMesssage в моем случае. Эта ошибка
Must contain a query definition
в основном возникает, если ваш запрос неверен, который вы написали на graphql. Начните видеть, как вы передаете свои переменные, как вы их используете и как вы их определяете.
Я также получил эту ошибку, когда добавил новые функции преобразователя (в новые файлы), но не смог включить ссылки на эти преобразователи в исполняемую схему graphql.
Не могли бы вы показать нам часть вашего редуктора? Я думаю, что ошибка может произойти в вашем действии "onSubmit". Потому что в вашем компоненте вы не ссылаетесь на кеш apollo