数据为空,但是,我在/ grahpql和网络中都看到了响应。
查询内容:准系统:
query GetProductById($product_id: Int!) {
getProductById(product_id: $product_id) {
id
product_id
name
product_type
create_time
update_time
sizes
click_url
price
discount_price
coupon_code
sale_date
sku
colors
in_stock
regions {
...domestic
...international
}
}
}
编辑:更新:将此内容缩小到:::
regions {
...domestic
...international
}
我认为这是问题。.不?
import { IntrospectionFragmentMatcher } from 'apollo-cache-inmemory';
const fragmentMatcher = new IntrospectionFragmentMatcher({
introspectionQueryResultData: {
__schema: {
types: [
{
kind: 'INTERFACE',
name: 'Regions',
possibleTypes: [
{
name: 'domestic'
},
{
name: 'international'
}
]
}
]
}
}
});
export default fragmentMatcher;
import fragmentMatcher from './RegionFragmentMatcher';
const cache = new InMemoryCache();
const apolloClient = new ApolloClient({
fragmentMatcher,
cache,
link: new HttpLink({
uri: `${config.url}/graphql`,
credentials: 'include'
}),
resolvers: Resolvers(cache),
addTypename: true,
dataIdFromObject,
introspection: true
});
export default apolloClient;
答案 0 :(得分:2)
应该将FragmentMatcher传递给InMemoryCache构造函数,而不是ApolloClient构造函数:
const cache = new InMemoryCache({ fragmentMatcher });
const client = new ApolloClient({
cache,
link: new HttpLink(),
});