refactor: separate out data structures into hoppscotch-data

This commit is contained in:
Andrew Bastin
2021-11-24 01:20:07 +05:30
parent 2884854aab
commit 38755bf3e3
47 changed files with 820 additions and 74 deletions

View File

@@ -0,0 +1,41 @@
export type GQLHeader = {
key: string
value: string
active: boolean
}
export type HoppGQLRequest = {
v: number
name: string
url: string
headers: GQLHeader[]
query: string
variables: string
}
export function translateToGQLRequest(x: any): HoppGQLRequest {
if (x.v && x.v === 1) return x
// Old request
const name = x.name ?? "Untitled"
const url = x.url ?? ""
const headers = x.headers ?? []
const query = x.query ?? ""
const variables = x.variables ?? []
return {
v: 1,
name,
url,
headers,
query,
variables,
}
}
export function makeGQLRequest(x: Omit<HoppGQLRequest, "v">) {
return {
v: 1,
...x,
}
}