TypeLink.vue 957 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <template>
  2. <span
  3. :class="isScalar ? 'text-secondaryLight' : 'cursor-pointer text-accent'"
  4. @click="jumpToType"
  5. >
  6. {{ typeString }}
  7. </span>
  8. </template>
  9. <script>
  10. import { defineComponent } from "@nuxtjs/composition-api"
  11. import { GraphQLScalarType } from "graphql"
  12. export default defineComponent({
  13. props: {
  14. // eslint-disable-next-line vue/require-default-prop
  15. gqlType: null,
  16. // (typeName: string) => void
  17. // eslint-disable-next-line vue/require-default-prop
  18. jumpTypeCallback: Function,
  19. },
  20. computed: {
  21. typeString() {
  22. return this.gqlType.toString()
  23. },
  24. isScalar() {
  25. return this.resolveRootType(this.gqlType) instanceof GraphQLScalarType
  26. },
  27. },
  28. methods: {
  29. jumpToType() {
  30. if (this.isScalar) return
  31. this.jumpTypeCallback(this.gqlType)
  32. },
  33. resolveRootType(type) {
  34. let t = type
  35. while (t.ofType != null) t = t.ofType
  36. return t
  37. },
  38. },
  39. })
  40. </script>