@redocly/graphql-docs
Version:
Redocly GraphQL docs
2 lines (1 loc) • 1.4 kB
JavaScript
import{getNamedType as i,isUnionType as p}from"graphql";import{getTypeField as n,getTypeGroup as a,isExcludedType as o,isFieldsType as h,TypeGroup as u}from"../schema/index.js";class T{schema;referenceMap=new Map;constructor(e){this.schema=e,this.createReferenceMap()}getQueryType(){return this.schema.getQueryType()}getQueryField(e){const t=this.getQueryType();return t&&n(t,e)}getMutationType(){return this.schema.getMutationType()}getMutationField(e){const t=this.getMutationType();return t&&n(t,e)}getSubscriptionType(){return this.schema.getSubscriptionType()}getSubscriptionField(e){const t=this.getSubscriptionType();return t&&n(t,e)}getDirective(e){return this.schema.getDirective(e)||void 0}getType(e){return this.schema.getType(e)||void 0}getTypeReferences(e){return this.referenceMap.get(e)}createReferenceMap(){const e=this.schema.getTypeMap();Object.values(e).forEach(t=>{!o(t,this.schema)&&h(t)?this.setFieldsTypeReferences(t):p(t)&&this.setUnionTypeReferences(t)})}setFieldsTypeReferences(e){const t=e.getFields();Object.values(t).forEach(s=>{const r=i(s.type),c={name:e.name,field:s.name,group:a(e)};this.setReference(r.name,c)})}setUnionTypeReferences(e){e.getTypes().forEach(t=>{const s=i(t),r={name:e.name,group:u.unions};this.setReference(s.name,r)})}setReference(e,t){const s=this.referenceMap.get(e);s?.length?s.push(t):this.referenceMap.set(e,[t])}}export{T as AppStore};