Last active
September 4, 2019 08:45
-
-
Save kukiron/5a2b4d1449c1975a1d9b0220801a84f3 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
import execute from '../execute'; | |
import type { AcquiredCreation, AcquiredCreationInput } from '../types'; | |
export default async ( | |
acquiredCreationInputs: Array<AcquiredCreationInput>, | |
): Promise<Array<AcquiredCreation>> => { | |
const queryParameters = acquiredCreationInputs | |
.map((_, index) => `$creationId${index}: ID!, $type${index}: String!`).join(', '); | |
const parameters = acquiredCreationInputs.reduce( | |
(accumulator, { creationId, type }, index) => ({ | |
...accumulator, | |
[`creationId${index}`]: creationId, | |
[`type${index}`]: type, | |
}), | |
{}, | |
); | |
const query = ( | |
`mutation AddUserAcquiredCreation(${queryParameters}) { | |
${acquiredCreationInputs.map((_, index) => ( | |
`result${index}: addUserAcquiredCreation(creationId: $creationId${index}, type: $type${index}) { | |
id | |
type | |
creationId | |
}` | |
)).join('\n')} | |
}` | |
); | |
const { results } = await execute(query, { ... }); // what's this line gonna be? | |
return results; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment