查询组件为数据返回 null 但网络显示响应
Query component returning null for data BUT network shows a response
数据为空,但是,我在 /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;
应将 FragmentMatcher 传递给 InMemoryCache 构造函数,而不是 ApolloClient 构造函数:
const cache = new InMemoryCache({ fragmentMatcher });
const client = new ApolloClient({
cache,
link: new HttpLink(),
});
数据为空,但是,我在 /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;
应将 FragmentMatcher 传递给 InMemoryCache 构造函数,而不是 ApolloClient 构造函数:
const cache = new InMemoryCache({ fragmentMatcher });
const client = new ApolloClient({
cache,
link: new HttpLink(),
});