我有一个React/Apollo应用程序,它总是让我的数据混乱和错误.数据在网络判断器中看起来是正确的,但当阿波罗返回时,它会改变它.
返回的记录应该是这样的:
{
id: 12345,
name: 'some record',
status: { id: 1, name: 'Active' }
types: [
{ id: 1, name: 'Client' },
{ id: 4, name: 'Example' }
],
// ... more props
}
当我在Chrome中查看网络判断器中的原始响应时,它们确实是这样的.
阿波罗返回的记录是这样的:
{
id: 12345,
name: 'some record',
status: { id: 1, name: 'Client' } // <-- The word "Active" gets changed to "Client"
types: [
{ id: 1, name: 'Client' },
{ id: 4, name: 'Example' }
],
// ... more props
}
我假设Apollo是试图所有花哨和酷试图"缓存"记录或其他东西,它假设状态ID和类型ID是相同的.所以它看到www.example.com是1,所以它假设这与类型ID是1相同的.
我怎么才能关掉阿波罗所有的花哨愚蠢的"功能"?
编辑:屏幕截图
This is the raw data printed from the console, the console.log of my useQuery
hook data:
This is the raw output that I see in the Network inspector:
我没有解释为什么这些出来不同除了阿波罗做一些奇怪的内部逻辑.回答是正确的,但阿波罗一把还给我就不一样了.
我的代码:
const { data, refetch } = useQuery(gql`
query GetScoreAudit(
$page: Int, $pageSize: Int, $search: String,
$orderBy: String, $order: Order,
$status: Int, $type: Int
) {
scoreAudit(
page: $page, pageSize: $pageSize, search: $search,
orderBy: $orderBy, order: $order,
status: $status, type: $type
) {
total
nodes {
id
name
managedWorkstations
managedServers
firewall
wpsCompliance
maxWpsCompliance
mrr
tpe
status {
id
name
}
types {
id
name
}
serviceCompanies {
service
exists
}
}
}
}
`, {
variables: {
page: tableOpts.pagination.page,
pageSize: tableOpts.pagination.pageSize,
search: tableOpts.filters.search,
orderBy: tableOpts.orderBy,
order: tableOpts.order,
status: tableOpts.filters.status,
type: tableOpts.filters.type
}
});
console.log(data);