@apollo/client Version: 3.4.16
My question is :
Does the type-level merge:true
policy deeply merge the object? Why the type policy added to ProcessorType
could merge priceInfo
but the type policy added to CoreType
could not work?
The example extended from #5762.
Schema is like this:
const PriceInfoType = new GraphQLObjectType({
name: 'PriceInfoType',
fields: {
rawPrice: {
type: GraphQLString,
}
}
})
const ProcessorType = new GraphQLObjectType({
name: 'ProcessorType',
fields: {
priceInfo: {
type: PriceInfoType,
},
model: {
type: GraphQLString,
},
clockSpeed: {
type: GraphQLInt,
}
}
})
const CoreType = new GraphQLObjectType({
name: 'CoreType',
fields: {
cpu: {
type: ProcessorType,
}
}
})
const ComputerType = new GraphQLObjectType({
name: 'ComputerType',
fields: {
id: {
type: GraphQLID,
},
name: {
type: GraphQLString,
},
core: {
type: CoreType,
}
}
})
Given that we cache some data with a query (MODEL_AND_PRICE_QUERY
) like this:
query ModelAndPrice {
computer {
id
core {
cpu {
priceInfo {
rawPrice
}
model
}
}
}
}
and later in the program run a query (CLOCK_SPEED_QUERY
) like this (with cache-first fetch policy):
query ClockSpeed {
computer {
id
core {
cpu {
clockSpeed
}
}
}
}
When cache policy is like this:
typePolicies: {
ProcessorType: {
merge: true
},
},
The cpu data (ProcessorType
) could be deep merged, including its non-normalized field priceInfo(PriceInfoType
)
When cache policy is added to the parent type CoreType
, like this:
typePolicies: {
CoreType: {
merge: true
},
},
The cpu data (ProcessorType
) could not be deep merged , with priceInfo(PriceInfoType
) overwritten by query ClockSpeed.
How to reproduce the issue:
Here is a reproduction of the issue: GitHub - Fishfaceeast/apollo-client-issue-2 at 3.4.16
Checkout branch 3.4.16 and start the app.
Click Model&Price
button - The program fetches data. Then Model and price data is dislayed
Click Clock speed
button - The program fetches data. Model and price data is overwritten by clock speed data.
Click Model&Price
again - Model and price data is gone from the cache. The program fetches data again.