import{buildSchema as d}from"graphql";import{MenuStore as f,AppStore as g}from"@redocly/graphql-docs";import h from"node:path";import{combineUrls as u}from"@redocly/theme/core/utils";import{GRAPHQL_SPEC_SLUG as w}from"../../../constants/common.js";import{deepMerge as q}from"../../../utils/object/deep-merge.js";import{reporter as S}from"../../tools/notifiers/reporter.js";import{getApiConfigByPath as b}from"../get-api-config.js";import{replaceFileExtension as x}from"../openapi-docs/store-definition-bundles.js";const E=async(r,{getConfig:i,fs:c})=>{const e=await i(),o=e?.graphql??{},t=await c.read(r),{graphql:n={},metadata:m}=b(e.apis,r),s=q(o||{},n,{feedback:o.feedback||e.feedback,downloadUrls:o.downloadUrls||[{url:u(w,`${x(r,h.posix.extname(r))}?download`)}]});let p,l;try{const a=d(t);l=new g(a),p=new f(a,s)}catch(a){await S.panicOnBuild(a);return}return{menu:p,store:l,settings:s,metadata:m,content:t}},F=async(r,{fs:i,cache:c,isPathIgnored:e})=>{const o=[];for(const{relativePath:t}of i.scan(/(\.gql|\.graphql)$/)){if(await e(t))continue;const n=await c.load(t,"graphql-doc").catch(()=>null);n?.data&&o.push({relativePath:t,settings:n.data.settings})}return o};export{E as graphqlDocLoader,F as graphqlDocsLoader};
