MCPcopy Create free account
hub / github.com/github/docs / getType

Function getType

src/graphql/scripts/utils/schema-helpers.js:109–152  ·  view source on GitHub ↗
(field)

Source from the content-addressed store, hash-verified

107// 3. non-null lists: `[foo]!`, `[foo!]!`
108// see https://github.com/rmosolgo/graphql-ruby/blob/master/guides/type_definitions/lists.md#lists-nullable-lists-and-lists-of-nulls
109function getType(field) {
110 // 1. single items
111 if (field.type.kind !== 'ListType') {
112 // nullable item, e.g. `license` query has `License` type
113 if (field.type.kind === 'NamedType') {
114 return field.type.name.value
115 }
116
117 // non-null item, e.g. `meta` query has `GitHubMetadata!` type
118 if (field.type.kind === 'NonNullType' && field.type.type.kind === 'NamedType') {
119 return `${field.type.type.name.value}!`
120 }
121 }
122 // 2. nullable lists
123 if (field.type.kind === 'ListType') {
124 // nullable items, e.g. `codesOfConduct` query has `[CodeOfConduct]` type
125 if (field.type.type.kind === 'NamedType') {
126 return `[${field.type.type.name.value}]`
127 }
128
129 // non-null items, e.g. `severities` arg has `[SecurityAdvisorySeverity!]` type
130 if (field.type.type.kind === 'NonNullType' && field.type.type.type.kind === 'NamedType') {
131 return `[${field.type.type.type.name.value}!]`
132 }
133 }
134
135 // 3. non-null lists
136 if (field.type.kind === 'NonNullType' && field.type.type.kind === 'ListType') {
137 // nullable items, e.g. `licenses` query has `[License]!` type
138 if (field.type.type.type.kind === 'NamedType') {
139 return `[${field.type.type.type.name.value}]!`
140 }
141
142 // non-null items, e.g. `marketplaceCategories` query has `[MarketplaceCategory!]!` type
143 if (
144 field.type.type.type.kind === 'NonNullType' &&
145 field.type.type.type.type.kind === 'NamedType'
146 ) {
147 return `[${field.type.type.type.type.name.value}!]!`
148 }
149 }
150
151 console.error(`cannot get type of ${field.name.value}`)
152}
153
154function getTypeKind(type, schema) {
155 type = removeMarkers(type)

Callers 1

getArgumentsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected