diff --git a/components/collections/SaveRequest.vue b/components/collections/SaveRequest.vue index 55e55a76b..947252382 100644 --- a/components/collections/SaveRequest.vue +++ b/components/collections/SaveRequest.vue @@ -55,6 +55,7 @@ import { editGraphqlRequest, saveGraphqlRequestAs, } from "~/newstore/collections" +import { getGQLSession, useGQLRequestName } from "~/newstore/GQLSession" import { getRESTRequest, useRESTRequestName } from "~/newstore/RESTSession" export default defineComponent({ @@ -63,9 +64,10 @@ export default defineComponent({ mode: { type: String, default: "rest" }, show: Boolean, }, - setup() { + setup(props) { return { - requestName: useRESTRequestName(), + requestName: + props.mode === "rest" ? useRESTRequestName() : useGQLRequestName(), } }, data() { @@ -118,7 +120,8 @@ export default defineComponent({ return } - const requestUpdated = getRESTRequest() + const requestUpdated = + this.mode === "rest" ? getRESTRequest() : getGQLSession() // Filter out all REST file inputs if (this.mode === "rest" && requestUpdated.bodyParams) { diff --git a/components/collections/graphql/Request.vue b/components/collections/graphql/Request.vue index ed8200e59..d22bd468c 100644 --- a/components/collections/graphql/Request.vue +++ b/components/collections/graphql/Request.vue @@ -92,6 +92,7 @@ diff --git a/components/history/index.vue b/components/history/index.vue index 772a7c8ed..a7e71dd24 100644 --- a/components/history/index.vue +++ b/components/history/index.vue @@ -144,8 +144,6 @@ export default defineComponent({ }, useHistory(entry: any) { if (this.page === "rest") setRESTRequest(entry) - // TODO: restore gql entry to request section - else console.log("not implemented yet") }, deleteHistory(entry: any) { if (this.page === "rest") deleteRESTHistoryEntry(entry) diff --git a/newstore/GQLSession.ts b/newstore/GQLSession.ts index 861952559..cdb61a815 100644 --- a/newstore/GQLSession.ts +++ b/newstore/GQLSession.ts @@ -1,5 +1,6 @@ import { distinctUntilChanged, pluck } from "rxjs/operators" import DispatchingStore, { defineDispatchers } from "./DispatchingStore" +import { useStream } from "~/helpers/utils/composables" export type GQLHeader = { key: string @@ -8,8 +9,8 @@ export type GQLHeader = { } type GQLSession = { + name: string url: string - connected: boolean headers: GQLHeader[] schema: string query: string @@ -17,9 +18,9 @@ type GQLSession = { response: string } -const defaultGQLSession: GQLSession = { +export const defaultGQLSession: GQLSession = { + name: "", url: "https://rickandmortyapi.com/graphql", - connected: false, headers: [], schema: "", query: `query GetCharacter($id: ID!) { @@ -33,16 +34,19 @@ const defaultGQLSession: GQLSession = { } const dispatchers = defineDispatchers({ + setSession(_: GQLSession, { session }: { session: GQLSession }) { + return session + }, + setName(_: GQLSession, { newName }: { newName: string }) { + return { + name: newName, + } + }, setURL(_: GQLSession, { newURL }: { newURL: string }) { return { url: newURL, } }, - setConnected(_: GQLSession, { newStatus }: { newStatus: boolean }) { - return { - connected: newStatus, - } - }, setHeaders(_, { headers }: { headers: GQLHeader[] }) { return { 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[]) { gqlSessionStore.dispatch({ dispatcher: "setHeaders", @@ -184,12 +179,36 @@ export function setGQLResponse(newResponse: string) { }) } -export const gqlURL$ = gqlSessionStore.subject$.pipe( - pluck("url"), +export function getGQLSession() { + 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() ) -export const gqlConnected$ = gqlSessionStore.subject$.pipe( - pluck("connected"), +export const gqlURL$ = gqlSessionStore.subject$.pipe( + pluck("url"), distinctUntilChanged() ) export const gqlQuery$ = gqlSessionStore.subject$.pipe(