signor_busi
07/15/2017, 4:07 PMpeterp
07/15/2017, 5:26 PMrequire("dotenv").config();
const Bluebird = require("bluebird");
const _ = require("lodash");
const { Lokka } = require("lokka");
const { Transport } = require("lokka-transport-http");
const headers = {
Authorization: "Bearer ${GRAPHQL_ACCESS_TOKEN}"
};
const client = new Lokka({
transport: new Transport(process.env.GRAPHQL_ENDPOINT, { headers })
});
const createAttendees = async () => {
const mutations = _.chain(_.range(1000))
.map(
n =>
`{
post: createAttendee(text: "${n}") {
id
}
}`
)
.value();
await Bluebird.map(mutations, m => client.mutate(m), { concurrency: 4 });
};
const queryBatch = () => {
return client.query(`
query getAttendees {
posts: allAttendees(first: 250) {
id
}
}
`);
};
const deleteBatch = async () => {
console.log("Fetching new nodes");
const posts = (await queryBatch()).posts;
if (posts && posts.length > 0) {
console.log(`Deleting next batch of ${posts.length} posts...`);
const mutations = _.chain(posts)
.map(
post =>
`{
deleteAttendee(id: "${post.id}") {
id
}
}`
)
.value();
await Bluebird.map(mutations, m => client.mutate(m), { concurrency: 4 });
await deleteBatch();
}
};
const main = async () => {
// set to true to create test data
if (false) {
} else {
// query total posts:
const postsMeta = await client.query(`{
meta: _allAttendeesMeta {
count
}
}`);
console.log(`Deleting ${postsMeta.meta.count} posts...`);
await deleteBatch();
}
console.log("Done!");
};
main().catch(e => console.error(e));
peterp
07/15/2017, 5:26 PMnilan
07/15/2017, 5:31 PMnilan
07/15/2017, 5:31 PMnilan
07/15/2017, 5:31 PMsignor_busi
07/15/2017, 5:59 PMagartha
07/15/2017, 9:12 PMmutation{
createPost(description: "blah"){
firstDesc: description
}
createPost(description: "more blah"){
secondDesc: description
}
}
Will result in:
{
"data": {
"createPost": {
"firstDesc": "blah",
"secondDesc": "more blah"
}
}
}
nilan
07/15/2017, 9:12 PMnilan
07/15/2017, 9:13 PMagartha
07/15/2017, 9:13 PMagartha
07/15/2017, 9:14 PMagartha
07/15/2017, 9:14 PMnilan
07/15/2017, 9:15 PMagartha
07/15/2017, 9:15 PMnilan
07/15/2017, 9:15 PMagartha
07/15/2017, 9:16 PMnilan
07/15/2017, 9:17 PMagartha
07/15/2017, 9:20 PMnilan
07/15/2017, 9:22 PMagartha
07/15/2017, 9:24 PMmutation{
createPost(description: "blah", result:""){
result
}
createPost(description: "more blah", result:""){
result
}
}
If ALL posts are created succesfully, I get a single result:
data {
createPost {
result: "ok"
}
}
If not, I get an error:
{
"data": null,
"errors": [
{
"message": "Field 'createPost' conflict because they have differing arguments. Use different aliases on the fields to fetch both if this was intentional.
<clipped>
And ALL mutations fail.nilan
07/15/2017, 9:24 PMagartha
07/15/2017, 9:25 PMTRANSFORM_ARGUMENT
, that's the only one where I can change the result
field I passed innilan
07/15/2017, 9:25 PMnilan
07/15/2017, 9:26 PMnilan
07/15/2017, 9:27 PMagartha
07/15/2017, 9:27 PMagartha
07/15/2017, 9:28 PMnilan
07/15/2017, 9:28 PMagartha
07/15/2017, 9:30 PM