Apollo GQL USEMUNT不会返回数据字段
我有以下在沙箱中工作正常的突变(它创建并返回书签):
mutation CreateBookmark ($options: BookmarkInput!) {
createBookmark(options: $options) {
bookmark {
id
title
url
}
}
}
当我尝试从我的React应用程序创建书签时,正在创建书签,但数据不确定。
这是我的代码:
const CREATE_BOOKMARK = gql`
mutation CreateBookmark($options: BookmarkInput!) {
createBookmark(options: $options) {
bookmark {
id
title
url
}
}
}
`;
const [mutateFunction, {data, error, loading}] = useMutation(CREATE_BOOKMARK);
mutateFunction({
variables: {
options: {
title: bookmark.title,
url: bookmark.url,
},
},
});
当我尝试console.log(data)
时,它会返回未定义。
我还试图不破坏这样返回的对象:
const [mutateFunction, obj] = useMutation(CREATE_BOOKMARK);
当i console.log(obj)
时,它返回以下内容:
{
error: ...,
loading: ...,
client: ...,
reset: ...
}
如您所见,没有数据字段。为什么会发生这种情况?
I have the following mutation that works just fine in the Sandbox (it creates and returns the bookmark):
mutation CreateBookmark ($options: BookmarkInput!) {
createBookmark(options: $options) {
bookmark {
id
title
url
}
}
}
When I try to create a bookmark from my react app, the bookmark is being created but data is undefined.
This is my code:
const CREATE_BOOKMARK = gql`
mutation CreateBookmark($options: BookmarkInput!) {
createBookmark(options: $options) {
bookmark {
id
title
url
}
}
}
`;
const [mutateFunction, {data, error, loading}] = useMutation(CREATE_BOOKMARK);
mutateFunction({
variables: {
options: {
title: bookmark.title,
url: bookmark.url,
},
},
});
When I try to console.log(data)
it returns undefined.
I have also tried to not destructure the object that is being returned like this:
const [mutateFunction, obj] = useMutation(CREATE_BOOKMARK);
When I console.log(obj)
, it returns this:
{
error: ...,
loading: ...,
client: ...,
reset: ...
}
As you can see, there is no data field. Why is this happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论