@zuplo/graphql 5.2152.0 → 5.2154.0
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.
- package/{index.min.cjs → out/cjs/index.js} +1 -1
- package/{index.min.js → out/esm/index.js} +1 -1
- package/package.json +5 -10
- /package/{index.min.cjs.LEGAL.txt → out/cjs/index.js.LEGAL.txt} +0 -0
- /package/{index.min.js.LEGAL.txt → out/esm/index.js.LEGAL.txt} +0 -0
- /package/{types-beta.d.ts → out/types/index.d.ts} +0 -0
|
@@ -178,4 +178,4 @@ In some cases, you need to provide options to alter GraphQL's execution behavior
|
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
`}o(kt,"getIntrospectionQuery");function Ct(e,t){k(e)&&k(e.__schema)||I(!1,`Invalid or incomplete introspection result. Ensure that you are passing "data" property of introspection response and no "errors" was returned alongside: ${m(e)}.`);let n=e.__schema,i=ae(n.types,l=>l.name,l=>N(l));for(let l of[...zt,...nn])i[l.name]&&(i[l.name]=l);let r=n.queryType?T(n.queryType):null,s=n.mutationType?T(n.mutationType):null,a=n.subscriptionType?T(n.subscriptionType):null,c=n.directives?n.directives.map($n):[];return new Ke({description:n.description,query:r,mutation:s,subscription:a,types:Object.values(i),directives:c,assumeValid:t?.assumeValid});function d(l){if(l.kind===L.LIST){let v=l.ofType;if(!v)throw new Error("Decorated type deeper than introspection query.");return new w(d(v))}if(l.kind===L.NON_NULL){let v=l.ofType;if(!v)throw new Error("Decorated type deeper than introspection query.");let se=d(v);return new E(Nt(se))}return f(l)}function f(l){let v=l.name;if(!v)throw new Error(`Unknown type reference: ${m(l)}.`);let se=i[v];if(!se)throw new Error(`Invalid or incomplete schema, unknown type: ${v}. Ensure that a full introspection query is used in order to build a client schema.`);return se}function T(l){return yt(f(l))}function x(l){return Tt(f(l))}function N(l){if(l!=null&&l.name!=null&&l.kind!=null)switch(l.kind){case L.SCALAR:return S(l);case L.OBJECT:return U(l);case L.INTERFACE:return K(l);case L.UNION:return F(l);case L.ENUM:return me(l);case L.INPUT_OBJECT:return re(l)}let v=m(l);throw new Error(`Invalid or incomplete introspection result. Ensure that a full introspection query is used in order to build a client schema: ${v}.`)}function S(l){return new J({name:l.name,description:l.description,specifiedByURL:l.specifiedByURL})}function g(l){if(l.interfaces===null&&l.kind===L.INTERFACE)return[];if(!l.interfaces){let v=m(l);throw new Error(`Introspection result missing interfaces: ${v}.`)}return l.interfaces.map(x)}function U(l){return new M({name:l.name,description:l.description,interfaces:()=>g(l),fields:()=>Z(l)})}function K(l){return new le({name:l.name,description:l.description,interfaces:()=>g(l),fields:()=>Z(l)})}function F(l){if(!l.possibleTypes){let v=m(l);throw new Error(`Introspection result missing possibleTypes: ${v}.`)}return new ve({name:l.name,description:l.description,types:()=>l.possibleTypes.map(T)})}function me(l){if(!l.enumValues){let v=m(l);throw new Error(`Introspection result missing enumValues: ${v}.`)}return new pe({name:l.name,description:l.description,values:ae(l.enumValues,v=>v.name,v=>({description:v.description,deprecationReason:v.deprecationReason}))})}function re(l){if(!l.inputFields){let v=m(l);throw new Error(`Introspection result missing inputFields: ${v}.`)}return new Ie({name:l.name,description:l.description,fields:()=>_e(l.inputFields)})}function Z(l){if(!l.fields)throw new Error(`Introspection result missing fields: ${m(l)}.`);return ae(l.fields,v=>v.name,Ue)}function Ue(l){let v=d(l.type);if(!de(v)){let se=m(v);throw new Error(`Introspection must provide output type for fields, but received: ${se}.`)}if(!l.args){let se=m(l);throw new Error(`Introspection result missing field args: ${se}.`)}return{description:l.description,deprecationReason:l.deprecationReason,type:v,args:_e(l.args)}}function _e(l){return ae(l,v=>v.name,Ze)}function Ze(l){let v=d(l.type);if(!z(v)){let Pn=m(v);throw new Error(`Introspection must provide input type for arguments, but received: ${Pn}.`)}let se=l.defaultValue!=null?ue(ct(l.defaultValue),v):void 0;return{description:l.description,type:v,defaultValue:se,deprecationReason:l.deprecationReason}}function $n(l){if(!l.args){let v=m(l);throw new Error(`Introspection result missing directive args: ${v}.`)}if(!l.locations){let v=m(l);throw new Error(`Introspection result missing directive locations: ${v}.`)}return new ne({name:l.name,description:l.description,isRepeatable:l.isRepeatable,locations:l.locations.slice(),args:_e(l.args)})}}o(Ct,"buildClientSchema");function zi(e,t){return`The query exceeds the maximum complexity of ${e}. Actual complexity is ${t}`}o(zi,"queryComplexityMessage");function Fn(e){let t=new Ee(e.schema),n=[],i=new Fe(e.schema,e.query,t,s=>n.push(s)),r=new on(i,{maximumComplexity:e.maximumComplexity??1/0,estimators:e.estimators,variables:e.variables,operationName:e.operationName,context:e.context});if(he(e.query,Ce(t,r)),n.length)throw n.pop();return r.complexity}o(Fn,"getComplexity");var on=class{static{o(this,"QueryComplexity")}context;complexity;options;OperationDefinition;estimators;includeDirectiveDef;skipDirectiveDef;variableValues;requestContext;constructor(t,n){if(Number(n.maximumComplexity)<=0)throw new Error("Maximum query complexity must be a positive number");this.context=t,this.complexity=0,this.options=n,this.includeDirectiveDef=this.context.getSchema().getDirective("include")||void 0,this.skipDirectiveDef=this.context.getSchema().getDirective("skip")||void 0,this.estimators=n.estimators,this.variableValues={},this.requestContext=n.context,this.OperationDefinition={enter:this.onOperationDefinitionEnter,leave:this.onOperationDefinitionLeave}}onOperationDefinitionEnter(t){if(typeof this.options.operationName=="string"&&this.options.operationName!==t.name?.value)return;let{coerced:n,errors:i}=wt(this.context.getSchema(),t.variableDefinitions?[...t.variableDefinitions]:[],this.options.variables??{});if(i&&i.length){i.forEach(s=>this.context.reportError(s));return}this.variableValues=n||{};let r=this.context.getSchema();switch(t.operation){case"query":{let s=r.getQueryType();if(!s)throw new Error("Schema does not define the required query root type");this.complexity+=this.nodeComplexity(t,s);break}case"mutation":{let s=r.getMutationType();if(!s)throw new Error("Schema does not define the required mutation root type");this.complexity+=this.nodeComplexity(t,s);break}case"subscription":{let s=r.getSubscriptionType();if(!s)throw new Error("Schema does not define the required mutation subscription type");this.complexity+=this.nodeComplexity(t,s);break}default:throw new Error(`Query complexity could not be calculated for operation of type ${t.operation}`)}}onOperationDefinitionLeave(t){if(!(typeof this.options.operationName=="string"&&this.options.operationName!==t.name?.value)&&(this.options.onComplete&&this.options.onComplete(this.complexity),this.complexity>this.options.maximumComplexity))return this.context.reportError(this.createError())}nodeComplexity(t,n){if(t.selectionSet){let i={};(n instanceof M||n instanceof le)&&(i=n.getFields());let r;xe(n)?r=this.context.getSchema().getPossibleTypes(n).map(a=>a.name):r=[n.name];let s=t.selectionSet.selections.reduce((a,c)=>{let d=a,f=!0,T=!1;for(let x of c.directives??[])switch(x.name.value){case"include":{let S=this.includeDirectiveDef&&We(this.includeDirectiveDef,c,this.variableValues||{});typeof S?.if=="boolean"&&(f=S.if);break}case"skip":{let S=this.skipDirectiveDef&&We(this.skipDirectiveDef,c,this.variableValues||{});typeof S?.if=="boolean"&&(T=S.if);break}}if(!f||T)return a;switch(c.kind){case p.FIELD:{let x=i[c.name.value];if(!x)break;let N=te(x.type),S;try{S=Xe(x,c,this.variableValues||{})}catch(F){return this.context.reportError(F),a}let g=0;ce(N)&&(g=this.nodeComplexity(c,N));let U={childComplexity:g,args:S,field:x,node:c,type:n,context:this.requestContext};if(!this.estimators.find(F=>{let me=F(U);return typeof me=="number"&&!isNaN(me)?(d=Ve(me,a,r),!0):!1}))return this.context.reportError(new y(`No complexity could be calculated for field ${n.name}.${x.name}. At least one complexity estimator has to return a complexity score.`)),a;break}case p.FRAGMENT_SPREAD:{let x=this.context.getFragment(c.name.value);if(!x)break;let N=this.context.getSchema().getType(x.typeCondition.name.value);if(!ce(N))break;let S=this.nodeComplexity(x,N);xe(N)?d=Ve(S,a,this.context.getSchema().getPossibleTypes(N).map(g=>g.name)):d=Ve(S,a,[N.name]);break}case p.INLINE_FRAGMENT:{let x=n;if(c.typeCondition&&c.typeCondition.name&&(x=this.context.getSchema().getType(c.typeCondition.name.value)||x,!ce(x)))break;let N=this.nodeComplexity(c,x);xe(x)?d=Ve(N,a,this.context.getSchema().getPossibleTypes(x).map(S=>S.name)):d=Ve(N,a,[x.name]);break}default:{d=Ve(this.nodeComplexity(c,n),a,r);break}}return d},{});return s?Math.max(...Object.values(s),0):NaN}return 0}createError(){return typeof this.options.createError=="function"?this.options.createError(this.options.maximumComplexity,this.complexity):new y(zi(this.options.maximumComplexity,this.complexity))}};function Ve(e,t,n){for(let i of n)Object.prototype.hasOwnProperty.call(t,i)?t[i]+=e:t[i]=e;return t}o(Ve,"addComplexities");function Vn(e){let t=e?.defaultComplexity??1;return n=>t+n.childComplexity}o(Vn,"simpleEstimator");var Un=o((e,t,n={})=>{let{definitions:i}=e,r=Ki(i),s=Hi(i);return Object.entries(s).map(([a,c])=>Ft(c,r,0,t,a,n))},"depthLimit");function Ki(e){return e.reduce((t,n)=>(n.kind===p.FRAGMENT_DEFINITION&&(t[n?.name?.value??""]=n),t),{})}o(Ki,"getFragments");function Hi(e){return e.reduce((t,n)=>{if(n.kind===p.OPERATION_DEFINITION){let i=n?.name?.value??"";t[i]=n}return t},{})}o(Hi,"getQueriesAndMutations");function Ft(e,t,n,i,r,s){if(n>i)throw s?.onLimitReached?.(n,r),new y(`${r||"Your query"} exceeds maximum operation depth of ${i}`,{nodes:[e]});let a=s?.ignore??[/^__/];switch(e.kind){case p.FIELD:return Xi(e,a)||!e.selectionSet?0:1+Math.max(...e.selectionSet.selections.map(c=>Ft(c,t,n+1,i,r,s)));case p.FRAGMENT_SPREAD:return Ft(t[e.name.value],t,n,i,r,s);case p.INLINE_FRAGMENT:case p.FRAGMENT_DEFINITION:case p.OPERATION_DEFINITION:return Math.max(...e.selectionSet.selections.map(c=>Ft(c,t,n,i,r,s)));default:throw new Error("uh oh! depth crawler cannot handle: "+e.kind)}}o(Ft,"determineDepth");var Xi=o((e,t)=>t.find(n=>e.name.value.match(n)!==null)||!1,"isIgnored");var Wi=o(async(e,t)=>{if(!t.complexityLimit)throw new Vt.ConfigurationError("No complexity maximum defined, you need to pass a maxComplexity to the policy");let i=t.endpointUrl;if(!i)throw new Vt.ConfigurationError("No GraphQL endpoint, you need to pass a endpointUrl to the policy");let r=kt(),c=(await(await fetch(i,{method:"POST",body:JSON.stringify({query:r}),headers:{"Content-Type":"application/json"}})).json()).data;if(!c||!c?.__schema)throw new y("GraphQL introspection query failed, enable introspection or pass a schema url in configuration.");let d=Ct(c,{assumeValid:!0}),f=Fn({estimators:[Vn({defaultComplexity:1})],schema:d,query:e,variables:{count:10}});if(t.complexityLimit&&f>t.complexityLimit)throw new y(`Query is too complex (${f}/${t.complexityLimit}), remove some fields and try again`)},"applyComplexityLimitPolicy"),Zi=o(async(e,t)=>{let n=t.depthLimit;if(!n)throw new Vt.ConfigurationError("No maximum depth defined, you need to pass a maxDepth to the policy");return Math.max(...Un(e,n))},"applyDepthLimitPolicy"),Mn=o(async(e,t,n)=>{try{let r=await e.clone().json(),s=pt(r.query);n.useDepthLimit&&await Zi(s,n.useDepthLimit),n.useComplexityLimit&&await Wi(s,n.useComplexityLimit)}catch(i){if(t.log.error(i),i instanceof y)return new Response(JSON.stringify(i.toJSON()),{status:400,headers:{"Content-Type":"application/json"}});throw i}return e},"GraphQLComplexityLimitInboundPolicy");var Gn=require("@zuplo/runtime");function er(e){if(!e)return!1;let t=e.replace(/\s/g,"");return t.includes("__schema")||t.includes("__type")}o(er,"isIntrospectionQuery");var jn=o(async(e,t)=>{let i=await e.clone().json();return er(i.query)?Gn.HttpProblems.forbidden(e,t,{detail:"Introspection queries are not allowed"}):e},"GraphQLDisableIntrospectionInboundPolicy");
|
|
181
|
-
/*! For license information please see index.
|
|
181
|
+
/*! For license information please see index.js.LEGAL.txt */
|
|
@@ -178,4 +178,4 @@ In some cases, you need to provide options to alter GraphQL's execution behavior
|
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
`}o(Rt,"getIntrospectionQuery");function kt(e,t){k(e)&&k(e.__schema)||I(!1,`Invalid or incomplete introspection result. Ensure that you are passing "data" property of introspection response and no "errors" was returned alongside: ${m(e)}.`);let n=e.__schema,i=ae(n.types,l=>l.name,l=>N(l));for(let l of[...Jt,...en])i[l.name]&&(i[l.name]=l);let r=n.queryType?T(n.queryType):null,s=n.mutationType?T(n.mutationType):null,a=n.subscriptionType?T(n.subscriptionType):null,c=n.directives?n.directives.map(Un):[];return new Ke({description:n.description,query:r,mutation:s,subscription:a,types:Object.values(i),directives:c,assumeValid:t?.assumeValid});function d(l){if(l.kind===L.LIST){let v=l.ofType;if(!v)throw new Error("Decorated type deeper than introspection query.");return new w(d(v))}if(l.kind===L.NON_NULL){let v=l.ofType;if(!v)throw new Error("Decorated type deeper than introspection query.");let se=d(v);return new E(xt(se))}return f(l)}function f(l){let v=l.name;if(!v)throw new Error(`Unknown type reference: ${m(l)}.`);let se=i[v];if(!se)throw new Error(`Invalid or incomplete schema, unknown type: ${v}. Ensure that a full introspection query is used in order to build a client schema.`);return se}function T(l){return ht(f(l))}function x(l){return yt(f(l))}function N(l){if(l!=null&&l.name!=null&&l.kind!=null)switch(l.kind){case L.SCALAR:return S(l);case L.OBJECT:return U(l);case L.INTERFACE:return K(l);case L.UNION:return F(l);case L.ENUM:return me(l);case L.INPUT_OBJECT:return re(l)}let v=m(l);throw new Error(`Invalid or incomplete introspection result. Ensure that a full introspection query is used in order to build a client schema: ${v}.`)}function S(l){return new J({name:l.name,description:l.description,specifiedByURL:l.specifiedByURL})}function g(l){if(l.interfaces===null&&l.kind===L.INTERFACE)return[];if(!l.interfaces){let v=m(l);throw new Error(`Introspection result missing interfaces: ${v}.`)}return l.interfaces.map(x)}function U(l){return new M({name:l.name,description:l.description,interfaces:()=>g(l),fields:()=>Z(l)})}function K(l){return new le({name:l.name,description:l.description,interfaces:()=>g(l),fields:()=>Z(l)})}function F(l){if(!l.possibleTypes){let v=m(l);throw new Error(`Introspection result missing possibleTypes: ${v}.`)}return new ve({name:l.name,description:l.description,types:()=>l.possibleTypes.map(T)})}function me(l){if(!l.enumValues){let v=m(l);throw new Error(`Introspection result missing enumValues: ${v}.`)}return new pe({name:l.name,description:l.description,values:ae(l.enumValues,v=>v.name,v=>({description:v.description,deprecationReason:v.deprecationReason}))})}function re(l){if(!l.inputFields){let v=m(l);throw new Error(`Introspection result missing inputFields: ${v}.`)}return new Ie({name:l.name,description:l.description,fields:()=>_e(l.inputFields)})}function Z(l){if(!l.fields)throw new Error(`Introspection result missing fields: ${m(l)}.`);return ae(l.fields,v=>v.name,Ue)}function Ue(l){let v=d(l.type);if(!de(v)){let se=m(v);throw new Error(`Introspection must provide output type for fields, but received: ${se}.`)}if(!l.args){let se=m(l);throw new Error(`Introspection result missing field args: ${se}.`)}return{description:l.description,deprecationReason:l.deprecationReason,type:v,args:_e(l.args)}}function _e(l){return ae(l,v=>v.name,Ze)}function Ze(l){let v=d(l.type);if(!z(v)){let Mn=m(v);throw new Error(`Introspection must provide input type for arguments, but received: ${Mn}.`)}let se=l.defaultValue!=null?ue(pt(l.defaultValue),v):void 0;return{description:l.description,type:v,defaultValue:se,deprecationReason:l.deprecationReason}}function Un(l){if(!l.args){let v=m(l);throw new Error(`Introspection result missing directive args: ${v}.`)}if(!l.locations){let v=m(l);throw new Error(`Introspection result missing directive locations: ${v}.`)}return new ne({name:l.name,description:l.description,isRepeatable:l.isRepeatable,locations:l.locations.slice(),args:_e(l.args)})}}o(kt,"buildClientSchema");function Gi(e,t){return`The query exceeds the maximum complexity of ${e}. Actual complexity is ${t}`}o(Gi,"queryComplexityMessage");function Cn(e){let t=new Ee(e.schema),n=[],i=new Fe(e.schema,e.query,t,s=>n.push(s)),r=new rn(i,{maximumComplexity:e.maximumComplexity??1/0,estimators:e.estimators,variables:e.variables,operationName:e.operationName,context:e.context});if(he(e.query,Ce(t,r)),n.length)throw n.pop();return r.complexity}o(Cn,"getComplexity");var rn=class{static{o(this,"QueryComplexity")}context;complexity;options;OperationDefinition;estimators;includeDirectiveDef;skipDirectiveDef;variableValues;requestContext;constructor(t,n){if(Number(n.maximumComplexity)<=0)throw new Error("Maximum query complexity must be a positive number");this.context=t,this.complexity=0,this.options=n,this.includeDirectiveDef=this.context.getSchema().getDirective("include")||void 0,this.skipDirectiveDef=this.context.getSchema().getDirective("skip")||void 0,this.estimators=n.estimators,this.variableValues={},this.requestContext=n.context,this.OperationDefinition={enter:this.onOperationDefinitionEnter,leave:this.onOperationDefinitionLeave}}onOperationDefinitionEnter(t){if(typeof this.options.operationName=="string"&&this.options.operationName!==t.name?.value)return;let{coerced:n,errors:i}=Dt(this.context.getSchema(),t.variableDefinitions?[...t.variableDefinitions]:[],this.options.variables??{});if(i&&i.length){i.forEach(s=>this.context.reportError(s));return}this.variableValues=n||{};let r=this.context.getSchema();switch(t.operation){case"query":{let s=r.getQueryType();if(!s)throw new Error("Schema does not define the required query root type");this.complexity+=this.nodeComplexity(t,s);break}case"mutation":{let s=r.getMutationType();if(!s)throw new Error("Schema does not define the required mutation root type");this.complexity+=this.nodeComplexity(t,s);break}case"subscription":{let s=r.getSubscriptionType();if(!s)throw new Error("Schema does not define the required mutation subscription type");this.complexity+=this.nodeComplexity(t,s);break}default:throw new Error(`Query complexity could not be calculated for operation of type ${t.operation}`)}}onOperationDefinitionLeave(t){if(!(typeof this.options.operationName=="string"&&this.options.operationName!==t.name?.value)&&(this.options.onComplete&&this.options.onComplete(this.complexity),this.complexity>this.options.maximumComplexity))return this.context.reportError(this.createError())}nodeComplexity(t,n){if(t.selectionSet){let i={};(n instanceof M||n instanceof le)&&(i=n.getFields());let r;xe(n)?r=this.context.getSchema().getPossibleTypes(n).map(a=>a.name):r=[n.name];let s=t.selectionSet.selections.reduce((a,c)=>{let d=a,f=!0,T=!1;for(let x of c.directives??[])switch(x.name.value){case"include":{let S=this.includeDirectiveDef&&We(this.includeDirectiveDef,c,this.variableValues||{});typeof S?.if=="boolean"&&(f=S.if);break}case"skip":{let S=this.skipDirectiveDef&&We(this.skipDirectiveDef,c,this.variableValues||{});typeof S?.if=="boolean"&&(T=S.if);break}}if(!f||T)return a;switch(c.kind){case p.FIELD:{let x=i[c.name.value];if(!x)break;let N=te(x.type),S;try{S=Xe(x,c,this.variableValues||{})}catch(F){return this.context.reportError(F),a}let g=0;ce(N)&&(g=this.nodeComplexity(c,N));let U={childComplexity:g,args:S,field:x,node:c,type:n,context:this.requestContext};if(!this.estimators.find(F=>{let me=F(U);return typeof me=="number"&&!isNaN(me)?(d=Ve(me,a,r),!0):!1}))return this.context.reportError(new y(`No complexity could be calculated for field ${n.name}.${x.name}. At least one complexity estimator has to return a complexity score.`)),a;break}case p.FRAGMENT_SPREAD:{let x=this.context.getFragment(c.name.value);if(!x)break;let N=this.context.getSchema().getType(x.typeCondition.name.value);if(!ce(N))break;let S=this.nodeComplexity(x,N);xe(N)?d=Ve(S,a,this.context.getSchema().getPossibleTypes(N).map(g=>g.name)):d=Ve(S,a,[N.name]);break}case p.INLINE_FRAGMENT:{let x=n;if(c.typeCondition&&c.typeCondition.name&&(x=this.context.getSchema().getType(c.typeCondition.name.value)||x,!ce(x)))break;let N=this.nodeComplexity(c,x);xe(x)?d=Ve(N,a,this.context.getSchema().getPossibleTypes(x).map(S=>S.name)):d=Ve(N,a,[x.name]);break}default:{d=Ve(this.nodeComplexity(c,n),a,r);break}}return d},{});return s?Math.max(...Object.values(s),0):NaN}return 0}createError(){return typeof this.options.createError=="function"?this.options.createError(this.options.maximumComplexity,this.complexity):new y(Gi(this.options.maximumComplexity,this.complexity))}};function Ve(e,t,n){for(let i of n)Object.prototype.hasOwnProperty.call(t,i)?t[i]+=e:t[i]=e;return t}o(Ve,"addComplexities");function Fn(e){let t=e?.defaultComplexity??1;return n=>t+n.childComplexity}o(Fn,"simpleEstimator");var Vn=o((e,t,n={})=>{let{definitions:i}=e,r=ji(i),s=$i(i);return Object.entries(s).map(([a,c])=>Ct(c,r,0,t,a,n))},"depthLimit");function ji(e){return e.reduce((t,n)=>(n.kind===p.FRAGMENT_DEFINITION&&(t[n?.name?.value??""]=n),t),{})}o(ji,"getFragments");function $i(e){return e.reduce((t,n)=>{if(n.kind===p.OPERATION_DEFINITION){let i=n?.name?.value??"";t[i]=n}return t},{})}o($i,"getQueriesAndMutations");function Ct(e,t,n,i,r,s){if(n>i)throw s?.onLimitReached?.(n,r),new y(`${r||"Your query"} exceeds maximum operation depth of ${i}`,{nodes:[e]});let a=s?.ignore??[/^__/];switch(e.kind){case p.FIELD:return Pi(e,a)||!e.selectionSet?0:1+Math.max(...e.selectionSet.selections.map(c=>Ct(c,t,n+1,i,r,s)));case p.FRAGMENT_SPREAD:return Ct(t[e.name.value],t,n,i,r,s);case p.INLINE_FRAGMENT:case p.FRAGMENT_DEFINITION:case p.OPERATION_DEFINITION:return Math.max(...e.selectionSet.selections.map(c=>Ct(c,t,n,i,r,s)));default:throw new Error("uh oh! depth crawler cannot handle: "+e.kind)}}o(Ct,"determineDepth");var Pi=o((e,t)=>t.find(n=>e.name.value.match(n)!==null)||!1,"isIgnored");var Qi=o(async(e,t)=>{if(!t.complexityLimit)throw new sn("No complexity maximum defined, you need to pass a maxComplexity to the policy");let i=t.endpointUrl;if(!i)throw new sn("No GraphQL endpoint, you need to pass a endpointUrl to the policy");let r=Rt(),c=(await(await fetch(i,{method:"POST",body:JSON.stringify({query:r}),headers:{"Content-Type":"application/json"}})).json()).data;if(!c||!c?.__schema)throw new y("GraphQL introspection query failed, enable introspection or pass a schema url in configuration.");let d=kt(c,{assumeValid:!0}),f=Cn({estimators:[Fn({defaultComplexity:1})],schema:d,query:e,variables:{count:10}});if(t.complexityLimit&&f>t.complexityLimit)throw new y(`Query is too complex (${f}/${t.complexityLimit}), remove some fields and try again`)},"applyComplexityLimitPolicy"),Bi=o(async(e,t)=>{let n=t.depthLimit;if(!n)throw new sn("No maximum depth defined, you need to pass a maxDepth to the policy");return Math.max(...Vn(e,n))},"applyDepthLimitPolicy"),qi=o(async(e,t,n)=>{try{let r=await e.clone().json(),s=at(r.query);n.useDepthLimit&&await Bi(s,n.useDepthLimit),n.useComplexityLimit&&await Qi(s,n.useComplexityLimit)}catch(i){if(t.log.error(i),i instanceof y)return new Response(JSON.stringify(i.toJSON()),{status:400,headers:{"Content-Type":"application/json"}});throw i}return e},"GraphQLComplexityLimitInboundPolicy");import{HttpProblems as Ji}from"@zuplo/runtime";function Yi(e){if(!e)return!1;let t=e.replace(/\s/g,"");return t.includes("__schema")||t.includes("__type")}o(Yi,"isIntrospectionQuery");var zi=o(async(e,t)=>{let i=await e.clone().json();return Yi(i.query)?Ji.forbidden(e,t,{detail:"Introspection queries are not allowed"}):e},"GraphQLDisableIntrospectionInboundPolicy");export{qi as GraphQLComplexityLimitInboundPolicy,zi as GraphQLDisableIntrospectionInboundPolicy};
|
|
181
|
-
/*! For license information please see index.
|
|
181
|
+
/*! For license information please see index.js.LEGAL.txt */
|
package/package.json
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zuplo/graphql",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2154.0",
|
|
4
4
|
"repository": "https://github.com/zuplo/zuplo",
|
|
5
5
|
"author": "Zuplo, Inc.",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
|
-
"node": "./index.
|
|
9
|
-
"worker": "./index.
|
|
10
|
-
"types": "./
|
|
8
|
+
"node": "./dist/index.cjs",
|
|
9
|
+
"worker": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts"
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
|
-
"types": "./types-beta.d.ts",
|
|
14
13
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
15
14
|
"engines": {
|
|
16
15
|
"node": ">=18.0.0"
|
|
@@ -20,11 +19,7 @@
|
|
|
20
19
|
"registry": "https://registry.npmjs.org"
|
|
21
20
|
},
|
|
22
21
|
"files": [
|
|
23
|
-
"
|
|
24
|
-
"index.min.cjs",
|
|
25
|
-
"index.min.cjs.LEGAL.txt",
|
|
26
|
-
"index.min.js",
|
|
27
|
-
"index.min.js.LEGAL.txt",
|
|
22
|
+
"out/**/**/*",
|
|
28
23
|
"README.md",
|
|
29
24
|
"LICENSE.txt"
|
|
30
25
|
],
|
|
File without changes
|
|
File without changes
|
|
File without changes
|