Calling the same query multiple times concatenates the results selector
krstns opened this issue · 2 comments
I'm calling two queries for the same model, one is used for searching and the other one for retrieving details.
After several queries, I started to receive errors from the server, upon a quick check I saw that the result selector gets concatenated with the previously used and grows to astronomical sizes.
I've tried to trace the issue but my knowledge of the inner works of mst-gql doesn't allow me to go too far.
I've checked that my methods make queries using the correct selector but right after the query call in the createActionInvoker
the context
already contains the query concatenated.
The way the queries are used:
this.dataService.searchPeopleByLastName(searchText).then(
(d) => {
this.processClientResults(d.people.collection);
},
(e) => {
console.log(`search failed: ${e}`);
}
);
where the searchPeopleByLastName
is nothing but:
public searchPeopleByLastName(lastName: string): Query<{ people: PersonConnectionModelType }> {
return this._rootStore.queryPeople(
{lastName: lastName},
selectFromPersonConnection()
.collection(
selectFromPerson().id.firstName.lastName. [...]
)
.toString()
);
}
I have pasted this if it makes any difference.
What is sure is that the queries are made quickly one after another. It's possible that one will not finish before the other one is made (results taken from cache).
Is there something I could do to mitigate this?
If nobody else posted a similar issue, it means that it's something related to my flow, but I would appreciate any help finding out what it is.
This is now becoming a showstopper for us.
I understand the project is almost dead, I don't expect anyone to work on that, however any kind of tip regarding where I could start my investigation would be helpful.
The query is being concatenated with previous calls and suddenly our server gets a request to return 10 times the same results.
just a simple example. In our code, when making the following query:
public queryAnimal(animal: string): Query<{ animal: AnimalModelType }> {
return this._rootStore.queryAnimal(
{ id: animal },
selectFromAnimal()
.people(selectFromAnimalPerson().person(selectFromPerson()))
.toString()
);
}
here's what's being sent to the server:
query animal($id: ID!) { animal(id: $id) {
__typename
id
people {
__typename
id
person {
__typename
id
}
animal {
__typename
id
}
person {
__typename
id
}
person {
__typename
id
}
}
}
}
First of all: the person
is sent 3x instead of 1x as requested.
The second is the animal
entry on the 2nd level. It's not requested at all in this call and it's added automatically.
The only idea I have is that somehow it concatenates selectors from a different query with this one, but without any guidance/tips on where to start searching I don't think I am able to work with that.
It will be greatly appreciated if you could give me a hand with this.
@beepsoft sorry to bother you but it seems like you're the only hope I've got now :)
Upon more debugging it became obvious...
We were misusing the automatically generated primitves. We cannot do *primite. as it will be modified in the memory and always called like that.