首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >必须包含查询定义。

必须包含查询定义。
EN

Stack Overflow用户
提问于 2018-06-05 09:05:45
回答 4查看 2.3K关注 0票数 2

当我尝试运行它时,当我试图运行它时,graphql.we会抛出一个错误。

14:16:38:必须包含查询定义。* null:null中的null- 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在update -node_modules/ getQueryDefinition中为null-client/bundle.umd.js:1609:0 in - node_modules/apollo-utilities/lib/bundle.umd.js:818:21 in tryFunctionOrLogError * null:null 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_tryFunctionOrLogError/zen-可观察到-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/in *null:空in - node_modules/promise/setimmediate/core.js:37:14 in tryCallOne - node_modules/promise/setimmediate/core.js:123:25 in -.来自框架内部的10个堆栈帧

我试图跟踪阿波罗缓存中的错误,但当我按下“发送”按钮时,我找不到得到这个错误的one.Am。

代码语言:javascript
复制
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)

请帮帮我!.Thanks提前

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2018-06-07 05:24:40

我通过纠正我的突变( PostMesssage中的case.This错误)来解决这个错误。

必须包含查询定义。

主要发生在您的查询不正确时,您已经用graphql编写。开始查看您如何传递变量、如何使用它们以及如何定义它们。

票数 0
EN

Stack Overflow用户

发布于 2018-06-05 09:40:47

在这一行:

代码语言:javascript
复制
 const data = proxy.readQuery({ query: PostMessage });

我看不到要在其中定义查询的对PostMessage的引用。

票数 0
EN

Stack Overflow用户

发布于 2018-06-05 19:05:39

此错误意味着在导入的PostMessage中找不到查询。确保它看起来像这样:(而不是速记等效的)

代码语言:javascript
复制
query postMessage($id: ID!) {
    postMessage(id: $id) {
        id
        title
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50696244

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档