Apollo - Uncaught (in promise) 错误:网络错误:无法读取未定义的属性“种类”
Posted
技术标签:
【中文标题】Apollo - Uncaught (in promise) 错误:网络错误:无法读取未定义的属性“种类”【英文标题】:Apollo - Uncaught (in promise) Error: Network error: Cannot read property 'kind' of undefined 【发布时间】:2018-04-28 14:00:13 【问题描述】:我正在使用 GraphQL 和 Apollo 编写一个简单的登录表单。每次用户登录后,它都会重新获取查询以获取用户数据。
import React, Component from 'react'
import AuthForm from './AuthForm'
import loginMutation from '../mutations/Login'
import graphql from 'react-apollo'
import userQuery from '../queries/CurrentUser'
//App.js
...
const networkInterface = createNetworkInterface(
uri: '/graphql',
opts:
credentials: 'same-origin',
)
const client = new ApolloClient(
dataIdFromObject: o => o.id,
networkInterface
)
...
//Login.js
class LoginForm extends Component
onSubmit( email, password )
this.props.mutate(
variables: email, password ,
refetchQueries: [ userQuery, varibles: null ]
)
render()
return (
<div>
<h3>Login</h3>
<AuthForm onSubmit= this.onSubmit.bind(this) />
</div>
)
export default graphql(loginMutation)(LoginForm)
//userQuery.js
import gql from 'graphql-tag'
export default gql`
user
id
email
`
问题是用户可以登录,但没有重新获取用户查询。相反,我不断收到此错误消息:
Uncaught (in promise) Error: Network error: Cannot read property 'kind' of undefined at new ApolloError (bundle.js:6231)
。
我找不到这个问题的原因。那么,谁能帮我解决这个问题,
【问题讨论】:
【参考方案1】:refetchQueries: [ userQuery, varibles: null ]
在refetchQueries
属性的数组中,您有一个对象userQuery
,您正在解构该对象,解构后该对象将是 userQuery: userQuery
。 Apollo 客户端无法识别此属性,它应该是 query: userQuery
。您在varibles: null
中也有拼写错误。应该是variables: null
。
更正的代码:
onSubmit( email, password )
this.props.mutate(
variables: email, password ,
refetchQueries: [ query: userQuery, variables: null ]
)
【讨论】:
以上是关于Apollo - Uncaught (in promise) 错误:网络错误:无法读取未定义的属性“种类”的主要内容,如果未能解决你的问题,请参考以下文章
Macbook pro 13" compile Apollo 2.5
Uncaught (in Promise) DOMException: play() 只能由用户手势启动
Uncaught (in promise) TypeError: Cannot set properties of null (setting 'innerText') in OpenWetherMa