Given a list of usernames and the following query to GITHUB API
:-
query.gql:
query USER_QUERY($username:String!){
user(login: $username){
name
repositories(isFork:false){
totalCount
}
}
}
I want to create a composite query
for every username
.
Example:
Let's say this is the list of usernames
array usernames=["Sheldon","Leonard","Raj","Holowitz"]
Expected Query:
{
sheldon:user(login: "sheldon") {
name
repositories(isFork: false) {
totalCount
}
}
leonard:user(login: "leonard") {
name
repositories(isFork: false) {
totalCount
}
}
raj:user(login: "raj") {
name
repositories(isFork: false) {
totalCount
}
}
holowitz:user(login: "holowitz") {
name
repositories(isFork: false) {
totalCount
}
}
Is there any react
ive-way to achieve the result?
There is no
react
ive way for this - react is not for glue string templates.Your expected query is not constructed in the right graphQL way. It might work but you shouldn't think that way - when you need array - just ask for an array. If you really need this kind of structure do it (conversion) after feching 'normal' array - it's a matter of one-liner
.filter()
fn. Don't expect this (strange) format (behavoiur) from universal response.Read related answers for this and this.
Even calling separate queries may be batched by apollo.