api-client/components/graphql/Type.vue

110 lines
2.9 KiB
Vue
Raw Normal View History

2019-11-18 20:17:07 +00:00
<template>
<div :id="`type_${gqlType.name}`" class="p-2 m-2">
2021-05-19 04:54:57 +00:00
<div
class="font-bold type-title"
:class="{ 'type-highlighted': isHighlighted }"
>
<span v-if="isInput" class="font-normal text-acColor">input </span>
2021-05-19 04:54:57 +00:00
<span v-else-if="isInterface" class="font-normal text-acColor"
>interface
</span>
<span v-else-if="isEnum" class="font-normal text-acColor">enum </span>
2020-10-04 09:46:16 +00:00
{{ gqlType.name }}
</div>
2021-05-19 04:54:57 +00:00
<div v-if="gqlType.description" class="mt-2 text-fgLightColor type-desc">
{{ gqlType.description }}
2019-11-18 20:17:07 +00:00
</div>
<div v-if="interfaces.length > 0" class="mb-2">
<h5>{{ $t("interfaces") }}</h5>
2021-05-19 04:54:57 +00:00
<div
v-for="gqlInterface in interfaces"
:key="gqlInterface.name"
class="m-2 ml-4"
>
<GraphqlTypeLink
:gql-type="gqlInterface"
:jump-type-callback="jumpTypeCallback"
/>
</div>
</div>
<div v-if="children.length > 0" class="mb-2">
<h5>{{ $t("children") }}</h5>
<div v-for="child in children" :key="child.name" class="m-2 ml-4">
2021-05-19 04:54:57 +00:00
<GraphqlTypeLink
:gql-type="child"
:jump-type-callback="jumpTypeCallback"
/>
</div>
</div>
2019-11-18 20:17:07 +00:00
<div v-if="gqlType.getFields">
<h5>{{ $t("fields") }}</h5>
2019-11-18 20:17:07 +00:00
<div v-for="field in gqlType.getFields()" :key="field.name">
<GraphqlField
2021-05-19 04:54:57 +00:00
:gql-field="field"
:is-highlighted="isFieldHighlighted({ field })"
:jump-type-callback="jumpTypeCallback"
2020-10-04 09:46:16 +00:00
/>
2019-11-18 20:17:07 +00:00
</div>
</div>
<div v-if="isEnum">
<h5>{{ $t("values") }}</h5>
2021-05-19 04:54:57 +00:00
<div
v-for="value in gqlType.getValues()"
:key="value.name"
class="m-4"
v-text="value.name"
></div>
</div>
2019-11-18 20:17:07 +00:00
</div>
</template>
<script>
2021-05-19 04:54:57 +00:00
import {
GraphQLEnumType,
GraphQLInputObjectType,
GraphQLInterfaceType,
} from "graphql"
2019-11-18 20:17:07 +00:00
export default {
props: {
2021-05-19 04:54:57 +00:00
// eslint-disable-next-line vue/require-default-prop, vue/require-prop-types
gqlType: {},
2021-05-19 04:54:57 +00:00
gqlTypes: { type: Array, default: () => [] },
jumpTypeCallback: { type: Function, default: () => {} },
2020-10-04 09:46:16 +00:00
isHighlighted: { type: Boolean, default: false },
highlightedFields: { type: Array, default: () => [] },
2020-10-04 09:46:16 +00:00
},
computed: {
isInput() {
return this.gqlType instanceof GraphQLInputObjectType
},
isInterface() {
return this.gqlType instanceof GraphQLInterfaceType
},
isEnum() {
return this.gqlType instanceof GraphQLEnumType
},
interfaces() {
2021-02-09 02:11:18 +00:00
return (this.gqlType.getInterfaces && this.gqlType.getInterfaces()) || []
},
children() {
return this.gqlTypes.filter(
2021-05-19 04:54:57 +00:00
(type) =>
type.getInterfaces && type.getInterfaces().includes(this.gqlType)
)
},
},
2021-05-19 04:54:57 +00:00
methods: {
isFieldHighlighted({ field }) {
return !!this.highlightedFields.find(({ name }) => name === field.name)
},
},
2020-02-24 18:44:50 +00:00
}
2019-11-18 20:17:07 +00:00
</script>
2021-05-19 04:54:57 +00:00
<style scoped lang="scss">
.type-highlighted {
@apply text-acColor;
}
</style>