@zuplo/graphql 6.42.1 → 6.43.1

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/out/esm/index.js CHANGED
@@ -179,4 +179,3 @@ In some cases, you need to provide options to alter GraphQL's execution behavior
179
179
  }
180
180
  }
181
181
  `}s(wt,"getIntrospectionQuery");function Rt(e,t){k(e)&&k(e.__schema)||b(!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=pe(n.types,l=>l.name,l=>N(l));for(let l of[...qt,...Zt])i[l.name]&&(i[l.name]=l);let r=n.queryType?T(n.queryType):null,o=n.mutationType?T(n.mutationType):null,a=n.subscriptionType?T(n.subscriptionType):null,c=n.directives?n.directives.map(Mn):[];return new Ke({description:n.description,query:r,mutation:o,subscription:a,types:Object.values(i),directives:c,assumeValid:t?.assumeValid});function d(l){if(l.kind===O.LIST){let v=l.ofType;if(!v)throw new Error("Decorated type deeper than introspection query.");return new w(d(v))}if(l.kind===O.NON_NULL){let v=l.ofType;if(!v)throw new Error("Decorated type deeper than introspection query.");let oe=d(v);return new E(xt(oe))}return f(l)}function f(l){let v=l.name;if(!v)throw new Error(`Unknown type reference: ${m(l)}.`);let oe=i[v];if(!oe)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 oe}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 O.SCALAR:return S(l);case O.OBJECT:return U(l);case O.INTERFACE:return K(l);case O.UNION:return V(l);case O.ENUM:return me(l);case O.INPUT_OBJECT:return se(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===O.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:s(()=>g(l),"interfaces"),fields:s(()=>ee(l),"fields")})}function K(l){return new de({name:l.name,description:l.description,interfaces:s(()=>g(l),"interfaces"),fields:s(()=>ee(l),"fields")})}function V(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:s(()=>l.possibleTypes.map(T),"types")})}function me(l){if(!l.enumValues){let v=m(l);throw new Error(`Introspection result missing enumValues: ${v}.`)}return new ce({name:l.name,description:l.description,values:pe(l.enumValues,v=>v.name,v=>({description:v.description,deprecationReason:v.deprecationReason}))})}function se(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:s(()=>_e(l.inputFields),"fields"),isOneOf:l.isOneOf})}function ee(l){if(!l.fields)throw new Error(`Introspection result missing fields: ${m(l)}.`);return pe(l.fields,v=>v.name,Ue)}function Ue(l){let v=d(l.type);if(!fe(v)){let oe=m(v);throw new Error(`Introspection must provide output type for fields, but received: ${oe}.`)}if(!l.args){let oe=m(l);throw new Error(`Introspection result missing field args: ${oe}.`)}return{description:l.description,deprecationReason:l.deprecationReason,type:v,args:_e(l.args)}}function _e(l){return pe(l,v=>v.name,Ze)}function Ze(l){let v=d(l.type);if(!z(v)){let Gn=m(v);throw new Error(`Introspection must provide input type for arguments, but received: ${Gn}.`)}let oe=l.defaultValue!=null?le(pt(l.defaultValue),v):void 0;return{description:l.description,type:v,defaultValue:oe,deprecationReason:l.deprecationReason}}function Mn(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 W({name:l.name,description:l.description,isRepeatable:l.isRepeatable,locations:l.locations.slice(),args:_e(l.args)})}}s(Rt,"buildClientSchema");function ji(e,t){return`The query exceeds the maximum complexity of ${e}. Actual complexity is ${t}`}s(ji,"queryComplexityMessage");function Fn(e){let t=new Ee(e.schema),n=[],i=new Fe(e.schema,e.query,t,o=>n.push(o)),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}s(Fn,"getComplexity");var rn=class{static{s(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(o=>this.context.reportError(o));return}this.variableValues=n||{};let r=this.context.getSchema();switch(t.operation){case"query":{let o=r.getQueryType();if(!o)throw new Error("Schema does not define the required query root type");this.complexity+=this.nodeComplexity(t,o);break}case"mutation":{let o=r.getMutationType();if(!o)throw new Error("Schema does not define the required mutation root type");this.complexity+=this.nodeComplexity(t,o);break}case"subscription":{let o=r.getSubscriptionType();if(!o)throw new Error("Schema does not define the required mutation subscription type");this.complexity+=this.nodeComplexity(t,o);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 de)&&(i=n.getFields());let r;xe(n)?r=this.context.getSchema().getPossibleTypes(n).map(a=>a.name):r=[n.name];let o=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=ne(x.type),S;try{S=Xe(x,c,this.variableValues||{})}catch(V){return this.context.reportError(V),a}let g=0;ue(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(V=>{let me=V(U);return typeof me=="number"&&!isNaN(me)?(d=Ve(me,a,r),!0):!1}))return this.context.reportError(new h(`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(!ue(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,!ue(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 o?Math.max(...Object.values(o),0):NaN}return 0}createError(){return typeof this.options.createError=="function"?this.options.createError(this.options.maximumComplexity,this.complexity):new h(ji(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}s(Ve,"addComplexities");function Vn(e){let t=e?.defaultComplexity??1;return n=>t+n.childComplexity}s(Vn,"simpleEstimator");var Un=s((e,t,n={})=>{let{definitions:i}=e,r=$i(i),o=Pi(i);return Object.entries(o).map(([a,c])=>kt(c,r,0,t,a,n))},"depthLimit");function $i(e){return e.reduce((t,n)=>(n.kind===p.FRAGMENT_DEFINITION&&(t[n?.name?.value??""]=n),t),{})}s($i,"getFragments");function Pi(e){return e.reduce((t,n)=>{if(n.kind===p.OPERATION_DEFINITION){let i=n?.name?.value??"";t[i]=n}return t},{})}s(Pi,"getQueriesAndMutations");function kt(e,t,n,i,r,o){if(n>i)throw o?.onLimitReached?.(n,r),new h(`${r||"Your query"} exceeds maximum operation depth of ${i}`,{nodes:[e]});let a=o?.ignore??[/^__/];switch(e.kind){case p.FIELD:return Qi(e,a)||!e.selectionSet?0:1+Math.max(...e.selectionSet.selections.map(c=>kt(c,t,n+1,i,r,o)));case p.FRAGMENT_SPREAD:return kt(t[e.name.value],t,n,i,r,o);case p.INLINE_FRAGMENT:case p.FRAGMENT_DEFINITION:case p.OPERATION_DEFINITION:return Math.max(...e.selectionSet.selections.map(c=>kt(c,t,n,i,r,o)));default:throw new Error("uh oh! depth crawler cannot handle: "+e.kind)}}s(kt,"determineDepth");var Qi=s((e,t)=>t.find(n=>e.name.value.match(n)!==null)||!1,"isIgnored");var Bi=s(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=wt(),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 h("GraphQL introspection query failed, enable introspection or pass a schema url in configuration.");let d=Rt(c,{assumeValid:!0}),f=Fn({estimators:[Vn({defaultComplexity:1})],schema:d,query:e,variables:{count:10}});if(t.complexityLimit&&f>t.complexityLimit)throw new h(`Query is too complex (${f}/${t.complexityLimit}), remove some fields and try again`)},"applyComplexityLimitPolicy"),qi=s(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(...Un(e,n))},"applyDepthLimitPolicy"),Ji=s(async(e,t,n)=>{try{let r=await e.clone().json(),o=at(r.query);n.useDepthLimit&&await qi(o,n.useDepthLimit),n.useComplexityLimit&&await Bi(o,n.useComplexityLimit)}catch(i){if(t.log.error(i),i instanceof h)return new Response(JSON.stringify(i.toJSON()),{status:400,headers:{"Content-Type":"application/json"}});throw i}return e},"GraphQLComplexityLimitInboundPolicy");import{HttpProblems as Yi}from"@zuplo/runtime";function zi(e){if(!e)return!1;let t=e.replace(/\s/g,"");return t.includes("__schema")||t.includes("__type")}s(zi,"isIntrospectionQuery");var Ki=s(async(e,t)=>{let i=await e.clone().json();return zi(i.query)?Yi.forbidden(e,t,{detail:"Introspection queries are not allowed"}):e},"GraphQLDisableIntrospectionInboundPolicy");export{Ji as GraphQLComplexityLimitInboundPolicy,Ki as GraphQLDisableIntrospectionInboundPolicy};
182
- /*! For license information please see index.js.LEGAL.txt */
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@zuplo/graphql",
3
3
  "type": "module",
4
- "version": "6.42.1",
4
+ "version": "6.43.1",
5
5
  "repository": "https://github.com/zuplo/zuplo",
6
6
  "author": "Zuplo, Inc.",
7
7
  "exports": {
8
8
  ".": {
9
- "import": "./out/index.js",
10
- "types": "./out/types/index.d.ts"
9
+ "types": "./out/types/index.d.ts",
10
+ "import": "./out/index.js"
11
11
  }
12
12
  },
13
13
  "license": "SEE LICENSE IN LICENSE.txt",
@@ -31,6 +31,6 @@
31
31
  "graphql": "^16.8.1"
32
32
  },
33
33
  "peerDependencies": {
34
- "@zuplo/runtime": "6.42.1"
34
+ "@zuplo/runtime": "6.43.1"
35
35
  }
36
36
  }
File without changes