Last active
January 12, 2023 18:23
-
-
Save alanzhao/b2b46b369a28781549bcec16a78d9f44 to your computer and use it in GitHub Desktop.
Dataloader testing script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { gql, request, GraphQLClient } = require('graphql-request'); | |
let query1 = gql` | |
query offers_getProductOfferById($offerId: ID!) { | |
getProductOfferById(offerId: $offerId) { | |
storeId | |
parentId | |
offerId | |
campaignId | |
offerValue | |
startDate | |
endDate | |
} | |
} | |
`; | |
let query2 = gql` | |
query web_getShoppingUpdatesCards($userId: ID!, $generateNew: Boolean, $offset: Int, $generateAlgo: String, $viewed: Boolean = true, $limit: Int = 25) { | |
getShoppingUpdatesCards( | |
userId: $userId | |
generateNew: $generateNew | |
offset: $offset | |
generateAlgo: $generateAlgo | |
viewed: $viewed | |
limit: $limit | |
) { | |
data { | |
recommendedOffers { | |
offer { | |
offerId | |
offerValue | |
endDate | |
} | |
} | |
} | |
} | |
} | |
`; | |
let variables1 = { | |
offerId: '053f3605-1b54-49bc-99d1-0933c9887d33', | |
}; | |
let variables2 = { | |
offerId: '00000002-c7ce-4957-9f8f-5109ec7f8ec7', | |
}; | |
let variables3 = { | |
userId: '352485277868873860', | |
}; | |
let variables4 = { | |
userId: '368926010070403076' | |
} | |
const endpoint = 'http://localhost:30000/graphql'; | |
const client = new GraphQLClient(endpoint, { headers: { | |
'Content-Type': 'application/json', | |
'Auth-Context': '8029046904314652934',//'286803396832599162', | |
'service-name': 'honey-extension', | |
'service-version': '13.8.0', | |
'device-id': 'aoeu', | |
} }); | |
// single get offerById query | |
async function main1() { | |
let query = query1; | |
const promises = [ | |
client.request(query, variables1).then((data) => { | |
return data.getProductOfferById; | |
}), | |
]; | |
const data = await Promise.all(promises); | |
console.log(data); | |
} | |
// concurrent get offerById query with different ids | |
async function main2() { | |
let query = query1; | |
const promises = [ | |
client.request(query, variables1).then((data) => { | |
return data.getProductOfferById; | |
}), | |
client.request(query, variables2).then((data) => { | |
return data.getProductOfferById; | |
}), | |
]; | |
const data = await Promise.all(promises); | |
console.log(data); | |
} | |
// concurrent get offerById query with same id | |
async function main3() { | |
let query = query1; | |
const promises = [ | |
client.request(query, variables1).then((data) => { | |
return data.getProductOfferById; | |
}), | |
client.request(query, variables1).then((data) => { | |
return data.getProductOfferById; | |
}), | |
client.request(query, variables1).then((data) => { | |
return data.getProductOfferById; | |
}), | |
client.request(query, variables1).then((data) => { | |
return data.getProductOfferById; | |
}), | |
]; | |
const data = await Promise.all(promises); | |
console.log(data); | |
} | |
// single node resolver that returns multiple offers | |
async function main4() { | |
let query = query2; | |
const promises = [ | |
client.request(query, variables3).then((data) => { | |
return data.getShoppingUpdatesCards.map(d => d.data.recommendedOffers); | |
}), | |
]; | |
const data = await Promise.all(promises); | |
console.log(data); | |
} | |
// two resolvers that returns multiple offers (some shared, some diff) | |
async function main5() { | |
let query = query2; | |
const promises = [ | |
client.request(query, variables3).then((data) => { | |
return data.getShoppingUpdatesCards.map(d => d.data.recommendedOffers); | |
}), | |
client.request(query, variables4).then((data) => { | |
return data.getShoppingUpdatesCards.map(d => d.data.recommendedOffers); | |
}), | |
]; | |
const data = await Promise.all(promises); | |
console.log(data); | |
} | |
// same resolver which returns multiple offers called concurrently | |
async function main6() { | |
let query = query2; | |
const promises = [ | |
client.request(query, variables3).then((data) => { | |
return data.getShoppingUpdatesCards.map(d => d.data.recommendedOffers); | |
}), | |
client.request(query, variables3).then((data) => { | |
return data.getShoppingUpdatesCards.map(d => d.data.recommendedOffers); | |
}), | |
client.request(query, variables3).then((data) => { | |
return data.getShoppingUpdatesCards.map(d => d.data.recommendedOffers); | |
}), | |
client.request(query, variables3).then((data) => { | |
return data.getShoppingUpdatesCards.map(d => d.data.recommendedOffers); | |
}), | |
]; | |
const data = await Promise.all(promises); | |
console.log(data); | |
} | |
// single getOfferById query | |
// main1(); | |
// concurrent getOfferById query with different ids | |
// main2(); | |
// concurrent getOfferById query with same id | |
// main3(); | |
// single node resolver which returns multiple offers | |
// main4(); | |
// concurrent node resolvers which returns different offers | |
// main5(); | |
// concurrent node resolvers which returns same offers | |
main6(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment