Skip to content

Commit

Permalink
chore: add fallback url and add reqIndex for graphql saving
Browse files Browse the repository at this point in the history
  • Loading branch information
nivedin committed Apr 24, 2024
1 parent 10b63be commit 0802c5d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ import { PersistenceService } from "~/services/persistence"
import { PersistedOAuthConfig } from "~/services/oauth/oauth.service"
import { GQLOptionTabs } from "~/components/graphql/RequestOptions.vue"
import { EditingProperties } from "../Properties.vue"
import { getDefaultGQLRequest } from "~/helpers/graphql/default"
const t = useI18n()
const toast = useToast()
Expand Down Expand Up @@ -379,32 +380,26 @@ const editCollection = (
displayModalEdit(true)
}
const onAddRequest = ({
name,
path,
index,
}: {
name: string
path: string
index: number
}) => {
const onAddRequest = ({ name, path }: { name: string; path: string }) => {
const newRequest = {
...tabs.currentActiveTab.value.document.request,
name,
url:
tabs.currentActiveTab.value.document.request.url ||
getDefaultGQLRequest().url,
}
saveGraphqlRequestAs(path, newRequest)
const insertionIndex = saveGraphqlRequestAs(path, newRequest)
const { auth, headers } = cascadeParentCollectionForHeaderAuth(
path,
"graphql"
)
tabs.createNewTab({
saveContext: {
originLocation: "user-collection",
folderPath: path,
requestIndex: index,
requestIndex: insertionIndex,
},
request: newRequest,
isDirty: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ import { PersistenceService } from "~/services/persistence"
import { PersistedOAuthConfig } from "~/services/oauth/oauth.service"
import { RESTOptionTabs } from "../http/RequestOptions.vue"
import { EditingProperties } from "./Properties.vue"
import { getDefaultRESTRequest } from "~/helpers/rest/default"
const t = useI18n()
const toast = useToast()
Expand Down Expand Up @@ -790,6 +791,9 @@ const onAddRequest = (requestName: string) => {
const newRequest = {
...cloneDeep(tabs.currentActiveTab.value.document.request),
name: requestName,
endpoint:
tabs.currentActiveTab.value.document.request.endpoint ||
getDefaultRESTRequest().endpoint,
}
const path = editingFolderPath.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ const request = useVModel(props, "modelValue", emit)
const url = computedWithControl(
() => tabs.currentActiveTab.value,
() => tabs.currentActiveTab.value.document.request.url
() =>
tabs.currentActiveTab.value.document.request.url ||
getDefaultGQLRequest().url
)
const activeGQLHeadersCount = computed(
Expand Down
10 changes: 10 additions & 0 deletions packages/hoppscotch-common/src/newstore/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1393,13 +1393,23 @@ export function editGraphqlRequest(
}

export function saveGraphqlRequestAs(path: string, request: HoppGQLRequest) {
// For calculating the insertion request index
const targetLocation = navigateToFolderWithIndexPath(
graphqlCollectionStore.value.state,
path.split("/").map((x) => parseInt(x))
)

const insertionIndex = targetLocation!.requests.length

graphqlCollectionStore.dispatch({
dispatcher: "saveRequestAs",
payload: {
path,
request,
},
})

return insertionIndex
}

export function removeGraphqlRequest(
Expand Down

0 comments on commit 0802c5d

Please sign in to comment.