api-client/components/graphql/Type.vue

107 lines
3 KiB
Vue
Raw Normal View History

2019-11-18 20:17:07 +00:00
<template>
2021-07-09 07:39:52 +00:00
<div :id="`type_${gqlType.name}`" class="p-4">
<div class="type-title" :class="{ 'text-accent': isHighlighted }">
2021-06-21 11:01:40 +00:00
<span v-if="isInput" class="text-accent">input </span>
<span v-else-if="isInterface" class="text-accent">interface </span>
<span v-else-if="isEnum" class="text-accent">enum </span>
2020-10-04 09:46:16 +00:00
{{ gqlType.name }}
</div>
<div v-if="gqlType.description" class="text-secondaryLight py-2 type-desc">
{{ gqlType.description }}
2019-11-18 20:17:07 +00:00
</div>
2021-07-09 07:39:52 +00:00
<div v-if="interfaces.length > 0">
<h5 class="my-2">Interfaces:</h5>
2021-07-13 23:49:08 +00:00
<div
v-for="(gqlInterface, index) in interfaces"
:key="`gqlInterface-${index}`"
>
2021-05-19 04:54:57 +00:00
<GraphqlTypeLink
:gql-type="gqlInterface"
:jump-type-callback="jumpTypeCallback"
2021-07-17 17:40:28 +00:00
class="border-divider border-l-2 pl-4"
2021-05-19 04:54:57 +00:00
/>
</div>
</div>
<div v-if="children.length > 0" class="mb-2">
<h5 class="my-2">Children:</h5>
2021-07-09 07:39:52 +00:00
<GraphqlTypeLink
2021-07-13 23:49:08 +00:00
v-for="(child, index) in children"
:key="`child-${index}`"
2021-07-09 07:39:52 +00:00
:gql-type="child"
:jump-type-callback="jumpTypeCallback"
2021-07-17 17:40:28 +00:00
class="border-divider border-l-2 pl-4"
2021-07-09 07:39:52 +00:00
/>
</div>
2019-11-18 20:17:07 +00:00
<div v-if="gqlType.getFields">
<h5 class="my-2">Fields:</h5>
2021-07-09 07:39:52 +00:00
<GraphqlField
2021-07-13 23:49:08 +00:00
v-for="(field, index) in gqlType.getFields()"
:key="`field-${index}`"
2021-07-17 17:40:28 +00:00
class="border-divider border-l-2 pl-4"
2021-07-09 07:39:52 +00:00
:gql-field="field"
:is-highlighted="isFieldHighlighted({ field })"
:jump-type-callback="jumpTypeCallback"
/>
2019-11-18 20:17:07 +00:00
</div>
<div v-if="isEnum">
<h5 class="my-2">Values:</h5>
2021-05-19 04:54:57 +00:00
<div
2021-07-13 23:49:08 +00:00
v-for="(value, index) in gqlType.getValues()"
:key="`value-${index}`"
2021-07-17 17:40:28 +00:00
class="border-divider border-l-2 pl-4"
2021-05-19 04:54:57 +00:00
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 {
2021-06-12 16:46:17 +00:00
@apply text-accent;
2021-05-19 04:54:57 +00:00
}
</style>