UNPKG

@cran/gql.reflect

Version:

Cranberry Introspection Utilities for GraphQL

49 lines (48 loc) 1.35 kB
import { ReflectElement } from "./ReflectElement"; import { _TypeKind } from "../input/_TypeKind"; export class ReflectProperty extends ReflectElement { source; fqdn; required; list; strict; typeName; constructor($, _, source) { super($, _); this.source = source; Object.assign(this, this.getModifiers()); this.fqdn = this.getFqdn(); } get type() { return this.$.types[this.typeName]; } getModifiers() { let type = this._.type; let required = false; let list = false; let strict = false; if (type.kind === _TypeKind.NON_NULL) { required = true; type = type.ofType; } if (type.kind === _TypeKind.LIST) { list = true; type = type.ofType; // TODO nested lists? if (type.kind === _TypeKind.NON_NULL) { strict = true; type = type.ofType; } } return { required, list, strict, typeName: type.name, }; } getFqdn() { let source = this.source; const path = [source.name,]; while (source instanceof ReflectProperty) { source = source.source; path.unshift(source.name); } return `${path.join(".")}.${this.name}`; } }