-
Hi, I have the following models (a stripped down version but the essentials are here) const Site = types
.model("Site", {
id: types.identifier,
name: types.string,
// these are external IDs, not related to my app, needed as strings for display
associatedIds: types.maybeNull(types.array(types.string)),
}).preProcessSnapshot(snapshot => {
console.log(snapshot);
return snapshot;
})
.actions(...);
const SiteStore = types
.model("SiteStore", {
items: types.optional(types.map(Site), {}),
}) .actions(self => {
/* eslint-disable no-param-reassign */
const { apolloClient } = getEnv(self);
return {
find: flow(function* find(id) {
if (self.items.has(id)) {
return self.items.get(id);
}
try {
const response = yield apolloClient.query({
query: gql`
{
site(id: "${id}") {
...SiteFullDetails
}
}
${siteFragments.fullDetails}
`,
});
const item = self.track(response.data.site);
return Promise.resolve(item);
} catch (error) {
return Promise.reject(error);
}
}),
track(entity) {
if (!self.items.has(entity.id)) {
console.log(entity);
return self.items.put(input);
}
return self.items.get(entity.id);
}, When retrieved from the API, in What am I doing wrong?
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @the-noob! The |
Beta Was this translation helpful? Give feedback.
-
Hi @EmilTholin - sorry for wasting your time, found the issue, close to PEBKAC. The mobx models mirror the GQL entities and we are using ApolloClient queries. The response has some extra
As you can see from my example above, I was logging |
Beta Was this translation helpful? Give feedback.
Hi @EmilTholin - sorry for wasting your time, found the issue, close to PEBKAC.
I've updated the sandbox example just for completeness and will describe the issue here, maybe it helps someone.
The mobx models mirror the GQL entities and we are using ApolloClient queries. The response has some extra
__typename
field and I made a function to remove that.