fix: use proper values for addTo field when auth type is api-key (#3966)
This commit is contained in:
@@ -3,31 +3,33 @@ import { z } from "zod"
|
||||
import V1_VERSION from "./v/1"
|
||||
import V2_VERSION from "./v/2"
|
||||
import V3_VERSION from "./v/3"
|
||||
import V4_VERSION from "./v/4"
|
||||
|
||||
export { GQLHeader } from "./v/1"
|
||||
export {
|
||||
HoppGQLAuthAPIKey,
|
||||
HoppGQLAuthBasic,
|
||||
HoppGQLAuthBearer,
|
||||
HoppGQLAuthNone,
|
||||
HoppGQLAuthInherit,
|
||||
} from "./v/2"
|
||||
|
||||
export { HoppGQLAuth } from "./v/3"
|
||||
export { HoppGQLAuth } from "./v/4"
|
||||
export { HoppGQLAuthOAuth2 } from "./v/3"
|
||||
export { HoppGQLAuthAPIKey } from "./v/4"
|
||||
|
||||
export const GQL_REQ_SCHEMA_VERSION = 3
|
||||
export const GQL_REQ_SCHEMA_VERSION = 4
|
||||
|
||||
const versionedObject = z.object({
|
||||
v: z.number(),
|
||||
})
|
||||
|
||||
export const HoppGQLRequest = createVersionedEntity({
|
||||
latestVersion: 3,
|
||||
latestVersion: 4,
|
||||
versionMap: {
|
||||
1: V1_VERSION,
|
||||
2: V2_VERSION,
|
||||
3: V3_VERSION,
|
||||
4: V4_VERSION,
|
||||
},
|
||||
getVersion(x) {
|
||||
const result = versionedObject.safeParse(x)
|
||||
|
||||
71
packages/hoppscotch-data/src/graphql/v/4.ts
Normal file
71
packages/hoppscotch-data/src/graphql/v/4.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { defineVersion } from "verzod"
|
||||
|
||||
import { HoppRESTAuthOAuth2 } from "../../rest"
|
||||
import {
|
||||
HoppGQLAuthAPIKey as HoppGQLAuthAPIKeyOld,
|
||||
HoppGQLAuthBasic,
|
||||
HoppGQLAuthBearer,
|
||||
HoppGQLAuthInherit,
|
||||
HoppGQLAuthNone,
|
||||
} from "./2"
|
||||
import { V3_SCHEMA } from "./3"
|
||||
|
||||
export { HoppRESTAuthOAuth2 as HoppGQLAuthOAuth2 } from "../../rest"
|
||||
|
||||
export const HoppGQLAuthAPIKey = HoppGQLAuthAPIKeyOld.extend({
|
||||
addTo: z.enum(["HEADERS", "QUERY_PARAMS"]).catch("HEADERS"),
|
||||
})
|
||||
|
||||
export type HoppGqlAuthOAuth2 = z.infer<typeof HoppRESTAuthOAuth2>
|
||||
|
||||
export const HoppGQLAuth = z
|
||||
.discriminatedUnion("authType", [
|
||||
HoppGQLAuthNone,
|
||||
HoppGQLAuthInherit,
|
||||
HoppGQLAuthBasic,
|
||||
HoppGQLAuthBearer,
|
||||
HoppGQLAuthAPIKey,
|
||||
HoppRESTAuthOAuth2, // both rest and gql have the same auth type for oauth2
|
||||
])
|
||||
.and(
|
||||
z.object({
|
||||
authActive: z.boolean(),
|
||||
})
|
||||
)
|
||||
|
||||
export type HoppGQLAuth = z.infer<typeof HoppGQLAuth>
|
||||
|
||||
export const V4_SCHEMA = V3_SCHEMA.extend({
|
||||
v: z.literal(4),
|
||||
auth: HoppGQLAuth,
|
||||
})
|
||||
|
||||
export default defineVersion({
|
||||
initial: false,
|
||||
schema: V4_SCHEMA,
|
||||
up(old: z.infer<typeof V3_SCHEMA>) {
|
||||
if (old.auth.authType === "api-key") {
|
||||
return {
|
||||
...old,
|
||||
v: 4 as const,
|
||||
auth: {
|
||||
...old.auth,
|
||||
addTo:
|
||||
old.auth.addTo === "Query params"
|
||||
? ("QUERY_PARAMS" as const)
|
||||
: ("HEADERS" as const),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...old,
|
||||
v: 4 as const,
|
||||
auth: {
|
||||
...old.auth,
|
||||
},
|
||||
}
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user