From 715d910877d218922c170d7a8a01387137516994 Mon Sep 17 00:00:00 2001 From: Liyas Thomas Date: Tue, 15 Mar 2022 00:44:26 +0530 Subject: [PATCH] Add an authorization tab for GraphQL (#2125) Co-authored-by: Rishabh Agarwal Co-authored-by: Rishabh Agarwal <45998880+RishabhAgarwal-2001@users.noreply.github.com> Co-authored-by: Andrew Bastin --- .../collections/graphql/Request.vue | 18 +- .../components/graphql/Authorization.vue | 322 ++++++++++++++++++ .../components/graphql/RequestOptions.vue | 16 +- .../components/graphql/Sidebar.vue | 5 + .../components/history/graphql/Card.vue | 18 +- .../hoppscotch-app/helpers/GQLConnection.ts | 32 +- .../hoppscotch-app/newstore/GQLSession.ts | 33 +- packages/hoppscotch-app/newstore/history.ts | 7 +- packages/hoppscotch-data/package.json | 2 +- .../hoppscotch-data/src/collection/index.ts | 4 +- .../src/graphql/HoppGQLAuth.ts | 43 +++ packages/hoppscotch-data/src/graphql/index.ts | 20 +- 12 files changed, 491 insertions(+), 29 deletions(-) create mode 100644 packages/hoppscotch-app/components/graphql/Authorization.vue create mode 100644 packages/hoppscotch-data/src/graphql/HoppGQLAuth.ts diff --git a/packages/hoppscotch-app/components/collections/graphql/Request.vue b/packages/hoppscotch-app/components/collections/graphql/Request.vue index bb585d26d..95f3387fe 100644 --- a/packages/hoppscotch-app/components/collections/graphql/Request.vue +++ b/packages/hoppscotch-app/components/collections/graphql/Request.vue @@ -123,6 +123,7 @@ diff --git a/packages/hoppscotch-app/components/graphql/RequestOptions.vue b/packages/hoppscotch-app/components/graphql/RequestOptions.vue index 4e049a845..72cac7b44 100644 --- a/packages/hoppscotch-app/components/graphql/RequestOptions.vue +++ b/packages/hoppscotch-app/components/graphql/RequestOptions.vue @@ -260,6 +260,9 @@ + + + +const auth = useStream( + gqlAuth$, + { authType: "none", authActive: true }, + setGQLAuth +) + // The UI representation of the headers list (has the empty end header) const workingHeaders = ref>([ { @@ -602,12 +613,14 @@ const runQuery = async () => { const runHeaders = clone(headers.value) const runQuery = clone(gqlQueryString.value) const runVariables = clone(variableString.value) + const runAuth = clone(auth.value) const responseText = await props.conn.runQuery( runURL, runHeaders, runQuery, - runVariables + runVariables, + runAuth ) const duration = Date.now() - startTime @@ -623,6 +636,7 @@ const runQuery = async () => { query: runQuery, headers: runHeaders, variables: runVariables, + auth: runAuth, }), response: response.value, star: false, diff --git a/packages/hoppscotch-app/components/graphql/Sidebar.vue b/packages/hoppscotch-app/components/graphql/Sidebar.vue index 029129e74..31acce919 100644 --- a/packages/hoppscotch-app/components/graphql/Sidebar.vue +++ b/packages/hoppscotch-app/components/graphql/Sidebar.vue @@ -210,6 +210,7 @@ import { useToast, } from "~/helpers/utils/composables" import { + setGQLAuth, setGQLHeaders, setGQLQuery, setGQLResponse, @@ -451,6 +452,10 @@ const handleUseHistory = (entry: GQLHistoryEntry) => { setGQLQuery(gqlQueryString) setGQLVariables(variableString) setGQLResponse(responseText) + setGQLAuth({ + authType: "none", + authActive: true, + }) props.conn.reset() } diff --git a/packages/hoppscotch-app/components/history/graphql/Card.vue b/packages/hoppscotch-app/components/history/graphql/Card.vue index 8cffa9136..3a86df73c 100644 --- a/packages/hoppscotch-app/components/history/graphql/Card.vue +++ b/packages/hoppscotch-app/components/history/graphql/Card.vue @@ -58,6 +58,7 @@