Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
fix: graphql query deprecation issue (#3506)
Anwarul Islambe3e5ba7e7b8
diff --git a/packages/hoppscotch-common/src/components/graphql/Field.vue b/packages/hoppscotch-common/src/components/graphql/Field.vueindex 9c022354f..c9c18532c 100644--- a/packages/hoppscotch-common/src/components/graphql/Field.vue+++ b/packages/hoppscotch-common/src/components/graphql/Field.vue@@ -1,50 +1,55 @@<template><div>- <div class="field-title" :class="{ 'field-highlighted': isHighlighted }">- {{ fieldName }}- <span v-if="fieldArgs.length > 0">- (- <span v-for="(field, index) in fieldArgs" :key="`field-${index}`">- {{ field.name }}:- <GraphqlTypeLink- :gql-type="field.type"- :jump-type-callback="jumpTypeCallback"- />- <span v-if="index !== fieldArgs.length - 1">, </span>+ <div class="flex justify-between gap-2">+ <div+ class="field-title flex-1"+ :class="{ 'field-highlighted': isHighlighted }"+ >+ {{ fieldName }}+ <span v-if="fieldArgs.length > 0">+ (+ <span v-for="(field, index) in fieldArgs" :key="`field-${index}`">+ {{ field.name }}:+ <GraphqlTypeLink+ :gql-type="field.type"+ @jump-to-type="jumpToType"+ />+ <span v-if="index !== fieldArgs.length - 1">, </span>+ </span>+ ) </span+ >:+ <GraphqlTypeLink :gql-type="gqlField.type" @jump-to-type="jumpToType" />+ </div>+ <div v-if="gqlField.deprecationReason">+ <span+ v-tippy="{ theme: 'tomato' }"+ class="!text-red-500 hover:!text-red-600 text-xs flex items-center gap-2 cursor-pointer"+ :title="gqlField.deprecationReason"+ >+ <IconAlertTriangle /> {{ t("state.deprecated") }}</span>- ) </span- >:- <GraphqlTypeLink- :gql-type="gqlField.type"- :jump-type-callback="jumpTypeCallback"- />+ </div></div><divv-if="gqlField.description"- class="py-2 text-secondaryLight field-desc"+ class="field-desc py-2 text-secondaryLight">{{ gqlField.description }}</div>- <div- v-if="gqlField.isDeprecated"- class="inline-block px-2 py-1 my-1 text-black bg-yellow-200 rounded field-deprecated"- >- {{ t("state.deprecated") }}- </div><div v-if="fieldArgs.length > 0"><h5 class="my-2">Arguments:</h5>- <div class="pl-4 border-l-2 border-divider">+ <div class="border-l-2 border-divider pl-4"><div v-for="(field, index) in fieldArgs" :key="`field-${index}`"><span>{{ field.name }}:<GraphqlTypeLink:gql-type="field.type"- :jump-type-callback="jumpTypeCallback"+ @jump-to-type="jumpToType"/></span><divv-if="field.description"- class="py-2 text-secondaryLight field-desc"+ class="field-desc py-2 text-secondaryLight">{{ field.description }}</div>@@ -54,37 +59,41 @@</div></template>-<script>-// TypeScript + Script Setup this :)-import { defineComponent } from "vue"+<script setup lang="ts">import { useI18n } from "@composables/i18n"+import { GraphQLType } from "graphql"+import { computed } from "vue"+import IconAlertTriangle from "~icons/lucide/alert-triangle"++const t = useI18n()++const props = withDefaults(+ defineProps<{+ gqlField: any+ isHighlighted: boolean+ }>(),+ {+ gqlField: {},+ isHighlighted: false,+ }+)-export default defineComponent({- props: {- gqlField: { type: Object, default: () => ({}) },- jumpTypeCallback: { type: Function, default: () => ({}) },- isHighlighted: { type: Boolean, default: false },- },- setup() {- return {- t: useI18n(),- }- },- computed: {- fieldName() {- return this.gqlField.name- },+const emit = defineEmits<{+ (e: "jump-to-type", type: GraphQLType): void+}>()- fieldArgs() {- return this.gqlField.args || []- },- },-})+const fieldName = computed(() => props.gqlField.name)++const fieldArgs = computed(() => props.gqlField.args || [])++const jumpToType = (type: GraphQLType) => {+ emit("jump-to-type", type)+}</script><style lang="scss" scoped>.field-highlighted {- @apply border-accent border-b-2;+ @apply border-b-2 border-accent;}.field-title {diff --git a/packages/hoppscotch-common/src/components/graphql/Sidebar.vue b/packages/hoppscotch-common/src/components/graphql/Sidebar.vueindex fbf51e047..84a15cfa9 100644--- a/packages/hoppscotch-common/src/components/graphql/Sidebar.vue+++ b/packages/hoppscotch-common/src/components/graphql/Sidebar.vue@@ -58,7 +58,7 @@v-for="(field, index) in filteredQueryFields":key="`field-${index}`":gql-field="field"- :jump-type-callback="handleJumpToType"+ @jump-to-type="handleJumpToType"class="p-4"/></HoppSmartTab>@@ -72,7 +72,7 @@v-for="(field, index) in filteredMutationFields":key="`field-${index}`":gql-field="field"- :jump-type-callback="handleJumpToType"+ @jump-to-type="handleJumpToType"class="p-4"/></HoppSmartTab>@@ -86,7 +86,7 @@v-for="(field, index) in filteredSubscriptionFields":key="`field-${index}`":gql-field="field"- :jump-type-callback="handleJumpToType"+ @jump-to-type="handleJumpToType"class="p-4"/></HoppSmartTab>@@ -103,7 +103,7 @@:gql-types="graphqlTypes":is-highlighted="isGqlTypeHighlighted(type)":highlighted-fields="getGqlTypeHighlightedFields(type)"- :jump-type-callback="handleJumpToType"+ @jump-to-type="handleJumpToType"/></HoppSmartTab></HoppSmartTabs>diff --git a/packages/hoppscotch-common/src/components/graphql/TypeLink.vue b/packages/hoppscotch-common/src/components/graphql/TypeLink.vueindex 82180a8b1..845c32522 100644--- a/packages/hoppscotch-common/src/components/graphql/TypeLink.vue+++ b/packages/hoppscotch-common/src/components/graphql/TypeLink.vue@@ -7,38 +7,31 @@</span></template>-<script lang="ts">-import { defineComponent } from "vue"-import { GraphQLScalarType } from "graphql"+<script setup lang="ts">+import { GraphQLScalarType, GraphQLType } from "graphql"+import { computed } from "vue"-export default defineComponent({- props: {- // eslint-disable-next-line vue/require-default-prop- gqlType: null,- // (typeName: string) => void- // eslint-disable-next-line vue/require-default-prop- jumpTypeCallback: Function,- },+const props = defineProps<{+ gqlType: GraphQLType+}>()- computed: {- typeString() {- return `${this.gqlType}`- },- isScalar() {- return this.resolveRootType(this.gqlType) instanceof GraphQLScalarType- },- },+const emit = defineEmits<{+ (e: "jump-to-type", type: GraphQLType): void+}>()- methods: {- jumpToType() {- if (this.isScalar) return- this.jumpTypeCallback(this.gqlType)- },- resolveRootType(type) {- let t = type- while (t.ofType != null) t = t.ofType- return t- },- },+const typeString = computed(() => `${props.gqlType}`)+const isScalar = computed(() => {+ return resolveRootType(props.gqlType) instanceof GraphQLScalarType})++function resolveRootType(type: GraphQLType) {+ let t = type as any+ while (t.ofType != null) t = t.ofType+ return t+}++function jumpToType() {+ if (isScalar.value) return+ emit("jump-to-type", props.gqlType)+}</script>