api-client/components/graphql/TypeLink.vue

45 lines
904 B
Vue
Raw Normal View History

<template>
<span
2021-07-09 07:39:52 +00:00
:class="isScalar ? 'text-secondaryLight' : 'cursor-pointer text-accent'"
class="font-mono"
2021-07-05 12:56:00 +00:00
@click="jumpToType"
>
2020-09-22 17:06:37 +00:00
{{ typeString }}
</span>
</template>
<script>
import { GraphQLScalarType } from "graphql"
export default {
props: {
2021-05-22 15:20:23 +00:00
// eslint-disable-next-line vue/require-default-prop
gqlType: null,
// (typeName: string) => void
2021-05-22 15:20:23 +00:00
// eslint-disable-next-line vue/require-default-prop
2020-02-24 18:44:50 +00:00
jumpTypeCallback: Function,
},
computed: {
typeString() {
2020-02-24 18:44:50 +00:00
return this.gqlType.toString()
},
isScalar() {
return this.resolveRootType(this.gqlType) instanceof GraphQLScalarType
},
},
methods: {
jumpToType() {
if (this.isScalar) return
2020-02-24 18:44:50 +00:00
this.jumpTypeCallback(this.gqlType)
},
resolveRootType(type) {
let t = type
while (t.ofType != null) t = t.ofType
return t
},
2020-02-24 18:44:50 +00:00
},
}
</script>