Skip to content

Instantly share code, notes, and snippets.

@belazer
Created October 27, 2022 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save belazer/cfa5f279b6169f13c40464d5afb6f168 to your computer and use it in GitHub Desktop.
Save belazer/cfa5f279b6169f13c40464d5afb6f168 to your computer and use it in GitHub Desktop.
const c = require('graphql-request');
require('dotenv').config();
const d = {
"data": {
"authors": [
{
"id": "123",
"bibliography": "Test Test",
},
{
"id": "456",
"bibliography": "Test Test",
},
{
"id": "789",
"bibliography": "Test Test",
},
]
}
};
const client = new c.GraphQLClient(
process.env.ENDPOINT,
{
headers: {
Authorization:
`Bearer ${process.env.TOKEN}`,
},
}
);
const query = `mutation updateAuthor($id: ID, $bibliography: String) {
updateAuthor(where: {id: $id}, data: {bibliography: $bibliography}) {
id
bibliography
}
}`;
const run = async () => {
const failed = {};
for (const author of d.data.authors) {
try {
console.log(author.id);
await client.request(query, { id: author.id, bibliography: author.bibliography });
// setTimeout(await client.request(query, { id: author.id, bibliography: author.bibliography }), 350);
} catch (e) {
failed[author.id] = e;
}
}
console.log(JSON.stringify(failed, null, 2));
};
run()
.then(() => console.log('Ready'))
.catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment