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
<template>
<GqlExplorerSection v-if="fields.length > 0" :title="t('graphql.fields')">
<GqlField
v-for="field in fields"
:key="field.name"
:field="field"
:show-add-field="showAddField"
/>
</GqlExplorerSection>
</template>
<script setup lang="ts">
import {
GraphQLNamedType,
isInputObjectType,
isInterfaceType,
isObjectType,
} from "graphql"
import { computed } from "vue"
import { useI18n } from "~/composables/i18n"
import { ExplorerFieldDef } from "~/helpers/graphql/explorer"
const t = useI18n()
const props = withDefaults(
defineProps<{
type: GraphQLNamedType
showAddField: boolean
}>(),
{
showAddField: true,
}
)
const fieldMap = computed(() => {
if (
!isObjectType(props.type) &&
!isInterfaceType(props.type) &&
!isInputObjectType(props.type)
) {
return {}
}
return props.type.getFields()
})
const fields = computed(() => {
return Object.values(fieldMap.value) as ExplorerFieldDef[]
})
</script>