Add revoke api key mutation in Web

This commit is contained in:
Hongbo Wu 2022-06-06 12:53:25 +08:00
parent fba142eb3b
commit aada005e50

View file

@ -0,0 +1,39 @@
import { gql } from 'graphql-request'
import { gqlFetcher } from '../networkHelpers'
import { ApiKey } from '../queries/useGetApiKeysQuery'
interface RevokeApiKeyResult {
revokeApiKey: RevokeApiKey
errorCodes?: unknown[]
}
type RevokeApiKey = {
apiKey: ApiKey
}
export async function revokeApiKeyMutation(
id: string
): Promise<any | undefined> {
const mutation = gql`
mutation {
revokeApiKey(id: "${id}") {
... on RevokeApiKeySuccess {
apiKey {
id
}
}
... on RevokeApiKeyError {
errorCodes
}
}
}
`
try {
const data = (await gqlFetcher(mutation)) as RevokeApiKeyResult
return data.errorCodes ? undefined : data.revokeApiKey.apiKey.id
} catch (error) {
console.log('revokeApiKeyMutation error', error)
return undefined
}
}