@graphile/pro
Version:
Professional PostGraphile enhancements
1 lines • 26.7 kB
JavaScript
(()=>{"use strict";var e={321:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.useDepthLimit=void 0;const i=n(124),r=n(567);t.useDepthLimit=function(e){const t=(0,i.depthLimit)(e);return{onValidate({params:e}){e.rules=e.rules?[...e.rules,t]:[...r.specifiedRules,t]}}}},124:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.countOperationDepths=t.countDepth=t.depthLimit=t.useDepthLimit=void 0;const i=n(567),r=n(110);var o=n(321);function s(e={}){const{maxDepth:t=12,maxListDepth:n=4,maxSelfReferentialDepth:i=2,maxIntrospectionDepth:o=12,maxIntrospectionListDepth:s=3,maxIntrospectionSelfReferentialDepth:a=2,maxDepthByFieldCoordinates:l,revealDetails:c=!1,fragmentsAddToDepth:u=!1}=e;return{maxDepth:t,maxListDepth:n,maxSelfReferentialDepth:i,maxIntrospectionDepth:o,maxIntrospectionListDepth:s,maxIntrospectionSelfReferentialDepth:a,maxDepthByFieldCoordinates:Object.assign(Object.create(null),{"Query.__schema":1,"Query.__type":1,"__Type.fields":1,"__Type.inputFields":1,"__Type.interfaces":1,"__Type.ofType":8,"__Type.possibleTypes":1,"__Field.args":1,"__Field.type":1,...l,[r.DEPTH]:t,[r.INTROSPECTION_DEPTH]:o,[r.LIST_DEPTH]:n,[r.INTROSPECTION_LIST_DEPTH]:s}),revealDetails:c,fragmentsAddToDepth:u}}function a(e,t){return"query"===t.operation?e.getQueryType():"mutation"===t.operation?e.getMutationType():"subscription"===t.operation?e.getSubscriptionType():null}function l(e){const t=new Map;for(const n of e)t.set(n.name.value,n);return t}function c(e,t,n,i={}){const r=s(i),o=a(e,t);if(!o)throw new Error("Could not determine root type for operation");const c=l(n);return{depths:u({schema:e,fragments:{get(e){const t=c.get(e);if(!t)throw new Error(`Fragment '${e}' not found!`);return t}},options:r,depthByFragment:new Map},o,t,[],!1),resolvedOptions:r}}function u(e,t,n,o,s){const{schema:a,fragments:l,options:{fragmentsAddToDepth:c},depthByFragment:d}=e;switch(n.kind){case i.Kind.OPERATION_DEFINITION:case i.Kind.FIELD:case i.Kind.INLINE_FRAGMENT:case i.Kind.FRAGMENT_DEFINITION:{const l=Object.create(null),d="Field"===n.kind?`${t.name}.${n.name.value}`:null;if(d&&p(l,d,1),n.selectionSet){(c||"Field"===n.kind)&&p(l,s?r.INTROSPECTION_DEPTH:r.DEPTH,1);const f=(()=>{switch(n.kind){case i.Kind.OPERATION_DEFINITION:return t;case i.Kind.FIELD:if((0,i.isObjectType)(t)){const e=n.name.value,o="__type"===e?i.TypeMetaFieldDef:"__schema"===e?i.SchemaMetaFieldDef:"__typename"===e?i.TypeNameMetaFieldDef:t.getFields()[n.name.value];return o?(p(l,s?r.INTROSPECTION_LIST_DEPTH:r.LIST_DEPTH,function(e){let t=0,n=e;do{if((0,i.isListType)(n))t++,n=n.ofType;else{if(!(0,i.isNonNullType)(n))break;n=n.ofType}}while(n&&t<100);return t}(o.type)),(0,i.getNamedType)(o.type)):null}break;case i.Kind.INLINE_FRAGMENT:return n.typeCondition?a.getType(n.typeCondition.name.value):t;case i.Kind.FRAGMENT_DEFINITION:return a.getType(n.typeCondition.name.value);default:throw new Error(`Unhandled node kind ${n.kind}`)}})();if(f){const t=l[r.DEPTH]??0,a=l[r.INTROSPECTION_DEPTH]??0,c=l[r.LIST_DEPTH]??0,p=l[r.INTROSPECTION_LIST_DEPTH]??0,g=d?l[d]??0:0;for(const h of n.selectionSet.selections){const n=h.kind===i.Kind.FIELD&&h.name.value.startsWith("__"),m=u(e,f,h,o,s||n),y=h.kind===i.Kind.FIELD?`${f.name}.${h.name.value}`:null;y&&!l[y]&&(l[y]=1);for(const e of Object.keys(m)){const n=(m[e]??0)+(e===d?g:e===r.DEPTH?t:e===r.INTROSPECTION_DEPTH?a:e===r.LIST_DEPTH?c:e===r.INTROSPECTION_LIST_DEPTH?p:0);(void 0===l[e]||l[e]<n)&&(l[e]=n)}}}}return l}case i.Kind.FRAGMENT_SPREAD:{const i=n.name.value,r=d.get(i);if(r)return r;if(o.includes(i))return{};const a=l.get(i);if(!a)return{};const c=u(e,t,a,[...o,i],s);return d.set(i,c),c}default:throw new Error(`Unexpected node type ${n.kind}`)}}function p(e,t,n=1){void 0!==e[t]?e[t]+=n:e[t]=n}Object.defineProperty(t,"useDepthLimit",{enumerable:!0,get:function(){return o.useDepthLimit}}),t.depthLimit=function(e={}){return function(t){const n=t.getSchema(),o=new Map;return{OperationDefinition:{enter(c){const p=c.name?.value??"(anonymous)",d=s(e),f={schema:n,fragments:l(t.getRecursivelyReferencedFragments(c)),options:d,depthByFragment:o},g=a(n,c);if(!g)return;const h=u(f,g,c,[],!1),{maxDepthByFieldCoordinates:m,revealDetails:y,maxSelfReferentialDepth:v,maxIntrospectionSelfReferentialDepth:b}=d,P=[];for(const e of Object.keys(h)){const t=e.includes(".")?e.startsWith("__")?b:v:void 0,n=h[e],i=m[e]??t,o=void 0===m[e];if(void 0!==i&&n>i)if(e.includes("."))P.push(`field ${e} nested ${n} times which exceeds ${o?"self referential ":""}maximum of ${i}`);else switch(e){case r.DEPTH:P.push(`operation depth ${n} exceeds maximum of ${i}`);break;case r.INTROSPECTION_DEPTH:P.push(`operation introspection depth ${n} exceeds maximum of ${i}`);break;case r.LIST_DEPTH:P.push(`operation list depth ${n} exceeds maximum of ${i}`);break;case r.INTROSPECTION_LIST_DEPTH:P.push(`operation introspection list depth ${n} exceeds maximum of ${i}`);break;default:P.push(`[internal error] coordinate '${e}' not understood`)}}return P.length>0?t.reportError(new i.GraphQLError(`'${p}' exceeds operation depth limits${y?`: ${P.join(", ")}`:""}.`,[c])):void 0}}}}},t.countDepth=c,t.countOperationDepths=function(e,t,n={}){const r="string"==typeof e?(0,i.buildSchema)(e):e,o=(0,i.parse)(t),s=o.definitions.filter((e=>e.kind===i.Kind.OPERATION_DEFINITION)),a=o.definitions.filter((e=>e.kind===i.Kind.FRAGMENT_DEFINITION)),l=Object.create(null);for(const e of s){const t=e.name?.value??"",{depths:i}=c(r,e,a,n);l[t]=i}return l}},110:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.INTROSPECTION_LIST_DEPTH=t.LIST_DEPTH=t.INTROSPECTION_DEPTH=t.DEPTH=void 0,t.DEPTH="$$depth",t.INTROSPECTION_DEPTH="$$introspectionDepth",t.LIST_DEPTH="$$listDepth",t.INTROSPECTION_LIST_DEPTH="$$introspectionListDepth"},254:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});const n=1e5,i=5e-4,r=1.2;t.default=e=>{function t(e,t,n,i=1e3,r=.12){var o;return Object.assign(Object.assign({},e),{extensions:Object.assign(Object.assign({},e.extensions),{graphilePro:Object.assign(Object.assign({},null===(o=e.extensions)||void 0===o?void 0:o.graphilePro),{getCosts(e){const{first:o,last:s}=e,a=o||s||i,l=0===a?0:1*Math.pow(a+3,.95);return{cost:t,baseChildCost:r,multiplier:Math.max(1,n*l)}}})})})}function o(e,t){var n;const i="number"==typeof t?{cost:t}:t;return Object.assign(Object.assign({},e),{extensions:Object.assign(Object.assign({},e.extensions),{graphilePro:Object.assign(Object.assign({},null===(n=e.extensions)||void 0===n?void 0:n.graphilePro),{getCosts:()=>i})})})}e.hook("GraphQLObjectType:fields:field",((e,t,n)=>{var i,r,o,s,a;const{scope:{isLiveField:l,originalField:c}}=n;if(!l)return e;const u=(null===(r=null===(i=e.extensions)||void 0===i?void 0:i.graphilePro)||void 0===r?void 0:r.getCosts)||(null===(s=null===(o=c.extensions)||void 0===o?void 0:o.graphilePro)||void 0===s?void 0:s.getCosts);return u?Object.assign(Object.assign({},e),{extensions:Object.assign(Object.assign({},e.extensions),{graphilePro:Object.assign(Object.assign({},null===(a=e.extensions)||void 0===a?void 0:a.graphilePro),{getCosts(...e){const t=u.apply(this,e);return Object.assign(Object.assign({},t),{cost:10*t.cost})}})})}):e})),e.hook("GraphQLObjectType:fields:field",((e,s,{scope:{isRootQuery:a,isPgFieldConnection:l,isPgFieldSimpleCollection:c,isPgConnectionTotalCountField:u,isPgRowConnectionType:p,isPageInfoHasNextPageField:d,isPageInfoHasPreviousPageField:f,isPgForwardRelationField:g,isPgBackwardRelationField:h,pgFieldIntrospection:m,fieldName:y}})=>{if(l||c)return m&&"class"===m.kind?a?t(e,1,1,parseInt(m.tags.unboundedAllCost,10)||n):t(e,.06,r,parseInt(m.tags.unboundedRelationCost,10)||1e3):m&&"procedure"===m.kind?a?t(e,(m.cost||100)*i,1,parseInt(m.tags.unboundedCost,10)||1e3):t(e,(m.cost||100)*i,r,parseInt(m.tags.unboundedCost,10)||50):t(e,2,r,n);if(u)return m&&"class"===m.kind?o(e,{cost:2,useParentMultiplier:!1}):(m&&m.kind,o(e,{cost:10,useParentMultiplier:!1}));if(p){if("pageInfo"===y)return o(e,{useParentMultiplier:!1,multiplier:1})}else{if(d||f)return o(e,{cost:7});if(g)return o(e,{cost:.06});if(h)return t(e,.06,r,1e3);if(m&&"procedure"===m.kind)return o(e,{cost:(m.cost||100)*i})}return e}))}},983:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});const i=n(567),r="|";function o(e){return null!=e.relation}function s(e){return e.join(r)}function a(e,t){if(e.length!==t.length)return e.length-t.length;const n=e.join(r),i=t.join(r);return n<i?-1:n>i?1:0}function l(e){return[...e].sort(((e,t)=>e<t?-1:e>t?1:0))}function c(e,t){return`${e}${r}${[...t.entries()].sort((([e],[t])=>e<t?-1:e>t?1:0)).map((([e,t])=>`${e}:${t}`)).join(",")}`}function u(e,t,n){const r=n.Self.name,{fieldName:o,isConnectionType:s,isEdgeType:a,pgIntrospection:l}=n.scope,c=function(e,t){const{fieldName:n,isPgForwardRelationField:i,isPgBackwardSingleRelationField:r,isPgBackwardRelationField:o,isPgFieldConnection:s,pgFieldIntrospection:a,pgIntrospection:l}=t;if(!n||!a)return null;if(i)return"constraint"===a.kind?function(e){const t=e.keyAttributes,n=e.foreignKeyAttributes;return t.every((e=>e))&&n.every((e=>e))?{localAttributes:t.map((e=>e.name)),remoteAttributes:n.map((e=>e.name))}:null}(a):null;if(!r&&!o)return null;const c=l,u=a;if(!c||"class"!==c.kind||!u||"class"!==u.kind)return null;const p=c.foreignConstraints.filter((e=>"f"===e.type&&e.classId===u.id)).find((t=>{const i=t.keyAttributes;if(!i.every((e=>e)))return!1;const o=!!u.constraints.find((e=>("p"===e.type||"u"===e.type)&&e.keyAttributeNums.length===i.length&&e.keyAttributeNums.every(((e,t)=>i[t].num===e))));return function(e,t,n,i,r,o,s,a){const l=i.keyAttributes;return!!l.every((e=>e))&&(s?a&&r===e.inflection.singleRelationByKeysBackwards(l,n,t,i):r===(o?e.inflection.manyRelationByKeys(l,n,t,i):e.inflection.manyRelationByKeysSimple(l,n,t,i)))}(e,c,u,t,n,!!s,!!r,o)}));return p?function(e){const t=e.keyAttributes,n=e.foreignKeyAttributes;return t.every((e=>e))&&n.every((e=>e))?{localAttributes:n.map((e=>e.name)),remoteAttributes:t.map((e=>e.name))}:null}(p):null}(t,n.scope),u=s&&("nodes"===o||"edges"===o),p=a&&"node"===o;if("class"===(null==l?void 0:l.kind)&&function(e,t,n){e.pgCycleUniqueAttributeGroupsByType.has(t)||e.pgCycleUniqueAttributeGroupsByType.set(t,l.constraints.filter((e=>"p"===e.type||"u"===e.type)).map((e=>e.keyAttributes)).filter((e=>e.every((e=>e)))).map((e=>e.map((e=>e.name)))))}(t,r),!c&&!u&&!p)return e;const d=(0,i.getNamedType)(e.type);return(0,i.isObjectType)(d)||(0,i.isInterfaceType)(d)?(function(e,t,n){const i=e.pgCycleEdgesByType.get(t);i?i.push(n):e.pgCycleEdgesByType.set(t,[n])}(t,r,{coordinate:`${r}.${o}`,targetTypeName:d.name,relation:c||void 0}),e):e}function p(e){const{localAttributes:t,remoteAttributes:n}=e.relation;return new Map(n.map(((e,n)=>[e,t[n]])))}function d(e,t){if(!o(t))return e;const{localAttributes:n,remoteAttributes:i}=t.relation;if(n.length!==e.size)return null;const r=[];for(let t=0,o=n.length;t<o;t++){const o=e.get(n[t]);if(null==o)return null;r.push([i[t],o])}return new Map(r)}function f(e,t,n,i){return n===e&&t.relation.localAttributes.every((e=>i.get(e)===e))}t.default=(e,t)=>{var n;const i=null!==(n=t.maxPgCycleDepth)&&void 0!==n?n:0;i<=0||(e.hook("build",(e=>e.extend(e,{pgCycleEdgesByType:new Map,pgCycleUniqueAttributeGroupsByType:new Map},"Adding cycle storage to build")),["PgCycles"]),e.hook("GraphQLObjectType:fields:field",u,["PgCycles"]),e.hook("finalize",((e,t)=>{const n=function(e,t,n){const i=[],r=new Set,u=[...e.entries()].flatMap((([e,n])=>n.filter(o).filter((n=>(t.get(e)||[]).some((e=>function(e,t){if(e.length!==t.length)return!1;const n=l(e),i=l(t);return n.every(((e,t)=>e===i[t]))}(e,n.relation.localAttributes))))).map((t=>({sourceTypeName:e,edge:t}))))).sort(((e,t)=>{const n=e.edge.coordinate,i=t.edge.coordinate;return n<i?-1:n>i?1:0}));for(const{sourceTypeName:t,edge:o}of u){const a=p(o);if(f(t,o,o.targetTypeName,a)){const e=[o.coordinate],t=s(e);r.has(t)||(r.add(t),i.push(e))}const l=(a,u,p,g,h)=>{if(!(g>=n))for(const n of e.get(a)||[]){if(p.includes(n.coordinate))continue;const e=d(u,n);if(!e)continue;const a=c(n.targetTypeName,e);if(h.has(a))continue;const m=[...p,n.coordinate];if(f(t,o,n.targetTypeName,e)){const e=m,t=s(e);r.has(t)||(r.add(t),i.push(e))}else l(n.targetTypeName,e,m,e===u?g:g+1,new Set([...h,a]))}};l(o.targetTypeName,a,[o.coordinate],1,new Set([c(o.targetTypeName,a)]))}return i.sort(a),i}(t.pgCycleEdgesByType,t.pgCycleUniqueAttributeGroupsByType,i);return e.extensions=Object.assign(Object.assign({},e.extensions||{}),{cycles:n}),e}),["PgCycles"]))}},242:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=e=>{e.hook("GraphQLObjectType:fields:field",((e,t,n)=>{var i,r,o,s,a;const{scope:{isLiveField:l,originalField:c}}=n;return l?Object.assign(Object.assign({},e),{extensions:Object.assign(Object.assign({},e.extensions),{graphilePro:Object.assign(Object.assign({},null===(i=e.extensions)||void 0===i?void 0:i.graphilePro),{paginationCap:(null===(o=null===(r=e.extensions)||void 0===r?void 0:r.graphilePro)||void 0===o?void 0:o.paginationCap)||(null===(a=null===(s=c.extensions)||void 0===s?void 0:s.graphilePro)||void 0===a?void 0:a.paginationCap)})})}):e})),e.hook("GraphQLObjectType:fields:field",((e,t,{scope:{isPgFieldConnection:n,isPgFieldSimpleCollection:i,pgFieldIntrospection:r,fieldName:o}})=>{var s;if(!n&&!i||!r||"class"!==r.kind&&"procedure"!==r.kind)return e;const a=null!=r.tags.paginationCap?parseInt(r.tags.paginationCap,10):1/0;if(-1===a||void 0===a)return e;if("number"!=typeof a||!isFinite(a)&&a!==1/0||a<-1)throw new Error(`Invalid pagination cap for '${o}', expected a number but instead received '${a}'`);return Object.assign(Object.assign({},e),{extensions:Object.assign(Object.assign({},e.extensions),{graphilePro:Object.assign(Object.assign({},null===(s=e.extensions)||void 0===s?void 0:s.graphilePro),{paginationCap:a,isPgFieldConnection:n,isPgFieldSimpleCollection:i})})})}))}},755:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});const i=n(567),r=n(891),o=n(222);t.default=e=>t=>{const{coerced:n,errors:s}=(0,r.default)(e,t);return{Document:{enter(){s&&s.forEach((e=>t.reportError(e)))}},Field:{enter(r){var s,a,l,c;const u=t.getFieldDef();if(!u)return;const p=(d=null===(a=null===(s=u.extensions)||void 0===s?void 0:s.graphilePro)||void 0===a?void 0:a.paginationCap,f=e.defaultPaginationCap,d===1/0?f:d);var d,f;if(null==p||!isFinite(p)||p<0)return;if(!(!(null===(c=null===(l=u.extensions)||void 0===l?void 0:l.graphilePro)||void 0===c?void 0:c.isPgFieldConnection)||r.selectionSet&&r.selectionSet.selections.find((e=>"Field"!==e.kind||"totalCount"!==e.name.value))))return;let g;try{g=(0,o.getArgumentValues)(u,r,n)||{}}catch(e){return void t.reportError(e)}const h=g.first,m=g.last;if(!h&&!m){const e=r.name.value;return void t.reportError(new i.GraphQLError(`You must provide a 'first' or 'last' argument to properly paginate the '${e}' field.`,r))}const y=h||m;if(y<0){const e=r.name.value;t.reportError(new i.GraphQLError(`Invalid pagination limit '${y}' on field '${e}', please pass an integer greater than zero.`,r))}else if(y>p){const e=r.name.value;t.reportError(new i.GraphQLError(`Invalid pagination limit '${y}' on field '${e}', please pass an integer no larger than '${p}'.`,r))}}}}}},891:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});const i=n(413);t.default=function(e,t){if(!e.calculatedVariableValues){const{operationName:n,variables:r}=e,o=t.getSchema(),s=t.getDocument().definitions.find((e=>"OperationDefinition"===e.kind&&(!n||!!e.name&&e.name.value===n)));if(!s)throw new Error(`Could not find operation named '${n}'`);const{errors:a,coerced:l}=(0,i.getVariableValues)(o,[...s.variableDefinitions||[]],r||{});e.calculatedVariableValues={errors:a,coerced:l}}return e.calculatedVariableValues}},222:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getArgumentValues=void 0;const i=n(413);Object.defineProperty(t,"getArgumentValues",{enumerable:!0,get:function(){return i.getArgumentValues}})},585:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});const i=n(567),r=n(891),o=n(222),s=.001;function a(e,t,n,i={},r){if(Object.keys(i).find((e=>!["cost","baseChildCost","multiplier","parent","useParentMultiplier"].includes(e))))throw new Error("Query cost visitor failed, invalid options passed to newNode");const{cost:o=s,baseChildCost:a=0,multiplier:l=1,parent:c=null,useParentMultiplier:u=!0}=i;if(!isFinite(o))throw new Error(`Invalid cost for ${t} ${n}: '${o}'`);if(!isFinite(l))throw new Error(`Invalid multiplier for ${t} ${n}: '${l}'`);r&&r(`->cost=${o}, baseChildCost=${a}, multiplier=${l}, ${u?`use parent multiplier ${c?c.multiplier:"-"}`:"independent"}`);const p={astNode:e,type:t,name:"string"==typeof n?n:null,cost:o,baseChildCost:a,multiplier:l,parent:c,useParentMultiplier:u,children:[]};return c&&c.children.push(p),p}function l(e,t,n=0){const{type:i,name:r,cost:o,baseChildCost:s,multiplier:a}=e;if("FragmentSpread"===i){if(!r)throw new Error("Met a fragment with no name");const e=t[r];if(!e)throw new Error(`Query cost visitor failed, could not find fragment '${r}'`);return o+e.children.reduce(((e,i)=>e+(i.useParentMultiplier?a:1)*((i.useParentMultiplier?s:0)+l(i,t,n+1))),0)}return o+e.children.reduce(((e,i)=>e+(i.useParentMultiplier?a:1)*((i.useParentMultiplier?s:0)+l(i,t,n+1))),0)}t.default=e=>t=>{const{coerced:n,errors:s}=(0,r.default)(e,t),{costLimit:c,operationName:u,onComplete:p}=e,d=[],f={};function g(e){if("OperationDefinition"!==e.type)throw new Error("Query cost visitor failed, validate called on wrong type of node");return l(e,f)}let h=null,m=0;const y=null;return{Document:{enter(){s&&s.forEach((e=>t.reportError(e)))},leave(e){const n=d.length>1?d.find((e=>e.name===u)):d[0];if(n){const e=.2*g(n);e>c&&t.reportError(new i.GraphQLError(`This query has a computed cost of '${Math.ceil(e)}' which exceeds the limit of '${c}'. Try reducing the depth of the query, reducing the number of rows returned from connections or avoiding more complex fields.`,n.astNode)),"function"==typeof p&&p(Math.ceil(e),e)}else t.reportError(new i.GraphQLError(`Query cost visitor failed, could not find operation '${u}'`,e))}},OperationDefinition:{enter(e){m++;const n=e.name?e.name.value:"",r={query:1,mutation:2,subscription:10}[e.operation];r?(h=a(e,"OperationDefinition",n,{multiplier:r},y),d.push(h)):t.reportError(new i.GraphQLError(`Operation '${e.operation}' not understood.`,e))},leave(e){e.name&&e.name.value;h=null,m--,0!==m&&t.reportError(new i.GraphQLError(`Query cost visitor failed, '${m}' !== '0'`,e))}},FragmentDefinition:{enter(e){m++;const t=e.name.value;h=a(e,"FragmentDefinition",t,{},y),f[t]=h},leave(e){e.name.value;h=null,m--,0!==m&&t.reportError(new i.GraphQLError(`Query cost visitor failed, '${m}' !== '0'`,e))}},Field:{enter(e){var r,s;m++;const l=h,c=e.name.value,u=t.getParentType(),p=t.getFieldDef();if(!p)return;let d={};try{d=(0,o.getArgumentValues)(p,e,n)}catch(e){return void t.reportError(e)}const f="function"==typeof(null===(s=null===(r=p.extensions)||void 0===r?void 0:r.graphilePro)||void 0===s?void 0:s.getCosts)?p.extensions.graphilePro.getCosts(d):{},g=Object.keys(f).find((e=>!["cost","baseChildCost","multiplier","useParentMultiplier"].includes(e)));if(g)return void t.reportError(new i.GraphQLError(`Query cost visitor failed, invalid cost key '${g}' for ${u}#${c}`,e));const{cost:v,baseChildCost:b,multiplier:P,useParentMultiplier:T}=f;h=a(e,"Field",`${u}#${c}`,{parent:l,cost:v,baseChildCost:b,multiplier:P,useParentMultiplier:T},y)},leave(e){e.name.value,t.getParentType();h&&(h=h.parent),m--}},FragmentSpread:{enter(e){m++;const t=e.name.value;h=a(e,"FragmentSpread",t,{parent:h},y)},leave(){h=h?h.parent:null,m--}},InlineFragment:{enter(e){m++,h=a(e,"InlineFragment","(anonymous)",{parent:h},y)},leave(){h=h?h.parent:null,m--}}}}},511:e=>{e.exports=require("crypto")},567:e=>{e.exports=require("graphql")},413:e=>{e.exports=require("graphql/execution/values")},899:e=>{e.exports=require("json5")},136:e=>{e.exports=require("pg")},752:e=>{e.exports=require("postgraphile")},866:e=>{e.exports=require("tslib")}},t={};function n(i){var r=t[i];if(void 0!==r)return r.exports;var o=t[i]={exports:{}};return e[i](o,o.exports,n),o.exports}var i={};(()=>{var e=i;Object.defineProperty(e,"__esModule",{value:!0}),e.PgForceConnectionLimitPlugin=e.PgCyclesPlugin=e.PgCostsPlugin=void 0;const t=n(866),r=n(124),o=n(585),s=n(755),a=n(254);e.PgCostsPlugin=a.default;const l=n(983);e.PgCyclesPlugin=l.default;const c=n(242);e.PgForceConnectionLimitPlugin=c.default;const u=n(136),p=n(511),d=n(752),f=n(899),g=36e5,h=24*g,m={maxDepth:16,maxListDepth:6,maxSelfReferentialDepth:5,revealDetails:!0};function y(e){const t=e||process.env.GRAPHILE_LICENSE;if("string"!=typeof t)throw new Error("You must set the GRAPHILE_LICENSE environmental variable to use @graphile/pro, find out more: https://www.graphile.org/postgraphile/plugins/#first-party-premium-plugins");let n;const i=(r=t,Buffer.from(String(r),"base64"));var r;if(i.length>7&&!(7&i.readUInt8(i.length-1))){const e=i.readUInt8(i.length-1)>>3,t=i.readUInt8(i.length-2);if(i.length>5+t){const r=i.slice(2,2+t),o=i.slice(2+t,i.length-2);if(0===e){const e=(0,p.createVerify)("SHA256");if(e.write(o),e.end(),e.verify("-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEiapOpoQOUtpoIoJjCZPyAiX51aIt\nwMJFV4OIttJG7N7EVGOAsgLddp02m8M35S82aHwCHW/AqeBbDpcCVvKGsQ==\n-----END PUBLIC KEY-----",r))try{n=JSON.parse(o.toString("utf8"))}catch(e){throw new Error("Invalid (corrupt) license file")}}}}if(!n)throw new Error("Invalid license key");const{t:o,g:s,e:a}=n,l=o;if(2&~s)throw new Error("Your license does not cover usage of the @graphile/pro module");if(a<Date.now())throw new Error("Your Graphile license has expired, please renew it!");if(a<Date.now()+90*h){const e=a-Date.now(),t=Math.floor(e/h),n=Math.floor((e-t*h)/g);console.error(`\n\n⚠️ ⚠️ ⚠️ \n\nYour Graphile license key will expire in ${t} ${1===t?"day":"days"} ${n} ${1===n?"hour":"hours"}, please update it at the Graphile Store.\n\n⚠️ ⚠️ ⚠️ \n\n`)}return{licensedTo:l}}function v(e){return e&&"function"==typeof e.constructor&&e.constructor.name&&String(e.constructor.name)||null}let b=!1;const P={"cli:flags:add:standard":e=>(e("--read-only-connection <string>","⚡️pass the PostgreSQL connection string to use for read-only queries (i.e. not mutations) - typically for connecting to replicas via PgBouncer or similar"),e),"cli:flags:add":e=>(e("--default-pagination-cap [int]","⚡️Ensures all connections have first/last specified and are no large than this value (default: 50), set to ' -1' to disable; override via smart comment `@paginationCap 50`"),e("--graphql-depth-limit [string]",`⚡️Validates GraphQL queries cannot be deeper than the specified int, or options (default: ${(0,f.stringify)(m)}), set to ' -1' to disable`),e("--graphql-cost-limit [int]","⚡️[experimental] Only allows queries with a computed cost below the specified int (default: 30000), set to ' -1' to disable"),e),"cli:library:options"(e,{config:t,cliOptions:n}){const i=Object.assign(Object.assign({},t.options),n),{defaultPaginationCap:r,graphqlDepthLimit:o,graphqlCostLimit:s,exposeGraphQLCost:a=!0,readOnlyConnection:l}=i,c=String(o||"").trim(),u="{"===c[0]?(0,f.parse)(c):parseInt(c,10)||m;return Object.assign(Object.assign({},e),{defaultPaginationCap:parseInt(String(r||""),10)||50,graphqlDepthLimit:u,graphqlCostLimit:parseInt(String(s||""),10)||3e4,exposeGraphQLCost:a,readOnlyConnection:l})},"cli:greeting"(e,{options:t}){const{license:n}=t;try{const{licensedTo:t}=y(n);return[...e,`@graphile/pro: v2.1.1, licensed to '${t}'`]}catch(t){return b=!0,[...e,`@graphile/pro IS DISABLED - INVALID LICENSE: ${t.message}`]}},"postgraphile:options"(e){const{defaultPaginationCap:t,graphqlDepthLimit:n,graphqlCostLimit:i,exposeGraphQLCost:r=!0,readOnlyConnection:o,license:s,allowExplain:p}=e;try{y(s)}catch(t){return b=!0,console.error(),console.error(),console.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"),console.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"),console.error(),console.error(`ERROR: @graphile/pro IS DISABLED (due to invalid/expired license), none of its protections will function. ${t.message}`),console.error(),console.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"),console.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"),console.error(),console.error(),e}let f;var g,h,P;return o&&(f=(h=g=o)instanceof u.Pool||(P=h)&&"function"==typeof P.constructor&&P.constructor===u.Pool.super_||h&&"object"==typeof h&&("Pool"===v(h)||"BoundPool"===v(h))&&h.Client&&h.options&&"function"==typeof h.connect&&"function"==typeof h.end&&"function"==typeof h.query?g:new u.Pool("string"==typeof g?{connectionString:g}:g||{}),f.on("error",(e=>{console.error("Read only PostgreSQL client generated error: ",e.message)})),d.debugPgClient&&f.on("connect",(e=>{(0,d.debugPgClient)(e,!!p)}))),Object.assign(Object.assign({},e),{graphqlDepthLimit:null!=n?n:m,graphqlCostLimit:null!=i?i:3e4,exposeGraphQLCost:r,readReplicaPgPool:f,appendPlugins:[...e.appendPlugins||[],a.default,l.default,c.default],graphileBuildOptions:Object.assign(Object.assign({},e.graphileBuildOptions),{defaultPaginationCap:null!=t?t:50})})},"postgraphile:httpParamsList"(e,{options:t,httpError:n}){if(b)return e;const{batchedQueryLimit:i=10}=t;if(e.length>i)throw n(400,`Too many batched queries, send no more than ${i}`);return e},"postgraphile:validationRules"(e,{options:n,req:i,operationName:a,variables:l,meta:c}){if(b)return e;const{overrideOptionsForRequest:u}=n,p=t.__rest(n,["overrideOptionsForRequest"]),d="function"==typeof u?Object.assign(Object.assign({},p),u(i,{options:n})):p,f=isFinite(d.graphqlDepthLimit)?Object.assign(Object.assign({},m),{maxDepth:d.graphqlDepthLimit}):Object.assign(Object.assign({},m),d.graphqlDepthLimit);return[...e,(0,s.default)({operationName:a,variables:l,defaultPaginationCap:d.defaultPaginationCap}),...f.maxDepth>=0?[(0,r.depthLimit)(f)]:[],...d.graphqlCostLimit>=0?[(0,o.default)({operationName:a,variables:l,costLimit:d.graphqlCostLimit,onComplete(e){d.exposeGraphQLCost&&c&&(c.graphqlQueryCost=e)}})]:[]]},withPostGraphileContext(e,{options:{readReplicaPgPool:t,queryDocumentAst:n,operationName:i}}){if(b)return e;const r=n;if(!t)return e;if(r&&"Document"===r.kind){const n=r.definitions.find((e=>"OperationDefinition"===e.kind&&(!i||!!e.name&&e.name.value===i)));if(n){const i=n.operation;if("query"===i||"subscription"===i)return(n,i)=>e(Object.assign(Object.assign({},n),{pgPool:t}),i)}}return e}};e.default=P})(),module.exports=i})();