Type.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <div :id="`type_${gqlType.name}`" class="p-4">
  3. <div class="type-title" :class="{ 'text-accent': isHighlighted }">
  4. <span v-if="isInput" class="text-accent">input </span>
  5. <span v-else-if="isInterface" class="text-accent">interface </span>
  6. <span v-else-if="isEnum" class="text-accent">enum </span>
  7. {{ gqlType.name }}
  8. </div>
  9. <div v-if="gqlType.description" class="text-secondaryLight py-2 type-desc">
  10. {{ gqlType.description }}
  11. </div>
  12. <div v-if="interfaces.length > 0">
  13. <h5 class="my-2">Interfaces:</h5>
  14. <div
  15. v-for="(gqlInterface, index) in interfaces"
  16. :key="`gqlInterface-${index}`"
  17. >
  18. <GraphqlTypeLink
  19. :gql-type="gqlInterface"
  20. :jump-type-callback="jumpTypeCallback"
  21. class="border-divider border-l-2 pl-4"
  22. />
  23. </div>
  24. </div>
  25. <div v-if="children.length > 0" class="mb-2">
  26. <h5 class="my-2">Children:</h5>
  27. <GraphqlTypeLink
  28. v-for="(child, index) in children"
  29. :key="`child-${index}`"
  30. :gql-type="child"
  31. :jump-type-callback="jumpTypeCallback"
  32. class="border-divider border-l-2 pl-4"
  33. />
  34. </div>
  35. <div v-if="gqlType.getFields">
  36. <h5 class="my-2">Fields:</h5>
  37. <GraphqlField
  38. v-for="(field, index) in gqlType.getFields()"
  39. :key="`field-${index}`"
  40. class="border-divider border-l-2 pl-4"
  41. :gql-field="field"
  42. :is-highlighted="isFieldHighlighted({ field })"
  43. :jump-type-callback="jumpTypeCallback"
  44. />
  45. </div>
  46. <div v-if="isEnum">
  47. <h5 class="my-2">Values:</h5>
  48. <div
  49. v-for="(value, index) in gqlType.getValues()"
  50. :key="`value-${index}`"
  51. class="border-divider border-l-2 pl-4"
  52. v-text="value.name"
  53. ></div>
  54. </div>
  55. </div>
  56. </template>
  57. <script>
  58. import { defineComponent } from "@nuxtjs/composition-api"
  59. import {
  60. GraphQLEnumType,
  61. GraphQLInputObjectType,
  62. GraphQLInterfaceType,
  63. } from "graphql"
  64. export default defineComponent({
  65. props: {
  66. // eslint-disable-next-line vue/require-default-prop, vue/require-prop-types
  67. gqlType: {},
  68. gqlTypes: { type: Array, default: () => [] },
  69. jumpTypeCallback: { type: Function, default: () => {} },
  70. isHighlighted: { type: Boolean, default: false },
  71. highlightedFields: { type: Array, default: () => [] },
  72. },
  73. computed: {
  74. isInput() {
  75. return this.gqlType instanceof GraphQLInputObjectType
  76. },
  77. isInterface() {
  78. return this.gqlType instanceof GraphQLInterfaceType
  79. },
  80. isEnum() {
  81. return this.gqlType instanceof GraphQLEnumType
  82. },
  83. interfaces() {
  84. return (this.gqlType.getInterfaces && this.gqlType.getInterfaces()) || []
  85. },
  86. children() {
  87. return this.gqlTypes.filter(
  88. (type) =>
  89. type.getInterfaces && type.getInterfaces().includes(this.gqlType)
  90. )
  91. },
  92. },
  93. methods: {
  94. isFieldHighlighted({ field }) {
  95. return !!this.highlightedFields.find(({ name }) => name === field.name)
  96. },
  97. },
  98. })
  99. </script>
  100. <style scoped lang="scss">
  101. .type-highlighted {
  102. @apply text-accent;
  103. }
  104. </style>