什么是错的这个基本apolloClient查询?
import gql from 'graphql-tag'
export default (context, apolloClient, userId) => (
apolloClient.query({
query: gql`
query RootQueryType($userId: ID!) {
verifyUser(
id: $userId
) {
id,
token
}
},
`,
options: {
variables: { userId: userId }
}
}).then(({ data }) => {
return { loggedInUser: data }
}).catch((error) => {
console.log(error)
return { loggedInUser: {} }
})
)
我得到的错误Error: GraphQL error: Variable "$userId" of required type "ID!" was not provided.
。但我设置的选项和变量与此数据。我不知道,我做错了。
第一个用户ID应该是ID,而不是用户ID,还应该定义为阿波罗服务器,以符合您查询ID ..
更改:
options: {
variables: { userId: userId }
}
至:
options: {
variables: { id: userId }
}
我认为你必须在查询定义的问题:
gql `
query RootQueryType($userId: ID!) {
verifyUser(
userId: $userId // here you need the parameter to be userId
) {
id,
token
}
}`