Use GQL variables for all mutations

This commit is contained in:
Jackson Harper 2024-07-09 09:42:18 +08:00
parent f2fc0c49d0
commit f19cae74bb
4 changed files with 12 additions and 10 deletions

View file

@ -14,7 +14,7 @@ export async function addPopularReadMutation(
readName: string
): Promise<string | undefined> {
const mutation = gql`
mutation {
mutation AddPopularRead($name: String!) {
addPopularRead(name: "${readName}") {
... on AddPopularReadSuccess {
pageId

View file

@ -15,8 +15,8 @@ export async function deleteLabelMutation(
labelId: string
): Promise<any | undefined> {
const mutation = gql`
mutation {
deleteLabel(id: "${labelId}") {
mutation DeleteLabel($id: ID!) {
deleteLabel(id: $id) {
... on DeleteLabelSuccess {
label {
id
@ -34,7 +34,9 @@ export async function deleteLabelMutation(
`
try {
const data = await gqlFetcher(mutation) as DeleteLabelResult
const data = (await gqlFetcher(mutation, {
id: labelId,
})) as DeleteLabelResult
return data.errorCodes ? undefined : data.deleteLabel.label.id
} catch (error) {
console.log('deleteLabelMutation error', error)

View file

@ -15,8 +15,8 @@ export async function deleteWebhookMutation(
id: string
): Promise<any | undefined> {
const mutation = gql`
mutation {
deleteWebhook(id: "${id}") {
mutation DeleteWebhook($id: ID!) {
deleteWebhook(id: $id) {
... on DeleteWebhookSuccess {
webhook {
id
@ -30,7 +30,7 @@ export async function deleteWebhookMutation(
`
try {
const data = (await gqlFetcher(mutation)) as DeleteWebhookResult
const data = (await gqlFetcher(mutation, { id })) as DeleteWebhookResult
return data.errorCodes ? undefined : data.deleteWebhook.webhook.id
} catch (error) {
console.log('deleteWebhookMutation error', error)

View file

@ -15,8 +15,8 @@ export async function revokeApiKeyMutation(
id: string
): Promise<any | undefined> {
const mutation = gql`
mutation {
revokeApiKey(id: "${id}") {
mutation RevokeApiKey($id: ID!) {
revokeApiKey(id: $id) {
... on RevokeApiKeySuccess {
apiKey {
id
@ -30,7 +30,7 @@ export async function revokeApiKeyMutation(
`
try {
const data = (await gqlFetcher(mutation)) as RevokeApiKeyResult
const data = (await gqlFetcher(mutation, { id })) as RevokeApiKeyResult
return data.errorCodes ? undefined : data.revokeApiKey.apiKey.id
} catch (error) {
console.log('revokeApiKeyMutation error', error)