Add an authorization tab for GraphQL (#2125)
Co-authored-by: Rishabh Agarwal <rishabh2001agarwal@gmail.com> Co-authored-by: Rishabh Agarwal <45998880+RishabhAgarwal-2001@users.noreply.github.com> Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { HoppGQLRequest, translateToGQLRequest } from "../graphql";
|
||||
import { GQL_REQ_SCHEMA_VERSION, HoppGQLRequest, translateToGQLRequest } from "../graphql";
|
||||
import { HoppRESTRequest, translateToNewRequest } from "../rest";
|
||||
|
||||
const CURRENT_COLL_SCHEMA_VER = 1
|
||||
@@ -65,7 +65,7 @@ export function translateToNewRESTCollection(
|
||||
export function translateToNewGQLCollection(
|
||||
x: any
|
||||
): HoppCollection<HoppGQLRequest> {
|
||||
if (x.v && x.v === 1) return x
|
||||
if (x.v && x.v === GQL_REQ_SCHEMA_VERSION) return x
|
||||
|
||||
// Legacy
|
||||
const name = x.name ?? "Untitled"
|
||||
|
||||
43
packages/hoppscotch-data/src/graphql/HoppGQLAuth.ts
Normal file
43
packages/hoppscotch-data/src/graphql/HoppGQLAuth.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
export type HoppGQLAuthNone = {
|
||||
authType: "none"
|
||||
}
|
||||
|
||||
export type HoppGQLAuthBasic = {
|
||||
authType: "basic"
|
||||
|
||||
username: string
|
||||
password: string
|
||||
}
|
||||
|
||||
export type HoppGQLAuthBearer = {
|
||||
authType: "bearer"
|
||||
|
||||
token: string
|
||||
}
|
||||
|
||||
export type HoppGQLAuthOAuth2 = {
|
||||
authType: "oauth-2"
|
||||
|
||||
token: string
|
||||
oidcDiscoveryURL: string
|
||||
authURL: string
|
||||
accessTokenURL: string
|
||||
clientID: string
|
||||
scope: string
|
||||
}
|
||||
|
||||
export type HoppGQLAuthAPIKey = {
|
||||
authType: "api-key"
|
||||
|
||||
key: string
|
||||
value: string
|
||||
addTo: string
|
||||
}
|
||||
|
||||
export type HoppGQLAuth = { authActive: boolean } & (
|
||||
| HoppGQLAuthNone
|
||||
| HoppGQLAuthBasic
|
||||
| HoppGQLAuthBearer
|
||||
| HoppGQLAuthOAuth2
|
||||
| HoppGQLAuthAPIKey
|
||||
)
|
||||
@@ -1,3 +1,9 @@
|
||||
import { HoppGQLAuth } from "./HoppGQLAuth"
|
||||
|
||||
export * from "./HoppGQLAuth"
|
||||
|
||||
export const GQL_REQ_SCHEMA_VERSION = 2
|
||||
|
||||
export type GQLHeader = {
|
||||
key: string
|
||||
value: string
|
||||
@@ -11,10 +17,11 @@ export type HoppGQLRequest = {
|
||||
headers: GQLHeader[]
|
||||
query: string
|
||||
variables: string
|
||||
auth: HoppGQLAuth
|
||||
}
|
||||
|
||||
export function translateToGQLRequest(x: any): HoppGQLRequest {
|
||||
if (x.v && x.v === 1) return x
|
||||
if (x.v && x.v === GQL_REQ_SCHEMA_VERSION) return x
|
||||
|
||||
// Old request
|
||||
const name = x.name ?? "Untitled"
|
||||
@@ -22,20 +29,25 @@ export function translateToGQLRequest(x: any): HoppGQLRequest {
|
||||
const headers = x.headers ?? []
|
||||
const query = x.query ?? ""
|
||||
const variables = x.variables ?? []
|
||||
const auth = x.auth ?? {
|
||||
authType: "none",
|
||||
authActive: true,
|
||||
}
|
||||
|
||||
return {
|
||||
v: 1,
|
||||
v: GQL_REQ_SCHEMA_VERSION,
|
||||
name,
|
||||
url,
|
||||
headers,
|
||||
query,
|
||||
variables,
|
||||
auth
|
||||
}
|
||||
}
|
||||
|
||||
export function makeGQLRequest(x: Omit<HoppGQLRequest, "v">) {
|
||||
export function makeGQLRequest(x: Omit<HoppGQLRequest, "v">): HoppGQLRequest {
|
||||
return {
|
||||
v: 1,
|
||||
v: GQL_REQ_SCHEMA_VERSION,
|
||||
...x,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user