Created
October 27, 2022 14:35
-
-
Save belazer/cfa5f279b6169f13c40464d5afb6f168 to your computer and use it in GitHub Desktop.
This file contains 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 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