feat: graphql request history and collection restore
This commit is contained in:
@@ -55,6 +55,7 @@ import {
|
|||||||
editGraphqlRequest,
|
editGraphqlRequest,
|
||||||
saveGraphqlRequestAs,
|
saveGraphqlRequestAs,
|
||||||
} from "~/newstore/collections"
|
} from "~/newstore/collections"
|
||||||
|
import { getGQLSession, useGQLRequestName } from "~/newstore/GQLSession"
|
||||||
import { getRESTRequest, useRESTRequestName } from "~/newstore/RESTSession"
|
import { getRESTRequest, useRESTRequestName } from "~/newstore/RESTSession"
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
@@ -63,9 +64,10 @@ export default defineComponent({
|
|||||||
mode: { type: String, default: "rest" },
|
mode: { type: String, default: "rest" },
|
||||||
show: Boolean,
|
show: Boolean,
|
||||||
},
|
},
|
||||||
setup() {
|
setup(props) {
|
||||||
return {
|
return {
|
||||||
requestName: useRESTRequestName(),
|
requestName:
|
||||||
|
props.mode === "rest" ? useRESTRequestName() : useGQLRequestName(),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
@@ -118,7 +120,8 @@ export default defineComponent({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestUpdated = getRESTRequest()
|
const requestUpdated =
|
||||||
|
this.mode === "rest" ? getRESTRequest() : getGQLSession()
|
||||||
|
|
||||||
// Filter out all REST file inputs
|
// Filter out all REST file inputs
|
||||||
if (this.mode === "rest" && requestUpdated.bodyParams) {
|
if (this.mode === "rest" && requestUpdated.bodyParams) {
|
||||||
|
|||||||
@@ -92,6 +92,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Vue from "vue"
|
import Vue from "vue"
|
||||||
import { removeGraphqlRequest } from "~/newstore/collections"
|
import { removeGraphqlRequest } from "~/newstore/collections"
|
||||||
|
import { setGQLSession } from "~/newstore/GQLSession"
|
||||||
|
|
||||||
export default Vue.extend({
|
export default Vue.extend({
|
||||||
props: {
|
props: {
|
||||||
@@ -133,6 +134,16 @@ export default Vue.extend({
|
|||||||
selectRequest() {
|
selectRequest() {
|
||||||
if (this.savingMode) {
|
if (this.savingMode) {
|
||||||
this.pick()
|
this.pick()
|
||||||
|
} else {
|
||||||
|
setGQLSession({
|
||||||
|
name: this.$props.request.name,
|
||||||
|
url: this.$props.request.url,
|
||||||
|
query: this.$props.request.query,
|
||||||
|
headers: this.$props.request.headers,
|
||||||
|
variables: this.$props.request.variables,
|
||||||
|
schema: "",
|
||||||
|
response: "",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
dragStart({ dataTransfer }: any) {
|
dragStart({ dataTransfer }: any) {
|
||||||
|
|||||||
@@ -265,7 +265,6 @@
|
|||||||
<CollectionsSaveRequest
|
<CollectionsSaveRequest
|
||||||
mode="graphql"
|
mode="graphql"
|
||||||
:show="showSaveRequestModal"
|
:show="showSaveRequestModal"
|
||||||
:editing-request="editRequest"
|
|
||||||
@hide-modal="hideRequestModal"
|
@hide-modal="hideRequestModal"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -333,7 +332,6 @@ export default defineComponent({
|
|||||||
const prettifyQueryIcon = ref("photo_filter")
|
const prettifyQueryIcon = ref("photo_filter")
|
||||||
const copyVariablesIcon = ref("content_copy")
|
const copyVariablesIcon = ref("content_copy")
|
||||||
|
|
||||||
const editRequest = ref({})
|
|
||||||
const showSaveRequestModal = ref(false)
|
const showSaveRequestModal = ref(false)
|
||||||
|
|
||||||
const schema = useReadonlyStream(props.conn.schemaString$, "")
|
const schema = useReadonlyStream(props.conn.schemaString$, "")
|
||||||
@@ -408,7 +406,6 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const hideRequestModal = () => {
|
const hideRequestModal = () => {
|
||||||
editRequest.value = {}
|
|
||||||
showSaveRequestModal.value = false
|
showSaveRequestModal.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -419,14 +416,6 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const saveRequest = () => {
|
const saveRequest = () => {
|
||||||
// TODO: Make the modal get the data from the session state
|
|
||||||
editRequest.value = {
|
|
||||||
url: url.value,
|
|
||||||
query: gqlQueryString.value,
|
|
||||||
headers: headers.value,
|
|
||||||
variables: variableString.value,
|
|
||||||
}
|
|
||||||
|
|
||||||
showSaveRequestModal.value = true
|
showSaveRequestModal.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -463,7 +452,6 @@ export default defineComponent({
|
|||||||
|
|
||||||
queryEditor,
|
queryEditor,
|
||||||
|
|
||||||
editRequest,
|
|
||||||
showSaveRequestModal,
|
showSaveRequestModal,
|
||||||
hideRequestModal,
|
hideRequestModal,
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
group-hover:text-secondaryDark
|
group-hover:text-secondaryDark
|
||||||
"
|
"
|
||||||
data-testid="restore_history_entry"
|
data-testid="restore_history_entry"
|
||||||
@click="$emit('use-entry')"
|
@click="useEntry"
|
||||||
>
|
>
|
||||||
<span class="truncate">
|
<span class="truncate">
|
||||||
{{ entry.url }}
|
{{ entry.url }}
|
||||||
@@ -60,30 +60,53 @@
|
|||||||
truncate
|
truncate
|
||||||
"
|
"
|
||||||
data-testid="restore_history_entry"
|
data-testid="restore_history_entry"
|
||||||
@click="$emit('use-entry')"
|
@click="useEntry"
|
||||||
>{{ line }}</span
|
>{{ line }}</span
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script lang="ts">
|
||||||
export default {
|
import { computed, defineComponent, ref } from "@nuxtjs/composition-api"
|
||||||
|
import { setGQLSession } from "~/newstore/GQLSession"
|
||||||
|
|
||||||
|
// TODO: Concrete entry data type
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
props: {
|
props: {
|
||||||
entry: { type: Object, default: () => {} },
|
entry: { type: Object, default: () => {} },
|
||||||
showMore: Boolean,
|
showMore: Boolean,
|
||||||
},
|
},
|
||||||
data() {
|
setup(props) {
|
||||||
|
const expand = ref(false)
|
||||||
|
|
||||||
|
const query = computed(() =>
|
||||||
|
expand
|
||||||
|
? (props.entry.query.split("\n") as string[])
|
||||||
|
: (props.entry.query
|
||||||
|
.split("\n")
|
||||||
|
.slice(0, 2)
|
||||||
|
.concat(["..."]) as string[])
|
||||||
|
)
|
||||||
|
|
||||||
|
const useEntry = () => {
|
||||||
|
setGQLSession({
|
||||||
|
name: "",
|
||||||
|
url: props.entry.url,
|
||||||
|
headers: props.entry.headers,
|
||||||
|
response: props.entry.response,
|
||||||
|
schema: "",
|
||||||
|
query: props.entry.query,
|
||||||
|
variables: props.entry.variables,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
expand: false,
|
expand,
|
||||||
|
query,
|
||||||
|
useEntry,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
})
|
||||||
query() {
|
|
||||||
return this.expand
|
|
||||||
? this.entry.query.split("\n")
|
|
||||||
: this.entry.query.split("\n").slice(0, 2).concat(["..."])
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -144,8 +144,6 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
useHistory(entry: any) {
|
useHistory(entry: any) {
|
||||||
if (this.page === "rest") setRESTRequest(entry)
|
if (this.page === "rest") setRESTRequest(entry)
|
||||||
// TODO: restore gql entry to request section
|
|
||||||
else console.log("not implemented yet")
|
|
||||||
},
|
},
|
||||||
deleteHistory(entry: any) {
|
deleteHistory(entry: any) {
|
||||||
if (this.page === "rest") deleteRESTHistoryEntry(entry)
|
if (this.page === "rest") deleteRESTHistoryEntry(entry)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { distinctUntilChanged, pluck } from "rxjs/operators"
|
import { distinctUntilChanged, pluck } from "rxjs/operators"
|
||||||
import DispatchingStore, { defineDispatchers } from "./DispatchingStore"
|
import DispatchingStore, { defineDispatchers } from "./DispatchingStore"
|
||||||
|
import { useStream } from "~/helpers/utils/composables"
|
||||||
|
|
||||||
export type GQLHeader = {
|
export type GQLHeader = {
|
||||||
key: string
|
key: string
|
||||||
@@ -8,8 +9,8 @@ export type GQLHeader = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GQLSession = {
|
type GQLSession = {
|
||||||
|
name: string
|
||||||
url: string
|
url: string
|
||||||
connected: boolean
|
|
||||||
headers: GQLHeader[]
|
headers: GQLHeader[]
|
||||||
schema: string
|
schema: string
|
||||||
query: string
|
query: string
|
||||||
@@ -17,9 +18,9 @@ type GQLSession = {
|
|||||||
response: string
|
response: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultGQLSession: GQLSession = {
|
export const defaultGQLSession: GQLSession = {
|
||||||
|
name: "",
|
||||||
url: "https://rickandmortyapi.com/graphql",
|
url: "https://rickandmortyapi.com/graphql",
|
||||||
connected: false,
|
|
||||||
headers: [],
|
headers: [],
|
||||||
schema: "",
|
schema: "",
|
||||||
query: `query GetCharacter($id: ID!) {
|
query: `query GetCharacter($id: ID!) {
|
||||||
@@ -33,16 +34,19 @@ const defaultGQLSession: GQLSession = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const dispatchers = defineDispatchers({
|
const dispatchers = defineDispatchers({
|
||||||
|
setSession(_: GQLSession, { session }: { session: GQLSession }) {
|
||||||
|
return session
|
||||||
|
},
|
||||||
|
setName(_: GQLSession, { newName }: { newName: string }) {
|
||||||
|
return {
|
||||||
|
name: newName,
|
||||||
|
}
|
||||||
|
},
|
||||||
setURL(_: GQLSession, { newURL }: { newURL: string }) {
|
setURL(_: GQLSession, { newURL }: { newURL: string }) {
|
||||||
return {
|
return {
|
||||||
url: newURL,
|
url: newURL,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setConnected(_: GQLSession, { newStatus }: { newStatus: boolean }) {
|
|
||||||
return {
|
|
||||||
connected: newStatus,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
setHeaders(_, { headers }: { headers: GQLHeader[] }) {
|
setHeaders(_, { headers }: { headers: GQLHeader[] }) {
|
||||||
return {
|
return {
|
||||||
headers,
|
headers,
|
||||||
@@ -102,15 +106,6 @@ export function setGQLURL(newURL: string) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setGQLConnected(newStatus: boolean) {
|
|
||||||
gqlSessionStore.dispatch({
|
|
||||||
dispatcher: "setConnected",
|
|
||||||
payload: {
|
|
||||||
newStatus,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setGQLHeaders(headers: GQLHeader[]) {
|
export function setGQLHeaders(headers: GQLHeader[]) {
|
||||||
gqlSessionStore.dispatch({
|
gqlSessionStore.dispatch({
|
||||||
dispatcher: "setHeaders",
|
dispatcher: "setHeaders",
|
||||||
@@ -184,12 +179,36 @@ export function setGQLResponse(newResponse: string) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const gqlURL$ = gqlSessionStore.subject$.pipe(
|
export function getGQLSession() {
|
||||||
pluck("url"),
|
return gqlSessionStore.value
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setGQLSession(session: GQLSession) {
|
||||||
|
gqlSessionStore.dispatch({
|
||||||
|
dispatcher: "setSession",
|
||||||
|
payload: {
|
||||||
|
session,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useGQLRequestName() {
|
||||||
|
return useStream(gqlName$, gqlSessionStore.value.name, (val) => {
|
||||||
|
gqlSessionStore.dispatch({
|
||||||
|
dispatcher: "setName",
|
||||||
|
payload: {
|
||||||
|
newName: val,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const gqlName$ = gqlSessionStore.subject$.pipe(
|
||||||
|
pluck("name"),
|
||||||
distinctUntilChanged()
|
distinctUntilChanged()
|
||||||
)
|
)
|
||||||
export const gqlConnected$ = gqlSessionStore.subject$.pipe(
|
export const gqlURL$ = gqlSessionStore.subject$.pipe(
|
||||||
pluck("connected"),
|
pluck("url"),
|
||||||
distinctUntilChanged()
|
distinctUntilChanged()
|
||||||
)
|
)
|
||||||
export const gqlQuery$ = gqlSessionStore.subject$.pipe(
|
export const gqlQuery$ = gqlSessionStore.subject$.pipe(
|
||||||
|
|||||||
Reference in New Issue
Block a user