nuxt-graphql-middleware 5.0.0-alpha.2 → 5.0.0-alpha.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/README.md +101 -19
  2. package/dist/client/200.html +10 -10
  3. package/dist/client/404.html +10 -10
  4. package/dist/client/_nuxt/BM34SYth.js +1 -0
  5. package/dist/client/_nuxt/CROlboVl.js +1 -0
  6. package/dist/client/_nuxt/D5hBL5aZ.js +25 -0
  7. package/dist/client/_nuxt/FTbv7CO6.js +1 -0
  8. package/dist/client/_nuxt/builds/latest.json +1 -1
  9. package/dist/client/_nuxt/builds/meta/de61b0f7-ec5c-4f2f-addb-b5017c30afb1.json +1 -0
  10. package/dist/client/_nuxt/entry.Cn9qfNGa.css +1 -0
  11. package/dist/client/_nuxt/error-404.ehK72JOs.css +1 -0
  12. package/dist/client/_nuxt/error-500._g0akJim.css +1 -0
  13. package/dist/client/_nuxt/index.DGEN-H8t.css +1 -0
  14. package/dist/client/_nuxt/lIgCBhS_.js +2 -0
  15. package/dist/client/index.html +10 -10
  16. package/dist/client-options.d.mts +6 -0
  17. package/dist/client-options.mjs +5 -0
  18. package/dist/module.d.mts +74 -340
  19. package/dist/module.json +4 -4
  20. package/dist/module.mjs +1384 -589
  21. package/dist/runtime/components/CodeFrame.vue +52 -0
  22. package/dist/runtime/components/CodeFrame.vue.d.ts +7 -0
  23. package/dist/runtime/components/DevModeOverlay.vue +52 -0
  24. package/dist/runtime/components/DevModeOverlay.vue.d.ts +3 -0
  25. package/dist/runtime/components/ErrorExtensions.vue +21 -0
  26. package/dist/runtime/components/ErrorExtensions.vue.d.ts +5 -0
  27. package/dist/runtime/components/ErrorGroup.vue +78 -0
  28. package/dist/runtime/components/ErrorGroup.vue.d.ts +9 -0
  29. package/dist/runtime/composables/nuxtApp.d.ts +2 -2
  30. package/dist/runtime/composables/nuxtApp.js +21 -1
  31. package/dist/runtime/composables/useAsyncGraphqlQuery.d.ts +7 -7
  32. package/dist/runtime/composables/useAsyncGraphqlQuery.js +10 -2
  33. package/dist/runtime/composables/useGraphqlMutation.d.ts +4 -4
  34. package/dist/runtime/composables/useGraphqlMutation.js +1 -1
  35. package/dist/runtime/composables/useGraphqlQuery.d.ts +4 -4
  36. package/dist/runtime/composables/useGraphqlQuery.js +1 -1
  37. package/dist/runtime/composables/useGraphqlState.d.ts +1 -1
  38. package/dist/runtime/composables/useGraphqlState.js +1 -1
  39. package/dist/runtime/composables/useGraphqlUploadMutation.d.ts +4 -4
  40. package/dist/runtime/composables/useGraphqlUploadMutation.js +2 -2
  41. package/dist/runtime/css/output.css +1 -0
  42. package/dist/runtime/helpers/composables.d.ts +17 -20
  43. package/dist/runtime/helpers/composables.js +0 -5
  44. package/dist/runtime/plugins/devMode.d.ts +2 -0
  45. package/dist/runtime/plugins/devMode.js +23 -0
  46. package/dist/runtime/plugins/provideState.d.ts +1 -1
  47. package/dist/runtime/{serverHandler → server/api}/debug.js +3 -7
  48. package/dist/runtime/server/api/mutation.js +29 -0
  49. package/dist/runtime/server/api/query.js +30 -0
  50. package/dist/runtime/server/api/upload.d.ts +2 -0
  51. package/dist/runtime/{serverHandler → server/api}/upload.js +13 -11
  52. package/dist/runtime/{serverHandler → server}/helpers/index.d.ts +10 -12
  53. package/dist/runtime/{serverHandler → server}/helpers/index.js +9 -26
  54. package/dist/runtime/server/utils/doGraphqlRequest.d.ts +18 -0
  55. package/dist/runtime/server/utils/doGraphqlRequest.js +68 -0
  56. package/dist/runtime/server/utils/index.d.ts +1 -1
  57. package/dist/runtime/server/utils/index.js +1 -1
  58. package/dist/runtime/server/utils/useGraphqlMutation.d.ts +4 -4
  59. package/dist/runtime/server/utils/useGraphqlQuery.d.ts +4 -4
  60. package/dist/runtime/settings/index.d.ts +0 -14
  61. package/dist/runtime/settings/index.js +0 -6
  62. package/dist/runtime/types.d.ts +204 -3
  63. package/dist/server-options.d.mts +8 -0
  64. package/dist/server-options.mjs +5 -0
  65. package/dist/shared/nuxt-graphql-middleware.xfMm4rGk.d.mts +523 -0
  66. package/dist/types.d.mts +1 -7
  67. package/dist/utils.d.mts +15 -0
  68. package/dist/utils.mjs +18 -0
  69. package/package.json +64 -57
  70. package/dist/client/_nuxt/BS583yk8.js +0 -25
  71. package/dist/client/_nuxt/CZ2Qwgdk.js +0 -2
  72. package/dist/client/_nuxt/DpxjPVZy.js +0 -1
  73. package/dist/client/_nuxt/GOrnHr4p.js +0 -1
  74. package/dist/client/_nuxt/builds/meta/f823ebfd-daab-468f-8f6f-07a236da64bd.json +0 -1
  75. package/dist/client/_nuxt/entry.AjgXSF89.css +0 -1
  76. package/dist/client/_nuxt/error-404.BJkSn6RI.css +0 -1
  77. package/dist/client/_nuxt/error-500.TOCKLquH.css +0 -1
  78. package/dist/client/_nuxt/exxdaCPN.js +0 -1
  79. package/dist/client/_nuxt/index.D19Q16VT.css +0 -1
  80. package/dist/module.cjs +0 -5
  81. package/dist/module.d.ts +0 -358
  82. package/dist/runtime/clientOptions/index.d.ts +0 -2
  83. package/dist/runtime/clientOptions/index.js +0 -3
  84. package/dist/runtime/serverHandler/index.js +0 -78
  85. package/dist/runtime/serverHandler/tsconfig.json +0 -3
  86. package/dist/runtime/serverOptions/defineGraphqlServerOptions.d.ts +0 -3
  87. package/dist/runtime/serverOptions/defineGraphqlServerOptions.js +0 -3
  88. package/dist/runtime/serverOptions/index.d.ts +0 -2
  89. package/dist/runtime/serverOptions/index.js +0 -2
  90. package/dist/types.d.ts +0 -7
  91. /package/dist/runtime/{serverHandler → server/api}/debug.d.ts +0 -0
  92. /package/dist/runtime/{serverHandler/index.d.ts → server/api/mutation.d.ts} +0 -0
  93. /package/dist/runtime/{serverHandler/upload.d.ts → server/api/query.d.ts} +0 -0
@@ -0,0 +1,2 @@
1
+ import{d as L,t as w,v as g,H as z,I as Ie,r as W,J as ie,j as O,K as ae,L as T,M as he,N as ze,O as x,x as v,P as fe,Q as me,R as P,S as F,y as V,T as Fe,U as Ve,V as B,W as ne,z as N,A as Y,B as re,X as Te,_ as Me}from"./D5hBL5aZ.js";const pe=L({__name:"NIcon",props:{icon:{}},setup(o){return(e,t)=>(g(),w("div",{class:z(["n-icon",e.icon])},null,2))}});typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Oe=o=>typeof o<"u";function Le(o){return JSON.parse(JSON.stringify(o))}function _e(o,e,t,n={}){var s,i,r;const{clone:c=!1,passive:l=!1,eventName:d,deep:u=!1,defaultValue:a,shouldEmit:f}=n,m=Ie(),p=t||(m==null?void 0:m.emit)||((s=m==null?void 0:m.$emit)==null?void 0:s.bind(m))||((r=(i=m==null?void 0:m.proxy)==null?void 0:i.$emit)==null?void 0:r.bind(m==null?void 0:m.proxy));let h=d;e||(e="modelValue"),h=h||`update:${e.toString()}`;const _=S=>c?typeof c=="function"?c(S):Le(S):S,k=()=>Oe(o[e])?_(o[e]):a,b=S=>{f?f(S)&&p(h,S):p(h,S)};if(l){const S=k(),$=W(S);let I=!1;return ie(()=>o[e],C=>{I||(I=!0,$.value=_(C),ae(()=>I=!1))}),ie($,C=>{!I&&(C!==o[e]||u)&&b(C)},{deep:u}),$}else return O({get(){return k()},set(S){b(S)}})}const $e={class:"n-text-input flex flex items-center border n-border-base rounded py-1 pl-1 pr-2 focus-within:n-focus-base focus-within:border-context n-bg-base"},Ee=L({__name:"NTextInput",props:{modelValue:{default:""},icon:{},placeholder:{},disabled:{type:Boolean},autofocus:{type:Boolean},autocomplete:{},readonly:{type:Boolean},type:{default:"text"}},emits:["keydown","keyup","change"],setup(o,{emit:e}){const s=_e(o,"modelValue",e,{passive:!0});return(i,r)=>{const c=pe;return g(),w("div",$e,[T(i.$slots,"icon",{},()=>[i.icon?(g(),P(c,{key:0,icon:i.icon,class:"ml-0.3em mr-0.1em text-1.1em op50"},null,8,["icon"])):F("",!0)]),he(v("input",fe({"onUpdate:modelValue":r[0]||(r[0]=l=>me(s)?s.value=l:null)},i.$props,{class:"ml-0.4em w-full flex-auto n-bg-base !outline-none"}),null,16),[[ze,x(s)]])])}}}),ge=L({__name:"Tag",props:{green:{type:Boolean},orange:{type:Boolean},text:{}},setup(o){const e=o,t=O(()=>e.green?"bg-green-400:10 text-green-400":e.orange?"bg-orange-400:10 text-orange-400":"bg-gray-400:10 text-gray");return(n,s)=>(g(),w("span",{class:z(["mx-0.5 select-none whitespace-nowrap rounded px-1.5 py-0.5 text-xs inline-block",x(t)])},V(n.text),3))}});let E;const j=[];function ve(o){if(j.push(o),!(typeof window>"u"))return window.__NUXT_DEVTOOLS__&&j.forEach(e=>e(window.__NUXT_DEVTOOLS__)),Object.defineProperty(window,"__NUXT_DEVTOOLS__",{set(e){e&&j.forEach(t=>t(e))},get(){return E.value},configurable:!0}),()=>{j.splice(j.indexOf(o),1)}}function De(){E||(E=Fe(),ve(e));function o(){E&&Ve(E)}function e(t){E.value=t,t.host&&t.host.hooks.hook("host:update:reactivity",o)}return E}const Ne=De(),Ae=["innerHTML"],Pe=["textContent"],Be=L({__name:"NCodeBlock",props:{code:{},lang:{},lines:{type:Boolean,default:!0},inline:{type:Boolean},grammarContextCode:{},transformRendered:{}},emits:["loaded"],setup(o,{emit:e}){const t=o,n=e,s=O(()=>{var c;const r=t.lang==="text"?{code:t.code,supported:!1}:((c=Ne.value)==null?void 0:c.devtools.renderCodeHighlight(t.code,t.lang,{grammarContextCode:t.grammarContextCode}))||{code:t.code,supported:!1};return r.supported&&t.transformRendered&&(r.code=t.transformRendered(r.code)),r.supported&&ae(()=>n("loaded")),r}),i=O(()=>["n-code-block shiki",t.lines&&!t.inline?"n-code-block-lines":""]);return(r,c)=>r.lang&&s.value.supported?(g(),w("pre",{key:0,class:z(i.value)},[v("code",{innerHTML:s.value.code},null,8,Ae)],2)):(g(),w("pre",{key:1,class:z(i.value)},[v("code",null,[(g(!0),w(B,null,ne(r.code.split(`
2
+ `),(l,d)=>(g(),w(B,{key:d},[v("span",{class:"line",textContent:V(l)},null,8,Pe),c[0]||(c[0]=v("br",null,null,-1))],64))),128))])],2))}}),Re={flex:"~ gap-3","items-center":""},je=L({__name:"NIconTitle",props:{icon:{},text:{}},setup(o){return(e,t)=>(g(),w("div",Re,[e.icon?(g(),w("div",{key:0,class:z(e.icon)},null,2)):F("",!0),T(e.$slots,"default",{},()=>[v("div",null,V(e.text),1)])]))}}),We=["open"],Ue={"text-base":""},Je={key:0,"text-sm":"",op50:""},Qe=L({__name:"NSectionBlock",props:{icon:{},text:{},description:{},containerClass:{default:""},headerClass:{},collapse:{type:Boolean,default:!0},open:{type:Boolean,default:!0},padding:{type:[Boolean,String],default:!0}},setup(o){const t=_e(o,"open",void 0,{passive:!0});function n(s){t.value=s.target.open}return(s,i)=>{const r=pe,c=je;return g(),w(B,null,[v("details",{open:x(t),onToggle:i[0]||(i[0]=(...l)=>n&&n(...l))},[v("summary",{class:z(["cursor-pointer select-none hover:bg-active p4",s.collapse?"":"pointer-events-none"])},[N(c,{icon:s.icon,text:s.text,"text-xl":"",transition:"",class:z([x(t)?"op100":"op60",s.headerClass])},{default:Y(()=>[v("div",null,[v("div",Ue,[T(s.$slots,"text",{},()=>[re(V(s.text),1)],!0)]),s.description||s.$slots.description?(g(),w("div",Je,[T(s.$slots,"description",{},()=>[re(V(s.description),1)],!0)])):F("",!0)]),i[1]||(i[1]=v("div",{class:"flex-auto"},null,-1)),T(s.$slots,"actions",{},void 0,!0),s.collapse?(g(),P(r,{key:0,icon:"carbon-chevron-down",class:"chevron","cursor-pointer":"","place-self-start":"","text-base":"",op75:"",transition:"","duration-500":""})):F("",!0)]),_:3},8,["icon","text","class"])],2),i._lazyshow1||x(t)?(i._lazyshow1=!0,g(),w(B,null,[he(v("div",{class:z(["flex flex-col flex-gap2 pb6 pt2",typeof s.padding=="string"?s.padding:s.padding?"px4":""])},[T(s.$slots,"details",{},void 0,!0),v("div",{class:z([s.containerClass,"mt1"])},[T(s.$slots,"default",{},void 0,!0)],2),T(s.$slots,"footer",{},void 0,!0)],2),[[Te,x(t)]])],64)):F("v-show-if",!0)],40,We),i[2]||(i[2]=v("div",{class:"x-divider"},null,-1))],64)}}}),qe=Me(Qe,[["__scopeId","data-v-f3591bcd"]]),Ge={class:"h-full of-auto p2"},He={class:"p5"},Ke={class:"font-mono mb4 font-bold text-3xl"},Xe={key:0,class:"mb3"},Ye=["href"],Ze={key:0,class:"font-mono bg-red-900 text-red-100 p2"},et=L({__name:"DocumentDetail",props:{id:{},timestamp:{},source:{},name:{},identifier:{},filePath:{},serverApiPrefix:{}},setup(o){const e=o,t=O(()=>[]),n=O(()=>e.identifier!=="fragment"?`${e.serverApiPrefix}/${e.identifier}/${e.name}`:null);return(s,i)=>{const r=ge,c=Be,l=qe;return g(),w("div",Ge,[v("div",He,[v("h2",Ke,V(s.name),1),x(n)?(g(),w("div",Xe,[s.identifier==="query"?(g(),P(r,{key:0,green:"",text:"GET"})):(g(),P(r,{key:1,orange:"",text:"POST"})),v("a",{class:"n-transition n-link n-link-base hover:n-link-hover ml2",target:"_blank",href:x(n)},V(x(n)),9,Ye)])):F("",!0)]),N(l,{text:"Document",description:s.filePath,padding:"px4"},{default:Y(()=>[N(c,{code:s.source,lang:"graphql"},null,8,["code"])]),_:1},8,["description"]),N(l,{text:"Errors",description:x(t).length+" errors",padding:"px4"},{default:Y(()=>[x(t).length?(g(),w("div",Ze,[(g(!0),w(B,null,ne(x(t),(d,u)=>(g(),w("div",{key:u},V(d),1))),128))])):F("",!0)]),_:1},8,["description"])])}}}),tt="ENTRIES",we="KEYS",ye="VALUES",y="";class q{constructor(e,t){const n=e._tree,s=Array.from(n.keys());this.set=e,this._type=t,this._path=s.length>0?[{node:n,keys:s}]:[]}next(){const e=this.dive();return this.backtrack(),e}dive(){if(this._path.length===0)return{done:!0,value:void 0};const{node:e,keys:t}=D(this._path);if(D(t)===y)return{done:!1,value:this.result()};const n=e.get(D(t));return this._path.push({node:n,keys:Array.from(n.keys())}),this.dive()}backtrack(){if(this._path.length===0)return;const e=D(this._path).keys;e.pop(),!(e.length>0)&&(this._path.pop(),this.backtrack())}key(){return this.set._prefix+this._path.map(({keys:e})=>D(e)).filter(e=>e!==y).join("")}value(){return D(this._path).node.get(y)}result(){switch(this._type){case ye:return this.value();case we:return this.key();default:return[this.key(),this.value()]}}[Symbol.iterator](){return this}}const D=o=>o[o.length-1],nt=(o,e,t)=>{const n=new Map;if(e===void 0)return n;const s=e.length+1,i=s+t,r=new Uint8Array(i*s).fill(t+1);for(let c=0;c<s;++c)r[c]=c;for(let c=1;c<i;++c)r[c*s]=c;return xe(o,e,t,n,r,1,s,""),n},xe=(o,e,t,n,s,i,r,c)=>{const l=i*r;e:for(const d of o.keys())if(d===y){const u=s[l-1];u<=t&&n.set(c,[o.get(d),u])}else{let u=i;for(let a=0;a<d.length;++a,++u){const f=d[a],m=r*u,p=m-r;let h=s[m];const _=Math.max(0,u-t-1),k=Math.min(r-1,u+t);for(let b=_;b<k;++b){const S=f!==e[b],$=s[p+b]+ +S,I=s[p+b+1]+1,C=s[m+b]+1,R=s[m+b+1]=Math.min($,I,C);R<h&&(h=R)}if(h>t)continue e}xe(o.get(d),e,t,n,s,u,r,c+d)}};class M{constructor(e=new Map,t=""){this._size=void 0,this._tree=e,this._prefix=t}atPrefix(e){if(!e.startsWith(this._prefix))throw new Error("Mismatched prefix");const[t,n]=Q(this._tree,e.slice(this._prefix.length));if(t===void 0){const[s,i]=se(n);for(const r of s.keys())if(r!==y&&r.startsWith(i)){const c=new Map;return c.set(r.slice(i.length),s.get(r)),new M(c,e)}}return new M(t,e)}clear(){this._size=void 0,this._tree.clear()}delete(e){return this._size=void 0,st(this._tree,e)}entries(){return new q(this,tt)}forEach(e){for(const[t,n]of this)e(t,n,this)}fuzzyGet(e,t){return nt(this._tree,e,t)}get(e){const t=Z(this._tree,e);return t!==void 0?t.get(y):void 0}has(e){const t=Z(this._tree,e);return t!==void 0&&t.has(y)}keys(){return new q(this,we)}set(e,t){if(typeof e!="string")throw new Error("key must be a string");return this._size=void 0,G(this._tree,e).set(y,t),this}get size(){if(this._size)return this._size;this._size=0;const e=this.entries();for(;!e.next().done;)this._size+=1;return this._size}update(e,t){if(typeof e!="string")throw new Error("key must be a string");this._size=void 0;const n=G(this._tree,e);return n.set(y,t(n.get(y))),this}fetch(e,t){if(typeof e!="string")throw new Error("key must be a string");this._size=void 0;const n=G(this._tree,e);let s=n.get(y);return s===void 0&&n.set(y,s=t()),s}values(){return new q(this,ye)}[Symbol.iterator](){return this.entries()}static from(e){const t=new M;for(const[n,s]of e)t.set(n,s);return t}static fromObject(e){return M.from(Object.entries(e))}}const Q=(o,e,t=[])=>{if(e.length===0||o==null)return[o,t];for(const n of o.keys())if(n!==y&&e.startsWith(n))return t.push([o,n]),Q(o.get(n),e.slice(n.length),t);return t.push([o,e]),Q(void 0,"",t)},Z=(o,e)=>{if(e.length===0||o==null)return o;for(const t of o.keys())if(t!==y&&e.startsWith(t))return Z(o.get(t),e.slice(t.length))},G=(o,e)=>{const t=e.length;e:for(let n=0;o&&n<t;){for(const i of o.keys())if(i!==y&&e[n]===i[0]){const r=Math.min(t-n,i.length);let c=1;for(;c<r&&e[n+c]===i[c];)++c;const l=o.get(i);if(c===i.length)o=l;else{const d=new Map;d.set(i.slice(c),l),o.set(e.slice(n,n+c),d),o.delete(i),o=d}n+=c;continue e}const s=new Map;return o.set(e.slice(n),s),s}return o},st=(o,e)=>{const[t,n]=Q(o,e);if(t!==void 0){if(t.delete(y),t.size===0)be(n);else if(t.size===1){const[s,i]=t.entries().next().value;Se(n,s,i)}}},be=o=>{if(o.length===0)return;const[e,t]=se(o);if(e.delete(t),e.size===0)be(o.slice(0,-1));else if(e.size===1){const[n,s]=e.entries().next().value;n!==y&&Se(o.slice(0,-1),n,s)}},Se=(o,e,t)=>{if(o.length===0)return;const[n,s]=se(o);n.set(s+e,t),n.delete(s)},se=o=>o[o.length-1],oe="or",ke="and",ot="and_not";class A{constructor(e){if((e==null?void 0:e.fields)==null)throw new Error('MiniSearch: option "fields" must be provided');const t=e.autoVacuum==null||e.autoVacuum===!0?X:e.autoVacuum;this._options={...K,...e,autoVacuum:t,searchOptions:{...ce,...e.searchOptions||{}},autoSuggestOptions:{...dt,...e.autoSuggestOptions||{}}},this._index=new M,this._documentCount=0,this._documentIds=new Map,this._idToShortId=new Map,this._fieldIds={},this._fieldLength=new Map,this._avgFieldLength=[],this._nextId=0,this._storedFields=new Map,this._dirtCount=0,this._currentVacuum=null,this._enqueuedVacuum=null,this._enqueuedVacuumConditions=te,this.addFields(this._options.fields)}add(e){const{extractField:t,tokenize:n,processTerm:s,fields:i,idField:r}=this._options,c=t(e,r);if(c==null)throw new Error(`MiniSearch: document does not have ID field "${r}"`);if(this._idToShortId.has(c))throw new Error(`MiniSearch: duplicate ID ${c}`);const l=this.addDocumentId(c);this.saveStoredFields(l,e);for(const d of i){const u=t(e,d);if(u==null)continue;const a=n(u.toString(),d),f=this._fieldIds[d],m=new Set(a).size;this.addFieldLength(l,f,this._documentCount-1,m);for(const p of a){const h=s(p,d);if(Array.isArray(h))for(const _ of h)this.addTerm(f,l,_);else h&&this.addTerm(f,l,h)}}}addAll(e){for(const t of e)this.add(t)}addAllAsync(e,t={}){const{chunkSize:n=10}=t,s={chunk:[],promise:Promise.resolve()},{chunk:i,promise:r}=e.reduce(({chunk:c,promise:l},d,u)=>(c.push(d),(u+1)%n===0?{chunk:[],promise:l.then(()=>new Promise(a=>setTimeout(a,0))).then(()=>this.addAll(c))}:{chunk:c,promise:l}),s);return r.then(()=>this.addAll(i))}remove(e){const{tokenize:t,processTerm:n,extractField:s,fields:i,idField:r}=this._options,c=s(e,r);if(c==null)throw new Error(`MiniSearch: document does not have ID field "${r}"`);const l=this._idToShortId.get(c);if(l==null)throw new Error(`MiniSearch: cannot remove document with ID ${c}: it is not in the index`);for(const d of i){const u=s(e,d);if(u==null)continue;const a=t(u.toString(),d),f=this._fieldIds[d],m=new Set(a).size;this.removeFieldLength(l,f,this._documentCount,m);for(const p of a){const h=n(p,d);if(Array.isArray(h))for(const _ of h)this.removeTerm(f,l,_);else h&&this.removeTerm(f,l,h)}}this._storedFields.delete(l),this._documentIds.delete(l),this._idToShortId.delete(c),this._fieldLength.delete(l),this._documentCount-=1}removeAll(e){if(e)for(const t of e)this.remove(t);else{if(arguments.length>0)throw new Error("Expected documents to be present. Omit the argument to remove all documents.");this._index=new M,this._documentCount=0,this._documentIds=new Map,this._idToShortId=new Map,this._fieldLength=new Map,this._avgFieldLength=[],this._storedFields=new Map,this._nextId=0}}discard(e){const t=this._idToShortId.get(e);if(t==null)throw new Error(`MiniSearch: cannot discard document with ID ${e}: it is not in the index`);this._idToShortId.delete(e),this._documentIds.delete(t),this._storedFields.delete(t),(this._fieldLength.get(t)||[]).forEach((n,s)=>{this.removeFieldLength(t,s,this._documentCount,n)}),this._fieldLength.delete(t),this._documentCount-=1,this._dirtCount+=1,this.maybeAutoVacuum()}maybeAutoVacuum(){if(this._options.autoVacuum===!1)return;const{minDirtFactor:e,minDirtCount:t,batchSize:n,batchWait:s}=this._options.autoVacuum;this.conditionalVacuum({batchSize:n,batchWait:s},{minDirtCount:t,minDirtFactor:e})}discardAll(e){const t=this._options.autoVacuum;try{this._options.autoVacuum=!1;for(const n of e)this.discard(n)}finally{this._options.autoVacuum=t}this.maybeAutoVacuum()}replace(e){const{idField:t,extractField:n}=this._options,s=n(e,t);this.discard(s),this.add(e)}vacuum(e={}){return this.conditionalVacuum(e)}conditionalVacuum(e,t){return this._currentVacuum?(this._enqueuedVacuumConditions=this._enqueuedVacuumConditions&&t,this._enqueuedVacuum!=null?this._enqueuedVacuum:(this._enqueuedVacuum=this._currentVacuum.then(()=>{const n=this._enqueuedVacuumConditions;return this._enqueuedVacuumConditions=te,this.performVacuuming(e,n)}),this._enqueuedVacuum)):this.vacuumConditionsMet(t)===!1?Promise.resolve():(this._currentVacuum=this.performVacuuming(e),this._currentVacuum)}async performVacuuming(e,t){const n=this._dirtCount;if(this.vacuumConditionsMet(t)){const s=e.batchSize||ee.batchSize,i=e.batchWait||ee.batchWait;let r=1;for(const[c,l]of this._index){for(const[d,u]of l)for(const[a]of u)this._documentIds.has(a)||(u.size<=1?l.delete(d):u.delete(a));this._index.get(c).size===0&&this._index.delete(c),r%s===0&&await new Promise(d=>setTimeout(d,i)),r+=1}this._dirtCount-=n}await null,this._currentVacuum=this._enqueuedVacuum,this._enqueuedVacuum=null}vacuumConditionsMet(e){if(e==null)return!0;let{minDirtCount:t,minDirtFactor:n}=e;return t=t||X.minDirtCount,n=n||X.minDirtFactor,this.dirtCount>=t&&this.dirtFactor>=n}get isVacuuming(){return this._currentVacuum!=null}get dirtCount(){return this._dirtCount}get dirtFactor(){return this._dirtCount/(1+this._documentCount+this._dirtCount)}has(e){return this._idToShortId.has(e)}getStoredFields(e){const t=this._idToShortId.get(e);if(t!=null)return this._storedFields.get(t)}search(e,t={}){const{searchOptions:n}=this._options,s={...n,...t},i=this.executeQuery(e,t),r=[];for(const[c,{score:l,terms:d,match:u}]of i){const a=d.length||1,f={id:this._documentIds.get(c),score:l*a,terms:Object.keys(u),queryTerms:d,match:u};Object.assign(f,this._storedFields.get(c)),(s.filter==null||s.filter(f))&&r.push(f)}return e===A.wildcard&&s.boostDocument==null||r.sort(de),r}autoSuggest(e,t={}){t={...this._options.autoSuggestOptions,...t};const n=new Map;for(const{score:i,terms:r}of this.search(e,t)){const c=r.join(" "),l=n.get(c);l!=null?(l.score+=i,l.count+=1):n.set(c,{score:i,terms:r,count:1})}const s=[];for(const[i,{score:r,terms:c,count:l}]of n)s.push({suggestion:i,terms:c,score:r/l});return s.sort(de),s}get documentCount(){return this._documentCount}get termCount(){return this._index.size}static loadJSON(e,t){if(t==null)throw new Error("MiniSearch: loadJSON should be given the same options used when serializing the index");return this.loadJS(JSON.parse(e),t)}static async loadJSONAsync(e,t){if(t==null)throw new Error("MiniSearch: loadJSON should be given the same options used when serializing the index");return this.loadJSAsync(JSON.parse(e),t)}static getDefault(e){if(K.hasOwnProperty(e))return H(K,e);throw new Error(`MiniSearch: unknown option "${e}"`)}static loadJS(e,t){const{index:n,documentIds:s,fieldLength:i,storedFields:r,serializationVersion:c}=e,l=this.instantiateMiniSearch(e,t);l._documentIds=U(s),l._fieldLength=U(i),l._storedFields=U(r);for(const[d,u]of l._documentIds)l._idToShortId.set(u,d);for(const[d,u]of n){const a=new Map;for(const f of Object.keys(u)){let m=u[f];c===1&&(m=m.ds),a.set(parseInt(f,10),U(m))}l._index.set(d,a)}return l}static async loadJSAsync(e,t){const{index:n,documentIds:s,fieldLength:i,storedFields:r,serializationVersion:c}=e,l=this.instantiateMiniSearch(e,t);l._documentIds=await J(s),l._fieldLength=await J(i),l._storedFields=await J(r);for(const[u,a]of l._documentIds)l._idToShortId.set(a,u);let d=0;for(const[u,a]of n){const f=new Map;for(const m of Object.keys(a)){let p=a[m];c===1&&(p=p.ds),f.set(parseInt(m,10),await J(p))}++d%1e3===0&&await Ce(0),l._index.set(u,f)}return l}static instantiateMiniSearch(e,t){const{documentCount:n,nextId:s,fieldIds:i,averageFieldLength:r,dirtCount:c,serializationVersion:l}=e;if(l!==1&&l!==2)throw new Error("MiniSearch: cannot deserialize an index created with an incompatible version");const d=new A(t);return d._documentCount=n,d._nextId=s,d._idToShortId=new Map,d._fieldIds=i,d._avgFieldLength=r,d._dirtCount=c||0,d._index=new M,d}executeQuery(e,t={}){if(e===A.wildcard)return this.executeWildcardQuery(t);if(typeof e!="string"){const f={...t,...e,queries:void 0},m=e.queries.map(p=>this.executeQuery(p,f));return this.combineResults(m,f.combineWith)}const{tokenize:n,processTerm:s,searchOptions:i}=this._options,r={tokenize:n,processTerm:s,...i,...t},{tokenize:c,processTerm:l}=r,a=c(e).flatMap(f=>l(f)).filter(f=>!!f).map(lt(r)).map(f=>this.executeQuerySpec(f,r));return this.combineResults(a,r.combineWith)}executeQuerySpec(e,t){const n={...this._options.searchOptions,...t},s=(n.fields||this._options.fields).reduce((h,_)=>({...h,[_]:H(n.boost,_)||1}),{}),{boostDocument:i,weights:r,maxFuzzy:c,bm25:l}=n,{fuzzy:d,prefix:u}={...ce.weights,...r},a=this._index.get(e.term),f=this.termResults(e.term,e.term,1,e.termBoost,a,s,i,l);let m,p;if(e.prefix&&(m=this._index.atPrefix(e.term)),e.fuzzy){const h=e.fuzzy===!0?.2:e.fuzzy,_=h<1?Math.min(c,Math.round(e.term.length*h)):h;_&&(p=this._index.fuzzyGet(e.term,_))}if(m)for(const[h,_]of m){const k=h.length-e.term.length;if(!k)continue;p==null||p.delete(h);const b=u*h.length/(h.length+.3*k);this.termResults(e.term,h,b,e.termBoost,_,s,i,l,f)}if(p)for(const h of p.keys()){const[_,k]=p.get(h);if(!k)continue;const b=d*h.length/(h.length+k);this.termResults(e.term,h,b,e.termBoost,_,s,i,l,f)}return f}executeWildcardQuery(e){const t=new Map,n={...this._options.searchOptions,...e};for(const[s,i]of this._documentIds){const r=n.boostDocument?n.boostDocument(i,"",this._storedFields.get(s)):1;t.set(s,{score:r,terms:[],match:{}})}return t}combineResults(e,t=oe){if(e.length===0)return new Map;const n=t.toLowerCase(),s=it[n];if(!s)throw new Error(`Invalid combination operator: ${t}`);return e.reduce(s)||new Map}toJSON(){const e=[];for(const[t,n]of this._index){const s={};for(const[i,r]of n)s[i]=Object.fromEntries(r);e.push([t,s])}return{documentCount:this._documentCount,nextId:this._nextId,documentIds:Object.fromEntries(this._documentIds),fieldIds:this._fieldIds,fieldLength:Object.fromEntries(this._fieldLength),averageFieldLength:this._avgFieldLength,storedFields:Object.fromEntries(this._storedFields),dirtCount:this._dirtCount,index:e,serializationVersion:2}}termResults(e,t,n,s,i,r,c,l,d=new Map){if(i==null)return d;for(const u of Object.keys(r)){const a=r[u],f=this._fieldIds[u],m=i.get(f);if(m==null)continue;let p=m.size;const h=this._avgFieldLength[f];for(const _ of m.keys()){if(!this._documentIds.has(_)){this.removeTerm(f,_,t),p-=1;continue}const k=c?c(this._documentIds.get(_),t,this._storedFields.get(_)):1;if(!k)continue;const b=m.get(_),S=this._fieldLength.get(_)[f],$=ct(b,p,this._documentCount,S,h,l),I=n*s*a*k*$,C=d.get(_);if(C){C.score+=I,ut(C.terms,e);const R=H(C.match,t);R?R.push(u):C.match[t]=[u]}else d.set(_,{score:I,terms:[e],match:{[t]:[u]}})}}return d}addTerm(e,t,n){const s=this._index.fetch(n,ue);let i=s.get(e);if(i==null)i=new Map,i.set(t,1),s.set(e,i);else{const r=i.get(t);i.set(t,(r||0)+1)}}removeTerm(e,t,n){if(!this._index.has(n)){this.warnDocumentChanged(t,e,n);return}const s=this._index.fetch(n,ue),i=s.get(e);i==null||i.get(t)==null?this.warnDocumentChanged(t,e,n):i.get(t)<=1?i.size<=1?s.delete(e):i.delete(t):i.set(t,i.get(t)-1),this._index.get(n).size===0&&this._index.delete(n)}warnDocumentChanged(e,t,n){for(const s of Object.keys(this._fieldIds))if(this._fieldIds[s]===t){this._options.logger("warn",`MiniSearch: document with ID ${this._documentIds.get(e)} has changed before removal: term "${n}" was not present in field "${s}". Removing a document after it has changed can corrupt the index!`,"version_conflict");return}}addDocumentId(e){const t=this._nextId;return this._idToShortId.set(e,t),this._documentIds.set(t,e),this._documentCount+=1,this._nextId+=1,t}addFields(e){for(let t=0;t<e.length;t++)this._fieldIds[e[t]]=t}addFieldLength(e,t,n,s){let i=this._fieldLength.get(e);i==null&&this._fieldLength.set(e,i=[]),i[t]=s;const c=(this._avgFieldLength[t]||0)*n+s;this._avgFieldLength[t]=c/(n+1)}removeFieldLength(e,t,n,s){if(n===1){this._avgFieldLength[t]=0;return}const i=this._avgFieldLength[t]*n-s;this._avgFieldLength[t]=i/(n-1)}saveStoredFields(e,t){const{storeFields:n,extractField:s}=this._options;if(n==null||n.length===0)return;let i=this._storedFields.get(e);i==null&&this._storedFields.set(e,i={});for(const r of n){const c=s(t,r);c!==void 0&&(i[r]=c)}}}A.wildcard=Symbol("*");const H=(o,e)=>Object.prototype.hasOwnProperty.call(o,e)?o[e]:void 0,it={[oe]:(o,e)=>{for(const t of e.keys()){const n=o.get(t);if(n==null)o.set(t,e.get(t));else{const{score:s,terms:i,match:r}=e.get(t);n.score=n.score+s,n.match=Object.assign(n.match,r),le(n.terms,i)}}return o},[ke]:(o,e)=>{const t=new Map;for(const n of e.keys()){const s=o.get(n);if(s==null)continue;const{score:i,terms:r,match:c}=e.get(n);le(s.terms,r),t.set(n,{score:s.score+i,terms:s.terms,match:Object.assign(s.match,c)})}return t},[ot]:(o,e)=>{for(const t of e.keys())o.delete(t);return o}},rt={k:1.2,b:.7,d:.5},ct=(o,e,t,n,s,i)=>{const{k:r,b:c,d:l}=i;return Math.log(1+(t-e+.5)/(e+.5))*(l+o*(r+1)/(o+r*(1-c+c*n/s)))},lt=o=>(e,t,n)=>{const s=typeof o.fuzzy=="function"?o.fuzzy(e,t,n):o.fuzzy||!1,i=typeof o.prefix=="function"?o.prefix(e,t,n):o.prefix===!0,r=typeof o.boostTerm=="function"?o.boostTerm(e,t,n):1;return{term:e,fuzzy:s,prefix:i,termBoost:r}},K={idField:"id",extractField:(o,e)=>o[e],tokenize:o=>o.split(at),processTerm:o=>o.toLowerCase(),fields:void 0,searchOptions:void 0,storeFields:[],logger:(o,e)=>{typeof(console==null?void 0:console[o])=="function"&&console[o](e)},autoVacuum:!0},ce={combineWith:oe,prefix:!1,fuzzy:!1,maxFuzzy:6,boost:{},weights:{fuzzy:.45,prefix:.375},bm25:rt},dt={combineWith:ke,prefix:(o,e,t)=>e===t.length-1},ee={batchSize:1e3,batchWait:10},te={minDirtFactor:.1,minDirtCount:20},X={...ee,...te},ut=(o,e)=>{o.includes(e)||o.push(e)},le=(o,e)=>{for(const t of e)o.includes(t)||o.push(t)},de=({score:o},{score:e})=>e-o,ue=()=>new Map,U=o=>{const e=new Map;for(const t of Object.keys(o))e.set(parseInt(t,10),o[t]);return e},J=async o=>{const e=new Map;let t=0;for(const n of Object.keys(o))e.set(parseInt(n,10),o[n]),++t%1e3===0&&await Ce(0);return e},Ce=o=>new Promise(e=>setTimeout(e,o)),at=/[\n\r\p{Z}\p{P}]+/u,ht={class:"relative",style:{height:"100vh"}},ft={class:"flex h-full"},mt={class:"h-full border-r border-r-gray-800 of-auto","h-full":"",style:{width:"22rem","min-width":"0",flex:"0 0 auto"}},pt={flex:"~ col gap2",border:"b base",class:"border-b-gray-800 p3 flex-1"},_t=["onClick"],gt={style:{width:"6rem"},class:"text-left"},vt=["onClick"],wt={key:0,class:"h-full relative w-full of-auto"},yt="nuxt-graphql-middleware",bt=L({__name:"index",setup(o){const e=new A({fields:["id","source","name","filePath","identifier"],storeFields:["id","source","name","identifier","filePath"],searchOptions:{fuzzy:.7}}),t=W(""),n=W([]),s=W(""),i=W(""),r=O(()=>{if(t.value)return n.value.find(u=>u.id===t.value)});async function c(u){e.removeAll(),n.value=u,e.addAll(u)}ve(async u=>{const a=u.devtools.extendClientRpc(yt,{showNotification(){},documentsUpdated(p){c(p)}}),f=await a.getDocuments();c(f);const m=await a.getModuleOptions();i.value=m.serverApiPrefix});function l(u){const a=document.createElement("textarea");a.value=u.source,a.style.top="0",a.style.left="0",a.style.position="fixed",document.body.appendChild(a),a.focus(),a.select();try{document.execCommand("copy")}catch{}document.body.removeChild(a)}const d=O(()=>s.value?e.search(s.value):n.value);return(u,a)=>{const f=Ee,m=ge,p=et;return g(),w("div",ht,[v("div",ft,[v("div",mt,[v("div",pt,[N(f,{modelValue:x(s),"onUpdate:modelValue":a[0]||(a[0]=h=>me(s)?s.value=h:null),placeholder:"Search documents...",icon:"carbon-search",class:"w-full"},null,8,["modelValue"])]),(g(!0),w(B,null,ne(x(d),h=>(g(),w("div",{key:h.id,class:"relative group"},[v("button",{class:"text-secondary hover:n-bg-hover flex select-none truncate px2 py2 font-mono text-sm w-full",onClick:_=>t.value=h.id},[v("div",gt,[h.identifier==="query"?(g(),P(m,{key:0,green:"",text:"Query"})):h.identifier==="mutation"?(g(),P(m,{key:1,orange:"",text:"Mutation"})):F("",!0)]),v("div",null,V(h.name),1)],8,_t),v("button",{class:"absolute right-0 top-0 text-sm h-full flex items-center opacity-0 group-hover:opacity-100 pr2",onClick:_=>l(h)},a[1]||(a[1]=[v("span",null,"Copy",-1)]),8,vt)]))),128))]),a[2]||(a[2]=v("div",{class:"splitpanes__splitter"},null,-1)),x(r)?(g(),w("div",wt,[N(p,fe(x(r),{"server-api-prefix":x(i)}),null,16,["server-api-prefix"])])):F("",!0)])])}}});export{bt as default};
@@ -1,11 +1,11 @@
1
- <!DOCTYPE html><html data-capo=""><head><meta charset="utf-8">
1
+ <!DOCTYPE html><html><head><meta charset="utf-8">
2
2
  <meta name="viewport" content="width=device-width, initial-scale=1">
3
- <link rel="stylesheet" href="/__nuxt-graphql-middleware/_nuxt/entry.AjgXSF89.css" crossorigin>
4
- <link rel="modulepreload" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/BS583yk8.js">
5
- <link rel="prefetch" as="style" crossorigin href="/__nuxt-graphql-middleware/_nuxt/error-404.BJkSn6RI.css">
6
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/DpxjPVZy.js">
7
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/exxdaCPN.js">
8
- <link rel="prefetch" as="style" crossorigin href="/__nuxt-graphql-middleware/_nuxt/error-500.TOCKLquH.css">
9
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/GOrnHr4p.js">
10
- <script type="module" src="/__nuxt-graphql-middleware/_nuxt/BS583yk8.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1741248348633,false]</script>
11
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-graphql-middleware",buildId:"f823ebfd-daab-468f-8f6f-07a236da64bd",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
3
+ <link rel="stylesheet" href="/__nuxt-graphql-middleware/_nuxt/entry.Cn9qfNGa.css" crossorigin>
4
+ <link rel="modulepreload" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/D5hBL5aZ.js">
5
+ <link rel="prefetch" as="style" crossorigin href="/__nuxt-graphql-middleware/_nuxt/error-404.ehK72JOs.css">
6
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/BM34SYth.js">
7
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/FTbv7CO6.js">
8
+ <link rel="prefetch" as="style" crossorigin href="/__nuxt-graphql-middleware/_nuxt/error-500._g0akJim.css">
9
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/CROlboVl.js">
10
+ <script type="module" src="/__nuxt-graphql-middleware/_nuxt/D5hBL5aZ.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1745386817962,false]</script>
11
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-graphql-middleware",buildId:"de61b0f7-ec5c-4f2f-addb-b5017c30afb1",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
@@ -0,0 +1,6 @@
1
+ import { ContextType, GraphqlClientOptions } from '../dist/runtime/types.js';
2
+ export { GraphqlClientOptions } from '../dist/runtime/types.js';
3
+
4
+ declare function defineGraphqlClientOptions<T extends ContextType>(options: GraphqlClientOptions<T>): GraphqlClientOptions<T>;
5
+
6
+ export { defineGraphqlClientOptions };
@@ -0,0 +1,5 @@
1
+ function defineGraphqlClientOptions(options) {
2
+ return options;
3
+ }
4
+
5
+ export { defineGraphqlClientOptions };
package/dist/module.d.mts CHANGED
@@ -1,358 +1,92 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- import { Types } from '@graphql-codegen/plugin-helpers';
3
- import { SchemaASTConfig } from '@graphql-codegen/schema-ast';
4
- import { GeneratorOptions } from 'graphql-typescript-deluxe';
5
- import { H3Event } from 'h3';
6
- import { FetchOptions, FetchResponse, FetchError } from 'ofetch';
7
- import { ContextType, GraphqlServerResponse } from '#graphql-middleware/types';
8
- import { GraphqlMiddlewareResponseUnion } from '#nuxt-graphql-middleware/generated-types';
2
+ import { M as ModuleContext, a as ModuleOptions } from './shared/nuxt-graphql-middleware.xfMm4rGk.mjs';
3
+ import { OperationResponseError } from '../dist/runtime/types.js';
4
+ import { HookResult } from 'nuxt/schema';
5
+ import { GeneratorOutput } from 'graphql-typescript-deluxe';
6
+ import 'graphql';
7
+ import '@nuxt/kit';
8
+ import 'h3';
9
+ import '@graphql-codegen/plugin-helpers';
10
+ import '@graphql-codegen/schema-ast';
9
11
 
10
- type GraphqlMiddlewareRequestContext<C extends ContextType = ContextType> = {
11
- client?: Partial<C>;
12
- };
13
- type GraphqlMiddlewareGraphqlEndpointMethod<C extends ContextType> = (event?: H3Event, operation?: string, operationName?: string, context?: GraphqlMiddlewareRequestContext<C>) => string | Promise<string> | undefined;
14
- type GraphqlMiddlewareServerFetchOptionsMethod<C extends ContextType> = (event?: H3Event, operation?: string, operationName?: string, context?: GraphqlMiddlewareRequestContext<C>) => FetchOptions | Promise<FetchOptions>;
15
- type GraphqlMiddlewareOnServerResponseMethod<ServerReponse, T, C extends ContextType> = (event: H3Event, response: FetchResponse<ServerReponse>, operation?: string, operationName?: string, context?: GraphqlMiddlewareRequestContext<C>) => T | Promise<T>;
16
- type GraphqlMiddlewareOnServerErrorMethod<C extends ContextType> = (event: H3Event, error: FetchError, operation?: string, operationName?: string, context?: GraphqlMiddlewareRequestContext<C>) => any | Promise<any>;
17
- type GraphqlMiddlewareDoRequestMethodContext<C extends ContextType> = {
18
- /**
19
- * The incoming request event from H3.
20
- */
21
- event: H3Event;
22
- /**
23
- * The type of operation.
24
- */
25
- operation: 'query' | 'mutation';
26
- /**
27
- * The name of the operation.
28
- */
29
- operationName: string;
30
- /**
31
- * The operation document (the raw GraphQL query/mutation as a string).
32
- */
33
- operationDocument: string;
34
- /**
35
- * Variables for the operation.
36
- */
37
- variables: Record<string, any>;
38
- /**
39
- * For file uploads (which are done using FormData), this contains the full
40
- * form data with these keys:
41
- *
42
- * - operations: string
43
- * A JSON string of an object with "query", "variables" and "operationName" properties.
44
- * Example:
45
- * operations='{ "query": "mutation ($id: String!, $file: Upload!) { uploadFile(id: $id, file: $file) { id filename } }", "variables": { "file": null, "id": "1" } }'
46
- * - map: string
47
- * A JSON string of an object whose keys are strings starting at '0' and the values being an array with a single string:
48
- * Example:
49
- * map='{ "0": ["variables.file"] }'
50
- * - [number]
51
- * For every file there is a FormData entry with a name that matches the key in `map`.
52
- * Example:
53
- * 0=[Binary File]
54
- */
55
- formData?: FormData;
56
- context: GraphqlMiddlewareRequestContext<C>;
57
- };
58
- type GraphqlMiddlewareDoRequestMethod<T, C extends ContextType> = (context: GraphqlMiddlewareDoRequestMethodContext<C>) => Promise<T>;
59
- /**
60
- * Configuration options during runtime.
61
- */
62
- type GraphqlMiddlewareServerOptions<Additions extends object = object, C extends ContextType = ContextType, CustomResponse = GraphqlServerResponse<GraphqlMiddlewareResponseUnion> & Additions> = {
63
- /**
64
- * Custom callback to return the GraphQL endpoint per request.
65
- *
66
- * The method is only called if no `doGraphqlRequest` method is implemented.
67
- *
68
- * @default undefined
69
- *
70
- * @example
71
- * ```ts
72
- * function graphqlEndpoint(event, operation, operationName) {
73
- * const language = getLanguageFromRequest(event)
74
- * return `https://api.example.com/${language}/graphql`
75
- * }
76
- * ```
77
- */
78
- graphqlEndpoint?: GraphqlMiddlewareGraphqlEndpointMethod<C>;
79
- /**
80
- * Provide the options for the ofetch request to the GraphQL server.
81
- *
82
- * The method is only called if no `doGraphqlRequest` method is implemented.
83
- *
84
- * @default undefined
85
- *
86
- * @example
87
- * ```ts
88
- * import { getHeader } from 'h3'
89
- *
90
- * // Pass the cookie from the client request to the GraphQL request.
91
- * function serverFetchOptions(event, operation, operationName) {
92
- * return {
93
- * headers: {
94
- * Cookie: getHeader(event, 'cookie')
95
- * }
96
- * }
97
- * }
98
- * ```
99
- */
100
- serverFetchOptions?: GraphqlMiddlewareServerFetchOptionsMethod<C>;
101
- /**
102
- * Handle the response from the GraphQL server.
103
- *
104
- * The method is only called if no `doGraphqlRequest` method is implemented.
105
- *
106
- * You can alter the response, add additional properties to the data, get
107
- * and set headers, etc.
108
- *
109
- * ```ts
110
- * import type { H3Event } from 'h3'
111
- * import type { FetchResponse } from 'ofetch'
112
- *
113
- * function onServerResponse(event: H3Event, graphqlResponse: FetchResponse) {
114
- * // Set a static header.
115
- * event.node.res.setHeader('x-nuxt-custom-header', 'A custom header value')
116
- *
117
- * // Pass the set-cookie header from the GraphQL response to the client.
118
- * const setCookie = graphqlResponse.headers.get('set-cookie')
119
- * if (setCookie) {
120
- * event.node.res.setHeader('set-cookie', setCookie)
121
- * }
122
- *
123
- * // Add additional properties to the response.
124
- * graphqlResponse._data.__customProperty = ['My', 'values']
125
- *
126
- * // Return the GraphQL response.
127
- * return graphqlResponse._data
128
- * }
129
- * ```
130
- */
131
- onServerResponse?: GraphqlMiddlewareOnServerResponseMethod<GraphqlServerResponse<GraphqlMiddlewareResponseUnion>, CustomResponse, C>;
132
- /**
133
- * Handle a fetch error from the GraphQL request.
134
- *
135
- * The method is only called if no `doGraphqlRequest` method is implemented.
136
- *
137
- * Note that errors are only thrown for responses that are not status
138
- * 200-299. See https://github.com/unjs/ofetch#%EF%B8%8F-handling-errors for
139
- * more information.
140
- *
141
- * ```ts
142
- * import { createError } from 'h3'
143
- * import type { H3Event } from 'h3'
144
- * import type { FetchError } from 'ofetch'
145
- *
146
- * function onServerError(
147
- * event: H3Event,
148
- * error: FetchError,
149
- * operation: string,
150
- * operationName: string,
151
- * ) {
152
- * // Throw a h3 error.
153
- * throw createError({
154
- * statusCode: 500,
155
- * statusMessage: `Couldn't execute GraphQL ${operation} "${operationName}".`,
156
- * data: error.message
157
- * })
158
- * }
159
- * ```
160
- */
161
- onServerError?: GraphqlMiddlewareOnServerErrorMethod<C>;
162
- /**
163
- * Provide a custom fetch method for requests to the GraphQL server.
164
- *
165
- * This can be used if onServerError, onServerResponse, serverFetchOptions
166
- * and graphqlEndpoint are not enough to meet your requirements.
167
- *
168
- * When this method is implemented, all other methods are not called.
169
- *
170
- * The method will be called in the /api/graphql server route and should
171
- * perform the GraphQL request and return the response.
172
- *
173
- * An example use case might be to handle expired tokens.
174
- *
175
- * * ```ts
176
- * async function doGraphqlRequest({
177
- * event,
178
- * operation,
179
- * operationName,
180
- * operationDocument,
181
- * variables,
182
- * }) {
183
- * const result = await $fetch.raw('https://example.com/graphql', {
184
- * method: 'POST'
185
- * body: {
186
- * query: operationDocument,
187
- * variables,
188
- * operationName
189
- * },
190
- * headers: {
191
- * 'custom-header': 'foobar'
192
- * }
193
- * })
194
- *
195
- * return result._data
196
- * }
197
- * ```
198
- */
199
- doGraphqlRequest?: GraphqlMiddlewareDoRequestMethod<CustomResponse, C>;
12
+ type BuildHookContext = {
13
+ output: GeneratorOutput;
200
14
  };
201
15
 
202
- interface ModuleOptions {
203
- /**
204
- * File glob patterns for the auto import feature.
205
- *
206
- * If left empty, no documents are auto imported.
207
- *
208
- * @default
209
- * ```json
210
- * ["**\/.{gql,graphql}", "!node_modules"]
211
- * ```
212
- *
213
- * @example
214
- * ```ts
215
- * // Load .graphql files from pages folder and from a node_modules dependency.
216
- * const autoImportPatterns = [
217
- * './pages/**\/*.graphql',
218
- * 'node_modules/my_library/dist/**\/*.graphql'
219
- * ]
220
- * ```
221
- */
222
- autoImportPatterns?: string[];
223
- /**
224
- * Additional raw documents to include.
225
- *
226
- * Useful if for example you need to generate queries during build time.
227
- *
228
- * @default []
229
- *
230
- * @example
231
- * ```ts
232
- * const documents = [`
233
- * query myQuery {
234
- * articles {
235
- * title
236
- * id
237
- * }
238
- * }`,
239
- * ...getGeneratedDocuments()
240
- * ]
241
- * ```
242
- */
243
- documents?: string[];
244
- /**
245
- * Wether the useGraphqlQuery, useGraphqlMutation and useGraphqlState
246
- * composables should be included.
247
- *
248
- * @default ```ts
249
- * true
250
- * ```
251
- */
252
- includeComposables?: boolean;
253
- /**
254
- * Enable support for uploading files via GraphQL.
255
- *
256
- * When enabled, an additional `useGraphqlUploadMutation` composable is
257
- * included, in addition to a new server endpoint that handles multi part
258
- * file uploads for GraphQL mutations.
259
- */
260
- enableFileUploads?: boolean;
261
- /**
262
- * Enable detailled debugging messages.
263
- *
264
- * @default false
265
- */
266
- debug?: boolean;
267
- /**
268
- * The URL of the GraphQL server.
269
- *
270
- * For the runtime execution you can provide a method that determines the endpoint
271
- * during runtime. See the server/graphqlMiddleware.serverOptions.ts documentation
272
- * for more information.
273
- */
274
- graphqlEndpoint: string;
275
- /**
276
- * Download the GraphQL schema and store it on disk.
277
- *
278
- * @default true
279
- */
280
- downloadSchema?: boolean;
281
- /**
282
- * The prefix for the server route.
283
- *
284
- * @default ```ts
285
- * "/api/graphql_middleware"
286
- * ```
287
- */
288
- serverApiPrefix?: string;
289
- /**
290
- * Path to the GraphQL schema file.
291
- *
292
- * If `downloadSchema` is `true`, the downloaded schema is written to this specified path.
293
- * If `downloadSchema` is `false`, this file must be present in order to generate types.
294
- *
295
- * @default './schema.graphql'
296
- */
297
- schemaPath?: string;
298
- /**
299
- * Options for graphql-typescript-deluxe code generator.
300
- */
301
- codegenConfig?: GeneratorOptions;
302
- /**
303
- * Configuration for graphql-codegen when downloading the schema.
304
- */
305
- codegenSchemaConfig?: {
16
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
17
+
18
+ declare module '#app' {
19
+ interface RuntimeNuxtHooks {
306
20
  /**
307
- * Configure how the schema.graphql file should be generated.
21
+ * Emitted when any GraphQL response contains errors.
308
22
  */
309
- schemaAstConfig?: SchemaASTConfig;
23
+ 'nuxt-graphql-middleware:errors': (errors: OperationResponseError) => HookResult;
24
+ }
25
+ }
26
+ declare module 'vite/types/customEvent.d.ts' {
27
+ interface CustomEventMap {
310
28
  /**
311
- * Configure how the schema-ast introspection request should be made.
312
- *
313
- * Usually this is where you can provide a custom authentication header:
314
- *
315
- * ```typescript
316
- * const codegenSchemaConfig = {
317
- * urlSchemaOptions: {
318
- * headers: {
319
- * authentication: 'foobar',
320
- * }
321
- * }
322
- * }
323
- * ```
29
+ * Emitted when GraphQL operations have been updated.
324
30
  */
325
- urlSchemaOptions?: Types.UrlSchemaOptions;
326
- };
327
- /**
328
- * Set to true if you want to output each compiled query and mutation in the
329
- * .nuxt folder.
330
- * Set to a path to output to a custom path.
331
- */
332
- outputDocuments?: boolean | string;
333
- /**
334
- * Enable Nuxt DevTools integration.
335
- */
336
- devtools?: boolean;
337
- /**
338
- * Client caching configuration.
339
- */
340
- clientCache?: {
341
- enabled?: boolean;
342
- maxSize?: number;
343
- };
344
- }
345
- interface ModuleHooks {
31
+ 'nuxt-graphql-middleware:reload': {
32
+ operations: string[];
33
+ };
34
+ }
346
35
  }
347
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
348
-
349
36
  declare module '@nuxt/schema' {
350
37
  interface AppConfig {
351
38
  graphqlMiddleware: {
39
+ /**
40
+ * Whether the client cache is enabled.
41
+ */
352
42
  clientCacheEnabled: boolean;
43
+ /**
44
+ * The max number of items in the cache.
45
+ */
353
46
  clientCacheMaxSize: number;
354
47
  };
355
48
  }
49
+ interface Nuxt {
50
+ /**
51
+ * The nuxt-graphql-middleware module context.
52
+ */
53
+ _nuxt_graphql_middleware?: ModuleContext;
54
+ }
55
+ interface NuxtHooks {
56
+ /**
57
+ * Called once right before the documents are initialised.
58
+ *
59
+ * Use this hook to add any additional documents based on for example the parsed schema.
60
+ *
61
+ * @example
62
+ *
63
+ * ```typescript`
64
+ * export default defineNuxtConfig({
65
+ * hooks: {
66
+ * 'nuxt-graphql-middleware:init': (ctx) => {
67
+ * if (ctx.schemaHasType('Comment')) {
68
+ * ctx.addDocument(
69
+ * 'queryFromHook',
70
+ * `query loadComments { author subject date body }`
71
+ * )
72
+ * }
73
+ * },
74
+ * },
75
+ * })
76
+ * ```
77
+ */
78
+ 'nuxt-graphql-middleware:init': (ctx: ModuleContext) => void | Promise<void>;
79
+ /**
80
+ * Called when building the state and templates.
81
+ *
82
+ * Generally this hook is called from within the builder:watch event, when
83
+ * a GraphQL file change was detected.
84
+ *
85
+ * The received argument is the output from the graphql-typescript-deluxe
86
+ * generator.
87
+ */
88
+ 'nuxt-graphql-middleware:build': (ctx: BuildHookContext) => void | Promise<void>;
89
+ }
356
90
  }
357
91
 
358
- export { type GraphqlMiddlewareServerOptions, type ModuleHooks, type ModuleOptions, _default as default };
92
+ export { ModuleOptions, _default as default };
package/dist/module.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "nuxt-graphql-middleware",
3
3
  "configKey": "graphqlMiddleware",
4
- "version": "5.0.0-alpha.2",
4
+ "version": "5.0.0-alpha.20",
5
5
  "compatibility": {
6
- "nuxt": ">=3.13.0"
6
+ "nuxt": ">=3.15.0"
7
7
  },
8
8
  "builder": {
9
- "@nuxt/module-builder": "0.8.4",
10
- "unbuild": "2.0.0"
9
+ "@nuxt/module-builder": "1.0.1",
10
+ "unbuild": "3.5.0"
11
11
  }
12
12
  }