Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@0no-co/graphqlsp

Package Overview
Dependencies
Maintainers
2
Versions
110
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@0no-co/graphqlsp - npm Package Compare versions

Comparing version 0.14.1 to 0.15.0

7

CHANGELOG.md
# @0no-co/graphqlsp
## 0.15.0
### Minor Changes
- Make the LSP work with [`gql.tada`](https://github.com/0no-co/gql.tada)
Submitted by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#160](https://github.com/0no-co/GraphQLSP/pull/160))
## 0.14.1

@@ -4,0 +11,0 @@

2

dist/index.js

@@ -1,1 +0,1 @@

"use strict";var e=require("graphql"),t=require("node-fetch"),n=require("path"),i=require("fs"),r=require("@graphql-codegen/core"),s=require("@graphql-codegen/typescript"),a=require("@graphql-codegen/typescript-operations"),o=require("@graphql-codegen/typed-document-node"),l=require("@graphql-codegen/add"),c=require("typescript/lib/tsserverlibrary"),p=require("graphql-language-service"),g=require("lru-cache"),u=require("@sindresorhus/fnv1a");function d(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,i.get?i:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var m=d(s),f=d(a),h=d(o),S=d(l);const x=async(t,s,a,o)=>{if(!t)return;const l={documents:[],config:{scalars:a,avoidOptionals:!1,enumsAsTypes:!0,globalNamespace:!0,nonOptionalTypename:!0},filename:s,schema:e.parse(e.printSchema(t)),plugins:[{typescript:{}},o&&{add:{content:o}}].filter(Boolean),pluginMap:o?{typescript:m,add:S}:{typescript:m}},c=await r.codegen(l);let p=s.split("/");p.pop();const g=n.posix.join(p.join("/"));i.existsSync(g)||i.mkdirSync(g),i.writeFile(n.posix.join(s),c,"utf8",(e=>{console.error(e)}))};function v(e,t){const n=i.readFileSync(e,"utf-8");return t.getFullText()!==n}function T(e,t){const n=e.languageService.getProgram();if(n)return n.getSourceFile(t)||void 0}function y(e,t){return function e(n){if(t>=n.getStart()&&t<n.getEnd())return c.forEachChild(n,e)||n}(e)}function E(e,t){const n=[];return function e(i){c.isTaggedTemplateExpression(i)&&i.tag.getText()===t||c.isNoSubstitutionTemplateLiteral(i)&&c.isTaggedTemplateExpression(i.parent)&&i.parent.tag.getText()===t?n.push(i):c.forEachChild(i,e)}(e),n}function N(e,t,n,i=!0){const r=[];let s=[],a=!i;return function i(o){if(c.isCallExpression(o)&&o.expression.getText()===t){a||(a=!0,s=b(e.fileName,o,n));const[t]=o.arguments;t&&c.isNoSubstitutionTemplateLiteral(t)&&r.push(t)}else c.forEachChild(o,i)}(e),{nodes:r,fragments:s}}function b(t,n,i){let r=[];const s=i.languageService.getDefinitionAtPosition(t,n.expression.getStart());if(!s)return r;const a=T(i,s[0].fileName);return a?(c.forEachChild(a,(t=>{if(c.isVariableStatement(t)&&t.declarationList&&"documents"===t.declarationList.declarations[0].name.getText()){const[n]=t.declarationList.declarations;n.initializer&&c.isObjectLiteralExpression(n.initializer)&&n.initializer.properties.forEach((t=>{if(c.isPropertyAssignment(t)&&c.isStringLiteral(t.name))try{const n=JSON.parse(`${t.name.getText().replace(/'/g,'"')}`);n.includes("fragment ")&&n.includes(" on ")&&e.parse(n,{noLocation:!0}).definitions.forEach((e=>{"FragmentDefinition"===e.kind&&r.push(e)}))}catch(e){}}))}})),r):r}function C(e){return e.statements.filter(c.isImportDeclaration)}function I(e){for(;c.isNoSubstitutionTemplateLiteral(e)||c.isToken(e)||c.isTemplateExpression(e)||c.isTemplateSpan(e);)e=e.parent;return e}function D(e){for(;c.isNoSubstitutionTemplateLiteral(e)||c.isToken(e)||c.isTemplateExpression(e)||c.isTemplateSpan(e);)e=e.parent;return e}class L{constructor(e,t){this.line=e,this.character=t}setLine(e){this.line=e}setCharacter(e){this.character=e}lessThanOrEqualTo(e){return this.line<e.line||this.line===e.line&&this.character<=e.character}}function k(t,n,i){if(c.isNoSubstitutionTemplateLiteral(t))return{combinedText:t.getText().slice(1,-1),resolvedSpans:[]};let r=t.template.getText().slice(1,-1);if(c.isNoSubstitutionTemplateLiteral(t.template)||0===t.template.templateSpans.length)return{combinedText:r,resolvedSpans:[]};let s=0;const a=t.template.templateSpans.map((t=>{if(c.isIdentifier(t.expression)){const a=i.languageService.getDefinitionAtPosition(n,t.expression.getStart());if(!a)return;const o=a[0],l=T(i,o.fileName);if(!l)return;const p=y(l,o.textSpan.start);if(!p||!p.parent)return;const g=p.parent;if(c.isVariableDeclaration(g)){const n=t.expression.escapedText,a=t.expression.getStart()-2,l={start:a,length:t.expression.end-a+1};if(g.initializer&&c.isTaggedTemplateExpression(g.initializer)){const e=k(g.initializer,o.fileName,i);r=r.replace("${"+t.expression.escapedText+"}",e.combinedText);const a={lines:e.combinedText.split("\n").length,identifier:n,original:l,new:{start:l.start+s,length:e.combinedText.length}};return s+=e.combinedText.length-l.length,a}if(g.initializer&&c.isAsExpression(g.initializer)&&c.isTaggedTemplateExpression(g.initializer.expression)){const e=k(g.initializer.expression,o.fileName,i);r=r.replace("${"+t.expression.escapedText+"}",e.combinedText);const a={lines:e.combinedText.split("\n").length,identifier:n,original:l,new:{start:l.start+s,length:e.combinedText.length}};return s+=e.combinedText.length-l.length,a}if(g.initializer&&c.isAsExpression(g.initializer)&&c.isAsExpression(g.initializer.expression)&&c.isObjectLiteralExpression(g.initializer.expression.expression)){const i=JSON.parse(g.initializer.expression.expression.getText()),a=e.print(i);r=r.replace("${"+t.expression.escapedText+"}",a);const o={lines:a.split("\n").length,identifier:n,original:l,new:{start:l.start+s,length:a.length}};return s+=a.length-l.length,o}return}}})).filter(Boolean);return{combinedText:r,resolvedSpans:a}}const F=(e,t)=>{const n=e.getText().slice(1,-1).split("\n"),i=p.onlineParser(),r=i.startState();let s,a=e.pos+1;for(let e=0;e<n.length;e++){const o=a-1,l=new p.CharacterStream(n[e]);for(;!l.eol();){const n=i.token(l,r),a=l.current();if(a&&o+l.getStartOfToken()<=t&&o+l.getCurrentPosition()>=t){s={line:e,start:l.getStartOfToken()+1,end:l.getCurrentPosition(),string:a,state:r,tokenKind:n};break}}a+=n[e].length+1}return s};function O(e,t){const n=e.filter(t);return 0===n.length?e:n}function A(e){return e.toLowerCase().replace(/\W/g,"")}function j(e,t){let n=function(e,t){let n,i;const r=[],s=e.length,a=t.length;for(n=0;n<=s;n++)r[n]=[n];for(i=1;i<=a;i++)r[0][i]=i;for(n=1;n<=s;n++)for(i=1;i<=a;i++){const s=e[n-1]===t[i-1]?0:1;r[n][i]=Math.min(r[n-1][i]+1,r[n][i-1]+1,r[n-1][i-1]+s),n>1&&i>1&&e[n-1]===t[i-2]&&e[n-2]===t[i-1]&&(r[n][i]=Math.min(r[n][i],r[n-2][i-2]+s))}return r[s][a]}(t,e);return e.length>t.length&&(n-=e.length-t.length-1,n+=0===e.indexOf(t)?0:.5),n}function P(e,t){const n=new Set;return R(e,((e,i)=>{if(i.kind===p.RuleKinds.FRAGMENT_SPREAD&&i.name){const e=w(i,p.RuleKinds.FIELD);t&&(null==e?void 0:e.name)===t&&n.add(i.name)}})),n}function w(e,t){var n,i,r,s,a,o,l,c,p,g;return(null===(n=e.prevState)||void 0===n?void 0:n.kind)===t?e.prevState:(null===(r=null===(i=e.prevState)||void 0===i?void 0:i.prevState)||void 0===r?void 0:r.kind)===t?e.prevState.prevState:(null===(o=null===(a=null===(s=e.prevState)||void 0===s?void 0:s.prevState)||void 0===a?void 0:a.prevState)||void 0===o?void 0:o.kind)===t?e.prevState.prevState.prevState:(null===(g=null===(p=null===(c=null===(l=e.prevState)||void 0===l?void 0:l.prevState)||void 0===c?void 0:c.prevState)||void 0===p?void 0:p.prevState)||void 0===g?void 0:g.kind)===t?e.prevState.prevState.prevState.prevState:void 0}function R(e,t){const n=e.split("\n"),i=p.onlineParser();let r=i.startState(),s="",a=new p.CharacterStream("");for(let e=0;e<n.length;e++){for(a=new p.CharacterStream(n[e]);!a.eol()&&(s=i.token(a,r),"BREAK"!==t(a,r,s,e)););t(a,r,s,e),r.kind||(r=i.startState())}return{start:a.getStartOfToken(),end:a.getCurrentPosition(),string:a.current(),state:r,style:s}}const q=(e,t,n,i,r)=>{const s=[];for(const a of e.elements)if(c.isObjectBindingPattern(a.name)){const e=[...t];a.propertyName&&n.includes(a.propertyName.getText())&&!t.includes(a.propertyName.getText())&&e.push(a.propertyName.getText());const o=q(a.name,e,n,i,r);s.push(...o)}else if(c.isIdentifier(a.name)){const e=[...t];a.propertyName&&n.includes(a.propertyName.getText())&&!t.includes(a.propertyName.getText())?e.push(a.propertyName.getText()):e.push(a.name.getText());const o=G(a.name,e,n,i,r);s.push(...o)}return s},G=(e,t,n,i,r)=>{let s=[];const a=r.languageService.getReferencesAtPosition(i.fileName,e.getStart());return a?(s=a.flatMap((s=>{if(s.fileName!==i.fileName)return[];if(e.getStart()<=s.textSpan.start&&e.getEnd()>=s.textSpan.start+s.textSpan.length)return[];let a=y(i,s.textSpan.start);if(!a)return[];const o=[...t];for(;c.isIdentifier(a)||c.isPropertyAccessExpression(a)||c.isElementAccessExpression(a)||c.isVariableDeclaration(a)||c.isBinaryExpression(a);){if(c.isVariableDeclaration(a)){if(c.isIdentifier(a.name))return G(a.name,o,n,i,r);if(c.isObjectBindingPattern(a.name))return q(a.name,o,n,i,r)}else c.isIdentifier(a)&&n.includes(a.text)&&!o.includes(a.text)?o.push(a.text):c.isPropertyAccessExpression(a)&&n.includes(a.name.text)&&!o.includes(a.name.text)?o.push(a.name.text):c.isElementAccessExpression(a)&&c.isStringLiteral(a.argumentExpression)&&n.includes(a.argumentExpression.text)&&!o.includes(a.argumentExpression.text)&&o.push(a.argumentExpression.text);a=a.parent}return o.join(".")})),s):s};function $(t,n){let i=[];return N(t,n.config.template||"gql",n,!1).nodes.forEach((r=>{const s=k(r,t.fileName,n).combinedText;try{const t=e.parse(s,{noLocation:!0});t.definitions.every((t=>t.kind===e.Kind.FRAGMENT_DEFINITION))&&(i=i.concat(t.definitions))}catch(e){return}})),i}const K=new Set(["populate","client","_optional","_required","arguments","argumentDefinitions","connection","refetchable","relay","required","inline"]),_=/Unknown directive "@([^)]+)"/g;let M=!1;const B=new g.LRUCache({ttl:9e5,max:5e3});function z(s){var a;const o=e=>s.project.projectService.logger.info(`[GraphQLSP] ${e}`),l=s.config;if(o("config: "+JSON.stringify(l)),!l.schema)throw o('Missing "schema" option in configuration.'),new Error("Please provide a GraphQL Schema!");o("Setting up the GraphQL Plugin");const g=l.scalars||{},d=l.extraTypes||"",m=null!==(a=l.disableTypegen)&&void 0!==a&&a,z=function(e){const t=Object.create(null);for(let n of Object.keys(e.languageService)){const i=e.languageService[n];t[n]=(...t)=>i.apply(e.languageService,t)}return t}(s),U=s.project.getCurrentDirectory()+"/__generated__/baseGraphQLSP.ts",J=((r,s,a,o,l,c,p)=>{const g={current:null,version:0};let u,d;try{"object"==typeof s?(u=new URL(s.url),d={headers:s.headers}):u=new URL(s)}catch(e){}if(u){const n=()=>{a(`Fetching introspection from ${u.toString()}`),t(u.toString(),{method:"POST",headers:d?{...d.headers||{},"Content-Type":"application/json"}:{"Content-Type":"application/json"},body:JSON.stringify({query:e.getIntrospectionQuery({descriptions:!0,schemaDescription:!1,inputValueDeprecation:!1,directiveIsRepeatable:!1,specifiedByUrl:!1})})}).then((e=>(a(`Got response ${e.statusText} ${e.status}`),e.ok?e.json():e.text()))).then((t=>{if(a(`Got result ${JSON.stringify(t)}`),"string"==typeof t)a(`Got error while fetching introspection ${t}`);else if(t.data)try{g.current=e.buildClientSchema(t.data),g.version=g.version+1,a(`Got schema for ${u.toString()}`),l&&x(g.current,o,c,p)}catch(e){a(`Got schema error for ${e.message}`)}else a(`Got invalid response ${JSON.stringify(t)}`)}))};n(),setInterval((()=>{n()}),6e4)}else if("string"==typeof s){const t=s.endsWith("json"),u=n.resolve(n.dirname(r),s);a(`Getting schema from ${u}`);const d=i.readFileSync(u,"utf-8");i.watchFile(u,(()=>{const n=i.readFileSync(u,"utf-8");g.current=t?e.buildClientSchema(JSON.parse(n)):e.buildSchema(n),g.version=g.version+1,l&&x(g.current,o,c)})),g.current=t?e.buildClientSchema(JSON.parse(d)):e.buildSchema(d),g.version=g.version+1,l&&x(g.current,o,c,p),a(`Got schema and initialized watcher for ${s}`)}return g})(s.project.getProjectName(),l.schema,o,U,!m,g,d);return z.getSemanticDiagnostics=t=>{const a=s.languageService.getSemanticDiagnostics(t),o=function(t,s,a,o,l){var g;const d=l.config.template||"gql",m=null!==(g=l.config.templateIsCallExpression)&&void 0!==g&&g;let x=T(l,s);if(!x)return;let b,I=[];if(m){const e=N(x,d,l);I=e.fragments,b=e.nodes}else b=E(x,d);const D=b.map((e=>{if((c.isNoSubstitutionTemplateLiteral(e)||c.isTemplateExpression(e))&&!m){if(!c.isTaggedTemplateExpression(e.parent))return;e=e.parent}return k(e,s,l).combinedText}));let L=[];const F=u(m?x.getText()+I.map((t=>e.print(t))).join("-")+o.version:D.join("-")+o.version);return B.has(F)?L=B.get(F):(L=((t,{nodes:n,fragments:i},r,s)=>{var a,o;const l=s.config.template||"gql",g=t.fileName,u=null!==(a=s.config.templateIsCallExpression)&&void 0!==a&&a,d=n.map((t=>{let n=t;if(!u&&(c.isNoSubstitutionTemplateLiteral(n)||c.isTemplateExpression(n))){if(!c.isTaggedTemplateExpression(n.parent))return;n=n.parent}const{combinedText:a,resolvedSpans:o}=k(n,g,s),d=a.split("\n");let m=!1;c.isAsExpression(n.parent)?c.isExpressionStatement(n.parent.parent)&&(m=!0):c.isExpressionStatement(n.parent)&&(m=!0);let f=n.pos+(u?0:l.length+(m?2:1));const h=f+n.getText().length;let S=[...i];if(u)try{const t=e.parse(a,{noLocation:!0}).definitions.filter((t=>t.kind===e.Kind.FRAGMENT_DEFINITION));S=S.filter((n=>!t.some((t=>t.kind===e.Kind.FRAGMENT_DEFINITION&&t.name.value===n.name.value))))}catch(e){}const x=p.getDiagnostics(a,r.current,void 0,void 0,S).filter((e=>{if(!e.message.includes("Unknown directive"))return!0;const[t]=e.message.split("("),n=_.exec(t);return!n||!K.has(n[1])})).map((e=>{const{start:t,end:n}=e.range;let i=f+t.line;for(let e=0;e<=t.line;e++)i+=e===t.line?t.character:d[e].length;let r=f+n.line;for(let e=0;e<=n.line;e++)r+=e===n.line?n.character:d[e].length;const s=o.find((e=>i>=e.new.start&&r<=e.new.start+e.new.length));if(s)return{...e,start:s.original.start,length:s.original.length};if(i>h){const t=o.filter((e=>e.new.start+e.new.length<i)).reduce(((e,t)=>e+(t.new.length-t.original.length)),0);return i-=t,r-=t,{...e,start:i+1,length:r-i}}return{...e,start:i+1,length:r-i}})).filter((e=>e.start+e.length<=h));try{const i=e.parse(a,{noLocation:!0});i.definitions.some((t=>t.kind===e.Kind.OPERATION_DEFINITION))&&(i.definitions.find((t=>t.kind===e.Kind.OPERATION_DEFINITION)).name||x.push({message:"Operation needs a name for types to be generated.",start:n.pos,code:52002,length:t.getText().length,range:{},severity:2}))}catch(e){}return x})).flat().filter(Boolean).map((e=>({file:t,length:e.length,start:e.start,category:2===e.severity?c.DiagnosticCategory.Warning:c.DiagnosticCategory.Error,code:"number"==typeof e.code?e.code:2===e.severity?52004:52001,messageText:e.message.split("\n")[0]})));if(u){const i=((t,n,i)=>{var r;const s=[];return null!==(r=i.config.trackFieldUsage)&&void 0!==r&&r?(n.forEach((n=>{const r=n.getText();if(r.includes("mutation")||r.includes("subscription"))return;const a=(e=>{let t=e,n=0;for(;!c.isVariableDeclaration(t)&&t.parent&&n<5;)t=t.parent,n++;return t})(n);if(!c.isVariableDeclaration(a))return;const o=i.languageService.getReferencesAtPosition(t.fileName,a.name.getStart());o&&o.forEach((r=>{if(r.fileName!==t.fileName)return;let o=y(t,r.textSpan.start);for(;o&&!c.isVariableStatement(o);)o=o.parent;if(!o||!c.isVariableStatement(o))return;const[l]=o.declarationList.declarations;if(l.name.getText()===a.name.getText())return;const p=[],g=[],u=[],d=["id","__typename"],m=new Map;e.visit(e.parse(n.getText().slice(1,-1)),{Field:{enter:e=>{if(d.includes(e.name.value)||u.push(e.name.value),e.selectionSet||d.includes(e.name.value))e.selectionSet&&p.push(e.name.value);else{let t;t=p.length?p.join(".")+"."+e.name.value:e.name.value,g.push(t),m.set(t,{start:e.name.loc.start,length:e.name.loc.end-e.name.loc.start})}},leave:e=>{e.selectionSet&&p.pop()}}});let f=l.name;c.isArrayBindingPattern(f)&&c.isBindingElement(f.elements[0])&&(f=f.elements[0].name);let h=[];h=c.isObjectBindingPattern(f)?q(f,[],u,t,i):G(f,[],u,t,i),g.filter((e=>!h.includes(e))).forEach((e=>{const i=m.get(e);i&&s.push({file:t,length:i.length,start:n.getStart()+i.start+1,category:c.DiagnosticCategory.Warning,code:52005,messageText:`Field '${e}' is not used.`})}))}))})),s):s})(t,n,s),r=null!==(o=s.config.shouldCheckForColocatedFragments)&&void 0!==o&&o;let a=[];if(console.log("[GraphhQLSP] Checking for colocated fragments ",!!r),r){const i=((e,t)=>{const n=C(e),i={};return n.length&&n.forEach((n=>{if(n.importClause){if(n.importClause.name){const r=t.languageService.getDefinitionAtPosition(e.fileName,n.importClause.name.getStart());if(r&&r.length){const[e]=r;if(e.fileName.includes("node_modules"))return;const s=T(t,e.fileName);if(!s)return;const a=$(s,t).map((e=>e.name.value));a.length&&!i[n.moduleSpecifier.getText()]?i[n.moduleSpecifier.getText()]={start:n.moduleSpecifier.getStart(),length:n.moduleSpecifier.getText().length,fragments:a}:a.length&&(i[n.moduleSpecifier.getText()].fragments=i[n.moduleSpecifier.getText()].fragments.concat(a))}}if(n.importClause.namedBindings&&c.isNamespaceImport(n.importClause.namedBindings)){const r=t.languageService.getDefinitionAtPosition(e.fileName,n.importClause.namedBindings.getStart());if(r&&r.length){const[e]=r;if(e.fileName.includes("node_modules"))return;const s=T(t,e.fileName);if(!s)return;const a=$(s,t).map((e=>e.name.value));a.length&&!i[n.moduleSpecifier.getText()]?i[n.moduleSpecifier.getText()]={start:n.moduleSpecifier.getStart(),length:n.moduleSpecifier.getText().length,fragments:a}:a.length&&(i[n.moduleSpecifier.getText()].fragments=i[n.moduleSpecifier.getText()].fragments.concat(a))}}else n.importClause.namedBindings&&c.isNamedImportBindings(n.importClause.namedBindings)&&n.importClause.namedBindings.elements.forEach((r=>{const s=t.languageService.getDefinitionAtPosition(e.fileName,r.getStart());if(s&&s.length){const[e]=s;if(e.fileName.includes("node_modules"))return;const r=T(t,e.fileName);if(!r)return;const a=$(r,t).map((e=>e.name.value));a.length&&!i[n.moduleSpecifier.getText()]?i[n.moduleSpecifier.getText()]={start:n.moduleSpecifier.getStart(),length:n.moduleSpecifier.getText().length,fragments:a}:a.length&&(i[n.moduleSpecifier.getText()].fragments=i[n.moduleSpecifier.getText()].fragments.concat(a))}}))}})),i})(t,s);console.log("[GraphhQLSP] Checking for colocated fragments ",JSON.stringify(i,null,2));const r=new Set;n.forEach((t=>{try{const n=e.parse(t.getText().slice(1,-1),{noLocation:!0});e.visit(n,{FragmentSpread:e=>{r.add(e.name.value)}})}catch(e){}})),Object.keys(i).forEach((e=>{const{fragments:n,start:s,length:o}=i[e],l=n.filter((e=>!r.has(e)));l.length&&a.push({file:t,length:o,start:s,category:c.DiagnosticCategory.Warning,code:52003,messageText:`Unused co-located fragment definition(s) "${l.join(", ")}" in ${e}`})}))}return[...d,...i,...a]}{const n=((t,n)=>{var i,r;const s=C(t),a=n.config.template||"gql",o=null!==(i=n.config.shouldCheckForColocatedFragments)&&void 0!==i&&i,l=[];if(s.length&&o){const i=null===(r=n.languageService.getProgram())||void 0===r?void 0:r.getTypeChecker();s.forEach((r=>{var s;if(!r.importClause)return;const o=[];if(r.importClause.name&&o.push(null===(s=r.importClause)||void 0===s?void 0:s.name.text),r.importClause.namedBindings&&c.isNamespaceImport(r.importClause.namedBindings))return;r.importClause.namedBindings&&c.isNamedImportBindings(r.importClause.namedBindings)&&r.importClause.namedBindings.elements.forEach((e=>{o.push(e.name.text)}));const p=null==i?void 0:i.getSymbolAtLocation(r.moduleSpecifier);if(!p)return;const g=null==i?void 0:i.getExportsOfModule(p);if(!g)return;const u=g.map((t=>{if(o.includes(t.name))return;const i=t.getDeclarations(),r=null==i?void 0:i.find((e=>!0));if(!r)return;const[s]=E(r,a);if(s){let i=s;if(c.isNoSubstitutionTemplateLiteral(i)||c.isTemplateExpression(i)){if(!c.isTaggedTemplateExpression(i.parent))return;i=i.parent}const r=k(i,i.getSourceFile().fileName,n).combinedText;try{if(e.parse(r,{noLocation:!0}).definitions.every((t=>t.kind===e.Kind.FRAGMENT_DEFINITION)))return`'${t.name}'`}catch(e){return}}})).filter(Boolean);u.length&&l.push({file:t,length:r.getText().length,start:r.getStart(),category:c.DiagnosticCategory.Message,code:52003,messageText:`Missing Fragment import(s) ${u.join(", ")} from ${r.moduleSpecifier.getText()}.`})}))}return l})(t,s);return[...d,...n]}})(x,{nodes:b,fragments:I},o,l),B.set(F,L)),((t,s,a,o,l,p,g,u)=>{var d;const m=g.fileName,x=u.config.scalars||{},y=null!==(d=u.config.disableTypegen)&&void 0!==d&&d;let E=g;if(!o.filter((e=>e.category===c.DiagnosticCategory.Error||e.category===c.DiagnosticCategory.Warning)).length&&!y)try{if(v(m,E)&&!M)return;M=!0;const o=E.fileName.split("/"),g=o[o.length-1].split(".");g[g.length-1]="generated.ts",o[o.length-1]=g.join("."),(async(t,s,a,o,l)=>{try{if(!t)return{success:!1};const c=s.split("/");c.pop();let p=n.posix.relative(c.join("/"),l).replace(".ts","");"__generated__/baseGraphQLSP"===p&&(p="./"+p);const g={documents:[{location:"operation.graphql",document:e.parse(a)}],config:{scalars:o,avoidOptionals:!1,enumsAsTypes:!0,nonOptionalTypename:!0,namespacedImportName:"Types"},filename:s,schema:e.parse(e.printSchema(t)),plugins:[{"typescript-operations":{}},{"typed-document-node":{}},{add:{content:`import * as Types from "${p}"`}}],pluginMap:{"typescript-operations":f,"typed-document-node":h,add:S}},u=await r.codegen(g);return i.writeFile(n.posix.join(s),u,"utf8",(e=>{console.error(e)})),{success:!0}}catch(e){return{success:!1}}})(a.current,o.join("/"),s.join("\n"),x,p).then((({success:n})=>{if(!n||l)return;if(E=T(u,m),!E||v(m,E))return;let i=0;const r=t.reduce(((t,n,r)=>{var a;if(E=T(u,m),!E)return t;const o=e.parse(s[r]||"",{noLocation:!0}),l=o.definitions.every((t=>t.kind===e.Kind.FRAGMENT_DEFINITION));let p="";if(p=l?o.definitions[0].name.value:(null===(a=o.definitions[0].name)||void 0===a?void 0:a.value)||"",!p)return t;p=p.charAt(0).toUpperCase()+p.slice(1);const d=n.parent.getChildren(),f=l?`${p}FragmentDoc`:`${p}Document`;let h=` as typeof import('./${g.join(".").replace(".ts","")}').${f}\n`;const S=d.find((e=>c.isImportTypeNode(e)));if(S&&S.getText().includes(f))return t;const x={length:1,start:n.end};let v="";if(S){const e=S.getText().split(".").pop();h=h.slice(4),h=h.substring(0,h.length-1);const i=n.getStart();v=t.slice(0,i)+t.slice(i).replace(S.getText(),h),x.length=h.length+((e||"").length-f.length)}else v=t.substring(0,x.start)+h+t.substring(x.start+x.length,t.length);return t=v,i+=h.length,E.hasBeenIncrementallyParsed=!1,E.update(v,{span:x,newLength:h.length}),E.text=v,t}),E.text),a=u.project.projectService.getScriptInfo(m),o=a.getSnapshot();a.editContent(0,o.getLength(),r),u.languageServiceHost.writeFile(E.fileName,r),a.reloadFromFile(),a.registerFileUpdate(),M=!1}))}catch(e){u.project.projectService.getScriptInfo(m).reloadFromFile(),M=!1}})(b,D,o,L,t,a,x,l),L}(a.length>0,t,U,J,s);return o?[...o,...a]:a},z.getCompletionsAtPosition=(t,n,i)=>{const r=function(t,n,i,r){var s;const a=r.config.template||"gql",o=null!==(s=r.config.templateIsCallExpression)&&void 0!==s&&s,l=T(r,t);if(!l)return;let g,u,d=y(l,n);if(!d)return;if(d=o?D(d):I(d),c.isCallExpression(d)&&o&&d.expression.getText()===a&&d.arguments.length>0&&c.isNoSubstitutionTemplateLiteral(d.arguments[0])){const s=F(d.arguments[0],n);if(!i.current||!s)return;g=`${d.arguments[0].getText().slice(1,-1)}\n${b(t,d,r).map((t=>e.print(t))).join("\n")}`,u=new L(s.line,s.start-1)}else{if(!c.isTaggedTemplateExpression(d))return;{const{template:e,tag:s}=d;if(!c.isIdentifier(s)||s.text!==a)return;const o=F(e,n);if(!o||!i.current)return;const{combinedText:l,resolvedSpans:p}=k(d,t,r),m=p.filter((e=>e.original.start<n&&e.original.start+e.original.length<n)).reduce(((e,t)=>e+(t.lines-1)),0);o.line=o.line+m,g=l,u=new L(o.line,o.start-1)}}const[m,f]=function(t,n,i){var r;const s=p.getTokenAtPosition(n,i);let a=[];try{a=e.parse(n,{noLocation:!0}).definitions.filter((t=>t.kind===e.Kind.FRAGMENT_DEFINITION))}catch(e){console.log("[GraphQLSP] ",e)}console.log("fraggers",a.map((t=>e.print(t))).join("\n"));let o=p.getAutocompleteSuggestions(t,n,i),l=function(t,n,i,r,s){if(!r)return[];const a=i.getTypeMap(),o=p.getDefinitionState(t.state);return function(e,t){return function(e,t){return t?O(O(e.map((e=>({proximity:j(A(e.label),t),entry:e}))),(e=>e.proximity<=2)),(e=>!e.entry.isDeprecated)).sort(((e,t)=>(e.entry.isDeprecated?1:0)-(t.entry.isDeprecated?1:0)||e.proximity-t.proximity||e.entry.label.length-t.entry.label.length)).map((e=>e.entry)):O(e,(e=>!e.isDeprecated))}(t,A(e.string))}(t,s.filter((t=>a[t.typeCondition.name.value]&&!(o&&o.kind===p.RuleKinds.FRAGMENT_DEFINITION&&o.name===t.name.value)&&e.isCompositeType(n.parentType)&&e.isCompositeType(a[t.typeCondition.name.value])&&e.doTypesOverlap(i,n.parentType,a[t.typeCondition.name.value]))).map((e=>({label:e.name.value,detail:String(a[e.typeCondition.name.value]),documentation:`fragment ${e.name.value} on ${e.typeCondition.name.value}`,kind:p.CompletionItemKind.Field,type:a[e.typeCondition.name.value]}))))}(s,p.getTypeInfo(t,s.state),t,n,a);console.log(JSON.stringify(l,null,2));const c="Invalid"===s.state.kind?s.state.prevState:s.state,g=null===(r=w(s.state,p.RuleKinds.FIELD))||void 0===r?void 0:r.name;if(c&&g){const{kind:e}=c;if(e===p.RuleKinds.ARGUMENTS||e===p.RuleKinds.ARGUMENT){const e=new Set;R(n,((t,n)=>{if(n.kind===p.RuleKinds.ARGUMENT){const t=w(n,p.RuleKinds.FIELD);g&&n.name&&(null==t?void 0:t.name)===g&&e.add(n.name)}})),o=o.filter((t=>!e.has(t.label)))}if(e===p.RuleKinds.SELECTION_SET||e===p.RuleKinds.FIELD||e===p.RuleKinds.ALIASED_FIELD){const e=new Set,t=P(n,g);R(n,((t,n)=>{if(n.kind===p.RuleKinds.FIELD||n.kind===p.RuleKinds.ALIASED_FIELD){const t=w(n,p.RuleKinds.FIELD);t&&t.name===g&&n.name&&e.add(n.name)}})),o=o.filter((t=>!e.has(t.label))),l=l.filter((e=>!t.has(e.label)))}if(e===p.RuleKinds.FRAGMENT_SPREAD){const e=P(n,g);o=o.filter((t=>!e.has(t.label))),l=l.filter((t=>!e.has(t.label)))}}return[o,l]}(i.current,g,u);return{isGlobalCompletion:!1,isMemberCompletion:!1,isNewIdentifierLocation:!1,entries:[...m.map((e=>{var t;return{...e,kind:c.ScriptElementKind.variableElement,name:e.label,kindModifiers:"declare",sortText:e.sortText||"0",labelDetails:{detail:e.type?" "+(null===(t=e.type)||void 0===t?void 0:t.toString()):void 0,description:e.documentation}}})),...f.map((e=>({...e,kind:c.ScriptElementKind.variableElement,name:e.label,insertText:"..."+e.label,kindModifiers:"declare",sortText:"0",labelDetails:{description:e.documentation}})))]}}(t,n,J,s);return r&&r.entries.length?r:s.languageService.getCompletionsAtPosition(t,n,i)||{isGlobalCompletion:!1,isMemberCompletion:!1,isNewIdentifierLocation:!1,entries:[]}},z.getQuickInfoAtPosition=(e,t)=>{const n=function(e,t,n,i){var r;const s=i.config.template||"gql",a=null!==(r=i.config.templateIsCallExpression)&&void 0!==r&&r,o=T(i,e);if(!o)return;let l,g,u=y(o,t);if(!u)return;if(u=a?D(u):I(u),c.isCallExpression(u)&&a&&u.expression.getText()===s&&u.arguments.length>0&&c.isNoSubstitutionTemplateLiteral(u.arguments[0])){const e=F(u.arguments[0],t);if(!n.current||!e)return;g=u.arguments[0].getText(),l=new L(e.line,e.start-1)}else{if(!c.isTaggedTemplateExpression(u))return;{const{template:r,tag:a}=u;if(!c.isIdentifier(a)||a.text!==s)return;const o=F(r,t);if(!o||!n.current)return;const{combinedText:p,resolvedSpans:d}=k(u,e,i),m=d.filter((e=>e.original.start<t&&e.original.start+e.original.length<t)).reduce(((e,t)=>e+(t.lines-1)),0);o.line=o.line+m,g=p,l=new L(o.line,o.start-1)}}const d=p.getHoverInformation(n.current,g,l);return{kind:c.ScriptElementKind.label,textSpan:{start:t,length:1},kindModifiers:"text",documentation:Array.isArray(d)?d.map((e=>({kind:"text",text:e}))):[{kind:"text",text:d}]}}(e,t,J,s);return n||s.languageService.getQuickInfoAtPosition(e,t)},o("proxy: "+JSON.stringify(z)),z}module.exports=()=>({create:z});
"use strict";var e=require("graphql"),t=require("node-fetch"),n=require("path"),i=require("fs"),r=require("@graphql-codegen/core"),s=require("@graphql-codegen/typescript"),a=require("@graphql-codegen/typescript-operations"),o=require("@graphql-codegen/typed-document-node"),l=require("@graphql-codegen/add"),c=require("typescript/lib/tsserverlibrary"),p=require("graphql-language-service"),g=require("lru-cache"),u=require("@sindresorhus/fnv1a");function d(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,i.get?i:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var m=d(s),f=d(a),h=d(o),S=d(l);const x=async(t,s,a,o)=>{if(!t)return;const l={documents:[],config:{scalars:a,avoidOptionals:!1,enumsAsTypes:!0,globalNamespace:!0,nonOptionalTypename:!0},filename:s,schema:e.parse(e.printSchema(t)),plugins:[{typescript:{}},o&&{add:{content:o}}].filter(Boolean),pluginMap:o?{typescript:m,add:S}:{typescript:m}},c=await r.codegen(l);let p=s.split("/");p.pop();const g=n.posix.join(p.join("/"));i.existsSync(g)||i.mkdirSync(g),i.writeFile(n.posix.join(s),c,"utf8",(e=>{console.error(e)}))};function v(e,t){const n=i.readFileSync(e,"utf-8");return t.getFullText()!==n}function T(e,t){const n=e.languageService.getProgram();if(n)return n.getSourceFile(t)||void 0}function y(e,t){return function e(n){if(t>=n.getStart()&&t<n.getEnd())return c.forEachChild(n,e)||n}(e)}function E(e,t){const n=[];return function e(i){c.isTaggedTemplateExpression(i)&&i.tag.getText()===t||c.isNoSubstitutionTemplateLiteral(i)&&c.isTaggedTemplateExpression(i.parent)&&i.parent.tag.getText()===t?n.push(i):c.forEachChild(i,e)}(e),n}function N(t,n,i){const r=[],s=i.languageService.getDefinitionAtPosition(t.getSourceFile().fileName,t.getStart());if(!s)return r;const[a]=s,o=T(i,a.fileName);if(!o)return r;let l=y(o,a.textSpan.start);if(!l)return r;if(c.isVariableDeclaration(l.parent)&&l.parent.initializer&&c.isCallExpression(l.parent.initializer)&&(l=l.parent.initializer),c.isCallExpression(l)&&l.expression.getText()===n){const[t,s]=l.arguments;s&&c.isArrayLiteralExpression(s)&&s.elements.forEach((e=>{c.isIdentifier(e)&&r.push(...N(e,n,i))}));try{e.parse(t.getText().slice(1,-1),{noLocation:!0}).definitions.forEach((e=>{"FragmentDefinition"===e.kind&&r.push(e)}))}catch(e){}}return r}function b(e,t,n,i=!0){const r=[];let s=[],a=!i;return function i(o){if(c.isCallExpression(o)&&o.expression.getText()===t){const[i,l]=o.arguments;return a||l?l&&c.isArrayLiteralExpression(l)&&l.elements.forEach((e=>{c.isIdentifier(e)&&s.push(...N(e,t,n))})):(a=!0,s=C(e.fileName,o,n)),void(i&&c.isNoSubstitutionTemplateLiteral(i)&&r.push(i))}c.forEachChild(o,i)}(e),{nodes:r,fragments:s}}function C(t,n,i){const r=i.config.template||"gql";let s=[];const a=i.languageService.getDefinitionAtPosition(t,n.expression.getStart());if(!a)return s;if(n.arguments[1]&&c.isArrayLiteralExpression(n.arguments[1]))return n.arguments[1].elements.forEach((e=>{c.isIdentifier(e)&&s.push(...N(e,r,i))})),s;const o=T(i,a[0].fileName);return o?(c.forEachChild(o,(t=>{if(c.isVariableStatement(t)&&t.declarationList&&"documents"===t.declarationList.declarations[0].name.getText()){const[n]=t.declarationList.declarations;n.initializer&&c.isObjectLiteralExpression(n.initializer)&&n.initializer.properties.forEach((t=>{if(c.isPropertyAssignment(t)&&c.isStringLiteral(t.name))try{const n=JSON.parse(`${t.name.getText().replace(/'/g,'"')}`);n.includes("fragment ")&&n.includes(" on ")&&e.parse(n,{noLocation:!0}).definitions.forEach((e=>{"FragmentDefinition"===e.kind&&s.push(e)}))}catch(e){}}))}})),s):s}function I(e){return e.statements.filter(c.isImportDeclaration)}function D(e){for(;c.isNoSubstitutionTemplateLiteral(e)||c.isToken(e)||c.isTemplateExpression(e)||c.isTemplateSpan(e);)e=e.parent;return e}function L(e){for(;c.isNoSubstitutionTemplateLiteral(e)||c.isToken(e)||c.isTemplateExpression(e)||c.isTemplateSpan(e);)e=e.parent;return e}class A{constructor(e,t){this.line=e,this.character=t}setLine(e){this.line=e}setCharacter(e){this.character=e}lessThanOrEqualTo(e){return this.line<e.line||this.line===e.line&&this.character<=e.character}}function F(t,n,i){if(c.isNoSubstitutionTemplateLiteral(t))return{combinedText:t.getText().slice(1,-1),resolvedSpans:[]};let r=t.template.getText().slice(1,-1);if(c.isNoSubstitutionTemplateLiteral(t.template)||0===t.template.templateSpans.length)return{combinedText:r,resolvedSpans:[]};let s=0;const a=t.template.templateSpans.map((t=>{if(c.isIdentifier(t.expression)){const a=i.languageService.getDefinitionAtPosition(n,t.expression.getStart());if(!a)return;const o=a[0],l=T(i,o.fileName);if(!l)return;const p=y(l,o.textSpan.start);if(!p||!p.parent)return;const g=p.parent;if(c.isVariableDeclaration(g)){const n=t.expression.escapedText,a=t.expression.getStart()-2,l={start:a,length:t.expression.end-a+1};if(g.initializer&&c.isTaggedTemplateExpression(g.initializer)){const e=F(g.initializer,o.fileName,i);r=r.replace("${"+t.expression.escapedText+"}",e.combinedText);const a={lines:e.combinedText.split("\n").length,identifier:n,original:l,new:{start:l.start+s,length:e.combinedText.length}};return s+=e.combinedText.length-l.length,a}if(g.initializer&&c.isAsExpression(g.initializer)&&c.isTaggedTemplateExpression(g.initializer.expression)){const e=F(g.initializer.expression,o.fileName,i);r=r.replace("${"+t.expression.escapedText+"}",e.combinedText);const a={lines:e.combinedText.split("\n").length,identifier:n,original:l,new:{start:l.start+s,length:e.combinedText.length}};return s+=e.combinedText.length-l.length,a}if(g.initializer&&c.isAsExpression(g.initializer)&&c.isAsExpression(g.initializer.expression)&&c.isObjectLiteralExpression(g.initializer.expression.expression)){const i=JSON.parse(g.initializer.expression.expression.getText()),a=e.print(i);r=r.replace("${"+t.expression.escapedText+"}",a);const o={lines:a.split("\n").length,identifier:n,original:l,new:{start:l.start+s,length:a.length}};return s+=a.length-l.length,o}return}}})).filter(Boolean);return{combinedText:r,resolvedSpans:a}}const k=(e,t)=>{const n=e.getText().slice(1,-1).split("\n"),i=p.onlineParser(),r=i.startState();let s,a=e.pos+1;for(let e=0;e<n.length;e++){const o=a-1,l=new p.CharacterStream(n[e]);for(;!l.eol();){const n=i.token(l,r),a=l.current();if(a&&o+l.getStartOfToken()<=t&&o+l.getCurrentPosition()>=t){s={line:e,start:l.getStartOfToken()+1,end:l.getCurrentPosition(),string:a,state:r,tokenKind:n};break}}a+=n[e].length+1}return s};function O(e,t){const n=e.filter(t);return 0===n.length?e:n}function j(e){return e.toLowerCase().replace(/\W/g,"")}function w(e,t){let n=function(e,t){let n,i;const r=[],s=e.length,a=t.length;for(n=0;n<=s;n++)r[n]=[n];for(i=1;i<=a;i++)r[0][i]=i;for(n=1;n<=s;n++)for(i=1;i<=a;i++){const s=e[n-1]===t[i-1]?0:1;r[n][i]=Math.min(r[n-1][i]+1,r[n][i-1]+1,r[n-1][i-1]+s),n>1&&i>1&&e[n-1]===t[i-2]&&e[n-2]===t[i-1]&&(r[n][i]=Math.min(r[n][i],r[n-2][i-2]+s))}return r[s][a]}(t,e);return e.length>t.length&&(n-=e.length-t.length-1,n+=0===e.indexOf(t)?0:.5),n}function P(e,t){const n=new Set;return q(e,((e,i)=>{if(i.kind===p.RuleKinds.FRAGMENT_SPREAD&&i.name){const e=R(i,p.RuleKinds.FIELD);t&&(null==e?void 0:e.name)===t&&n.add(i.name)}})),n}function R(e,t){var n,i,r,s,a,o,l,c,p,g;return(null===(n=e.prevState)||void 0===n?void 0:n.kind)===t?e.prevState:(null===(r=null===(i=e.prevState)||void 0===i?void 0:i.prevState)||void 0===r?void 0:r.kind)===t?e.prevState.prevState:(null===(o=null===(a=null===(s=e.prevState)||void 0===s?void 0:s.prevState)||void 0===a?void 0:a.prevState)||void 0===o?void 0:o.kind)===t?e.prevState.prevState.prevState:(null===(g=null===(p=null===(c=null===(l=e.prevState)||void 0===l?void 0:l.prevState)||void 0===c?void 0:c.prevState)||void 0===p?void 0:p.prevState)||void 0===g?void 0:g.kind)===t?e.prevState.prevState.prevState.prevState:void 0}function q(e,t){const n=e.split("\n"),i=p.onlineParser();let r=i.startState(),s="",a=new p.CharacterStream("");for(let e=0;e<n.length;e++){for(a=new p.CharacterStream(n[e]);!a.eol()&&(s=i.token(a,r),"BREAK"!==t(a,r,s,e)););t(a,r,s,e),r.kind||(r=i.startState())}return{start:a.getStartOfToken(),end:a.getCurrentPosition(),string:a.current(),state:r,style:s}}const $=(e,t,n,i,r)=>{const s=[];for(const a of e.elements)if(c.isObjectBindingPattern(a.name)){const e=[...t];a.propertyName&&n.includes(a.propertyName.getText())&&!t.includes(a.propertyName.getText())&&e.push(a.propertyName.getText());const o=$(a.name,e,n,i,r);s.push(...o)}else if(c.isIdentifier(a.name)){const e=[...t];a.propertyName&&n.includes(a.propertyName.getText())&&!t.includes(a.propertyName.getText())?e.push(a.propertyName.getText()):e.push(a.name.getText());const o=G(a.name,e,n,i,r);s.push(...o)}return s},G=(e,t,n,i,r)=>{let s=[];const a=r.languageService.getReferencesAtPosition(i.fileName,e.getStart());return a?(s=a.flatMap((s=>{if(s.fileName!==i.fileName)return[];if(e.getStart()<=s.textSpan.start&&e.getEnd()>=s.textSpan.start+s.textSpan.length)return[];let a=y(i,s.textSpan.start);if(!a)return[];const o=[...t];for(;c.isIdentifier(a)||c.isPropertyAccessExpression(a)||c.isElementAccessExpression(a)||c.isVariableDeclaration(a)||c.isBinaryExpression(a);){if(c.isVariableDeclaration(a)){if(c.isIdentifier(a.name))return G(a.name,o,n,i,r);if(c.isObjectBindingPattern(a.name))return $(a.name,o,n,i,r)}else c.isIdentifier(a)&&n.includes(a.text)&&!o.includes(a.text)?o.push(a.text):c.isPropertyAccessExpression(a)&&n.includes(a.name.text)&&!o.includes(a.name.text)?o.push(a.name.text):c.isElementAccessExpression(a)&&c.isStringLiteral(a.argumentExpression)&&n.includes(a.argumentExpression.text)&&!o.includes(a.argumentExpression.text)&&o.push(a.argumentExpression.text);a=a.parent}return o.join(".")})),s):s};function K(t,n){let i=[];return b(t,n.config.template||"gql",n,!1).nodes.forEach((r=>{const s=F(r,t.fileName,n).combinedText;try{const t=e.parse(s,{noLocation:!0});t.definitions.every((t=>t.kind===e.Kind.FRAGMENT_DEFINITION))&&(i=i.concat(t.definitions))}catch(e){return}})),i}const _=new Set(["populate","client","_optional","_required","arguments","argumentDefinitions","connection","refetchable","relay","required","inline"]),M=/Unknown directive "@([^)]+)"/g;let B=!1;const z=new g.LRUCache({ttl:9e5,max:5e3});function U(s){var a;const o=e=>s.project.projectService.logger.info(`[GraphQLSP] ${e}`),l=s.config;if(o("config: "+JSON.stringify(l)),!l.schema)throw o('Missing "schema" option in configuration.'),new Error("Please provide a GraphQL Schema!");o("Setting up the GraphQL Plugin");const g=l.scalars||{},d=l.extraTypes||"",m=null!==(a=l.disableTypegen)&&void 0!==a&&a,N=function(e){const t=Object.create(null);for(let n of Object.keys(e.languageService)){const i=e.languageService[n];t[n]=(...t)=>i.apply(e.languageService,t)}return t}(s),U=s.project.getCurrentDirectory()+"/__generated__/baseGraphQLSP.ts",J=((r,s,a,o,l,c,p)=>{const g={current:null,version:0};let u,d;try{"object"==typeof s?(u=new URL(s.url),d={headers:s.headers}):u=new URL(s)}catch(e){}if(u){const n=()=>{a(`Fetching introspection from ${u.toString()}`),t(u.toString(),{method:"POST",headers:d?{...d.headers||{},"Content-Type":"application/json"}:{"Content-Type":"application/json"},body:JSON.stringify({query:e.getIntrospectionQuery({descriptions:!0,schemaDescription:!1,inputValueDeprecation:!1,directiveIsRepeatable:!1,specifiedByUrl:!1})})}).then((e=>(a(`Got response ${e.statusText} ${e.status}`),e.ok?e.json():e.text()))).then((t=>{if(a(`Got result ${JSON.stringify(t)}`),"string"==typeof t)a(`Got error while fetching introspection ${t}`);else if(t.data)try{g.current=e.buildClientSchema(t.data),g.version=g.version+1,a(`Got schema for ${u.toString()}`),l&&x(g.current,o,c,p)}catch(e){a(`Got schema error for ${e.message}`)}else a(`Got invalid response ${JSON.stringify(t)}`)}))};n(),setInterval((()=>{n()}),6e4)}else if("string"==typeof s){const t=s.endsWith("json"),u=n.resolve(n.dirname(r),s);a(`Getting schema from ${u}`);const d=i.readFileSync(u,"utf-8");i.watchFile(u,(()=>{const n=i.readFileSync(u,"utf-8");g.current=t?e.buildClientSchema(JSON.parse(n)):e.buildSchema(n),g.version=g.version+1,l&&x(g.current,o,c)})),g.current=t?e.buildClientSchema(JSON.parse(d)):e.buildSchema(d),g.version=g.version+1,l&&x(g.current,o,c,p),a(`Got schema and initialized watcher for ${s}`)}return g})(s.project.getProjectName(),l.schema,o,U,!m,g,d);return N.getSemanticDiagnostics=t=>{const a=s.languageService.getSemanticDiagnostics(t),o=function(t,s,a,o,l){var g;const d=l.config.template||"gql",m=null!==(g=l.config.templateIsCallExpression)&&void 0!==g&&g;let x=T(l,s);if(!x)return;let N,C=[];if(m){const e=b(x,d,l);C=e.fragments,N=e.nodes}else N=E(x,d);const D=N.map((e=>{if((c.isNoSubstitutionTemplateLiteral(e)||c.isTemplateExpression(e))&&!m){if(!c.isTaggedTemplateExpression(e.parent))return;e=e.parent}return F(e,s,l).combinedText}));let L=[];const A=u(m?x.getText()+C.map((t=>e.print(t))).join("-")+o.version:D.join("-")+o.version);return z.has(A)?L=z.get(A):(L=((t,{nodes:n,fragments:i},r,s)=>{var a,o;const l=s.config.template||"gql",g=t.fileName,u=null!==(a=s.config.templateIsCallExpression)&&void 0!==a&&a,d=n.map((t=>{let n=t;if(!u&&(c.isNoSubstitutionTemplateLiteral(n)||c.isTemplateExpression(n))){if(!c.isTaggedTemplateExpression(n.parent))return;n=n.parent}const{combinedText:a,resolvedSpans:o}=F(n,g,s),d=a.split("\n");let m=!1;c.isAsExpression(n.parent)?c.isExpressionStatement(n.parent.parent)&&(m=!0):c.isExpressionStatement(n.parent)&&(m=!0);let f=n.pos+(u?0:l.length+(m?2:1));const h=f+n.getText().length;let S=[...i];if(u)try{const t=e.parse(a,{noLocation:!0}).definitions.filter((t=>t.kind===e.Kind.FRAGMENT_DEFINITION));S=S.filter((n=>!t.some((t=>t.kind===e.Kind.FRAGMENT_DEFINITION&&t.name.value===n.name.value))))}catch(e){}const x=p.getDiagnostics(a,r.current,void 0,void 0,S).filter((e=>{if(!e.message.includes("Unknown directive"))return!0;const[t]=e.message.split("("),n=M.exec(t);return!n||!_.has(n[1])})).map((e=>{const{start:t,end:n}=e.range;let i=f+t.line;for(let e=0;e<=t.line;e++)i+=e===t.line?t.character:d[e].length;let r=f+n.line;for(let e=0;e<=n.line;e++)r+=e===n.line?n.character:d[e].length;const s=o.find((e=>i>=e.new.start&&r<=e.new.start+e.new.length));if(s)return{...e,start:s.original.start,length:s.original.length};if(i>h){const t=o.filter((e=>e.new.start+e.new.length<i)).reduce(((e,t)=>e+(t.new.length-t.original.length)),0);return i-=t,r-=t,{...e,start:i+1,length:r-i}}return{...e,start:i+1,length:r-i}})).filter((e=>e.start+e.length<=h));try{const i=e.parse(a,{noLocation:!0});i.definitions.some((t=>t.kind===e.Kind.OPERATION_DEFINITION))&&(i.definitions.find((t=>t.kind===e.Kind.OPERATION_DEFINITION)).name||x.push({message:"Operation needs a name for types to be generated.",start:n.pos,code:52002,length:t.getText().length,range:{},severity:2}))}catch(e){}return x})).flat().filter(Boolean).map((e=>({file:t,length:e.length,start:e.start,category:2===e.severity?c.DiagnosticCategory.Warning:c.DiagnosticCategory.Error,code:"number"==typeof e.code?e.code:2===e.severity?52004:52001,messageText:e.message.split("\n")[0]})));if(u){const i=((t,n,i)=>{var r;const s=[];return null!==(r=i.config.trackFieldUsage)&&void 0!==r&&r?(n.forEach((n=>{const r=n.getText();if(r.includes("mutation")||r.includes("subscription"))return;const a=(e=>{let t=e,n=0;for(;!c.isVariableDeclaration(t)&&t.parent&&n<5;)t=t.parent,n++;return t})(n);if(!c.isVariableDeclaration(a))return;const o=i.languageService.getReferencesAtPosition(t.fileName,a.name.getStart());o&&o.forEach((r=>{if(r.fileName!==t.fileName)return;let o=y(t,r.textSpan.start);for(;o&&!c.isVariableStatement(o);)o=o.parent;if(!o||!c.isVariableStatement(o))return;const[l]=o.declarationList.declarations;if(l.name.getText()===a.name.getText())return;const p=[],g=[],u=[],d=["id","__typename"],m=new Map;e.visit(e.parse(n.getText().slice(1,-1)),{Field:{enter:e=>{if(d.includes(e.name.value)||u.push(e.name.value),e.selectionSet||d.includes(e.name.value))e.selectionSet&&p.push(e.name.value);else{let t;t=p.length?p.join(".")+"."+e.name.value:e.name.value,g.push(t),m.set(t,{start:e.name.loc.start,length:e.name.loc.end-e.name.loc.start})}},leave:e=>{e.selectionSet&&p.pop()}}});let f=l.name;c.isArrayBindingPattern(f)&&c.isBindingElement(f.elements[0])&&(f=f.elements[0].name);let h=[];h=c.isObjectBindingPattern(f)?$(f,[],u,t,i):G(f,[],u,t,i),g.filter((e=>!h.includes(e))).forEach((e=>{const i=m.get(e);i&&s.push({file:t,length:i.length,start:n.getStart()+i.start+1,category:c.DiagnosticCategory.Warning,code:52005,messageText:`Field '${e}' is not used.`})}))}))})),s):s})(t,n,s),r=null!==(o=s.config.shouldCheckForColocatedFragments)&&void 0!==o&&o;let a=[];if(console.log("[GraphhQLSP] Checking for colocated fragments ",!!r),r){const i=((e,t)=>{const n=I(e),i={};return n.length&&n.forEach((n=>{if(n.importClause){if(n.importClause.name){const r=t.languageService.getDefinitionAtPosition(e.fileName,n.importClause.name.getStart());if(r&&r.length){const[e]=r;if(e.fileName.includes("node_modules"))return;const s=T(t,e.fileName);if(!s)return;const a=K(s,t).map((e=>e.name.value));a.length&&!i[n.moduleSpecifier.getText()]?i[n.moduleSpecifier.getText()]={start:n.moduleSpecifier.getStart(),length:n.moduleSpecifier.getText().length,fragments:a}:a.length&&(i[n.moduleSpecifier.getText()].fragments=i[n.moduleSpecifier.getText()].fragments.concat(a))}}if(n.importClause.namedBindings&&c.isNamespaceImport(n.importClause.namedBindings)){const r=t.languageService.getDefinitionAtPosition(e.fileName,n.importClause.namedBindings.getStart());if(r&&r.length){const[e]=r;if(e.fileName.includes("node_modules"))return;const s=T(t,e.fileName);if(!s)return;const a=K(s,t).map((e=>e.name.value));a.length&&!i[n.moduleSpecifier.getText()]?i[n.moduleSpecifier.getText()]={start:n.moduleSpecifier.getStart(),length:n.moduleSpecifier.getText().length,fragments:a}:a.length&&(i[n.moduleSpecifier.getText()].fragments=i[n.moduleSpecifier.getText()].fragments.concat(a))}}else n.importClause.namedBindings&&c.isNamedImportBindings(n.importClause.namedBindings)&&n.importClause.namedBindings.elements.forEach((r=>{const s=t.languageService.getDefinitionAtPosition(e.fileName,r.getStart());if(s&&s.length){const[e]=s;if(e.fileName.includes("node_modules"))return;const r=T(t,e.fileName);if(!r)return;const a=K(r,t).map((e=>e.name.value));a.length&&!i[n.moduleSpecifier.getText()]?i[n.moduleSpecifier.getText()]={start:n.moduleSpecifier.getStart(),length:n.moduleSpecifier.getText().length,fragments:a}:a.length&&(i[n.moduleSpecifier.getText()].fragments=i[n.moduleSpecifier.getText()].fragments.concat(a))}}))}})),i})(t,s),r=new Set;n.forEach((t=>{try{const n=e.parse(t.getText().slice(1,-1),{noLocation:!0});e.visit(n,{FragmentSpread:e=>{r.add(e.name.value)}})}catch(e){}})),Object.keys(i).forEach((e=>{const{fragments:n,start:s,length:o}=i[e],l=Array.from(new Set(n.filter((e=>!r.has(e)))));l.length&&a.push({file:t,length:o,start:s,category:c.DiagnosticCategory.Warning,code:52003,messageText:`Unused co-located fragment definition(s) "${l.join(", ")}" in ${e}`})}))}return[...d,...i,...a]}{const n=((t,n)=>{var i,r;const s=I(t),a=n.config.template||"gql",o=null!==(i=n.config.shouldCheckForColocatedFragments)&&void 0!==i&&i,l=[];if(s.length&&o){const i=null===(r=n.languageService.getProgram())||void 0===r?void 0:r.getTypeChecker();s.forEach((r=>{var s;if(!r.importClause)return;const o=[];if(r.importClause.name&&o.push(null===(s=r.importClause)||void 0===s?void 0:s.name.text),r.importClause.namedBindings&&c.isNamespaceImport(r.importClause.namedBindings))return;r.importClause.namedBindings&&c.isNamedImportBindings(r.importClause.namedBindings)&&r.importClause.namedBindings.elements.forEach((e=>{o.push(e.name.text)}));const p=null==i?void 0:i.getSymbolAtLocation(r.moduleSpecifier);if(!p)return;const g=null==i?void 0:i.getExportsOfModule(p);if(!g)return;const u=new Set;g.forEach((t=>{if(o.includes(t.name))return;const i=t.getDeclarations(),r=null==i?void 0:i.find((e=>!0));if(!r)return;const[s]=E(r,a);if(s){let i=s;if(c.isNoSubstitutionTemplateLiteral(i)||c.isTemplateExpression(i)){if(!c.isTaggedTemplateExpression(i.parent))return;i=i.parent}const r=F(i,i.getSourceFile().fileName,n).combinedText;try{e.parse(r,{noLocation:!0}).definitions.every((t=>t.kind===e.Kind.FRAGMENT_DEFINITION))&&u.add(`'${t.name}'`)}catch(e){return}}}));const d=Array.from(u);d.length&&l.push({file:t,length:r.getText().length,start:r.getStart(),category:c.DiagnosticCategory.Message,code:52003,messageText:`Missing Fragment import(s) ${d.join(", ")} from ${r.moduleSpecifier.getText()}.`})}))}return l})(t,s);return[...d,...n]}})(x,{nodes:N,fragments:C},o,l),z.set(A,L)),((t,s,a,o,l,p,g,u)=>{var d;const m=g.fileName,x=u.config.scalars||{},y=null!==(d=u.config.disableTypegen)&&void 0!==d&&d;let E=g;if(!o.filter((e=>e.category===c.DiagnosticCategory.Error||e.category===c.DiagnosticCategory.Warning)).length&&!y)try{if(v(m,E)&&!B)return;B=!0;const o=E.fileName.split("/"),g=o[o.length-1].split(".");g[g.length-1]="generated.ts",o[o.length-1]=g.join("."),(async(t,s,a,o,l)=>{try{if(!t)return{success:!1};const c=s.split("/");c.pop();let p=n.posix.relative(c.join("/"),l).replace(".ts","");"__generated__/baseGraphQLSP"===p&&(p="./"+p);const g={documents:[{location:"operation.graphql",document:e.parse(a)}],config:{scalars:o,avoidOptionals:!1,enumsAsTypes:!0,nonOptionalTypename:!0,namespacedImportName:"Types"},filename:s,schema:e.parse(e.printSchema(t)),plugins:[{"typescript-operations":{}},{"typed-document-node":{}},{add:{content:`import * as Types from "${p}"`}}],pluginMap:{"typescript-operations":f,"typed-document-node":h,add:S}},u=await r.codegen(g);return i.writeFile(n.posix.join(s),u,"utf8",(e=>{console.error(e)})),{success:!0}}catch(e){return{success:!1}}})(a.current,o.join("/"),s.join("\n"),x,p).then((({success:n})=>{if(!n||l)return;if(E=T(u,m),!E||v(m,E))return;let i=0;const r=t.reduce(((t,n,r)=>{var a;if(E=T(u,m),!E)return t;const o=e.parse(s[r]||"",{noLocation:!0}),l=o.definitions.every((t=>t.kind===e.Kind.FRAGMENT_DEFINITION));let p="";if(p=l?o.definitions[0].name.value:(null===(a=o.definitions[0].name)||void 0===a?void 0:a.value)||"",!p)return t;p=p.charAt(0).toUpperCase()+p.slice(1);const d=n.parent.getChildren(),f=l?`${p}FragmentDoc`:`${p}Document`;let h=` as typeof import('./${g.join(".").replace(".ts","")}').${f}\n`;const S=d.find((e=>c.isImportTypeNode(e)));if(S&&S.getText().includes(f))return t;const x={length:1,start:n.end};let v="";if(S){const e=S.getText().split(".").pop();h=h.slice(4),h=h.substring(0,h.length-1);const i=n.getStart();v=t.slice(0,i)+t.slice(i).replace(S.getText(),h),x.length=h.length+((e||"").length-f.length)}else v=t.substring(0,x.start)+h+t.substring(x.start+x.length,t.length);return t=v,i+=h.length,E.hasBeenIncrementallyParsed=!1,E.update(v,{span:x,newLength:h.length}),E.text=v,t}),E.text),a=u.project.projectService.getScriptInfo(m),o=a.getSnapshot();a.editContent(0,o.getLength(),r),u.languageServiceHost.writeFile(E.fileName,r),a.reloadFromFile(),a.registerFileUpdate(),B=!1}))}catch(e){u.project.projectService.getScriptInfo(m).reloadFromFile(),B=!1}})(N,D,o,L,t,a,x,l),L}(a.length>0,t,U,J,s);return o?[...o,...a]:a},N.getCompletionsAtPosition=(t,n,i)=>{const r=function(t,n,i,r){var s;const a=r.config.template||"gql",o=null!==(s=r.config.templateIsCallExpression)&&void 0!==s&&s,l=T(r,t);if(!l)return;let g,u,d=y(l,n);if(!d)return;if(d=o?L(d):D(d),c.isCallExpression(d)&&o&&d.expression.getText()===a&&d.arguments.length>0&&c.isNoSubstitutionTemplateLiteral(d.arguments[0])){const s=k(d.arguments[0],n);if(!i.current||!s)return;g=`${d.arguments[0].getText().slice(1,-1)}\n${C(t,d,r).map((t=>e.print(t))).join("\n")}`,u=new A(s.line,s.start-1)}else{if(!c.isTaggedTemplateExpression(d))return;{const{template:e,tag:s}=d;if(!c.isIdentifier(s)||s.text!==a)return;const o=k(e,n);if(!o||!i.current)return;const{combinedText:l,resolvedSpans:p}=F(d,t,r),m=p.filter((e=>e.original.start<n&&e.original.start+e.original.length<n)).reduce(((e,t)=>e+(t.lines-1)),0);o.line=o.line+m,g=l,u=new A(o.line,o.start-1)}}const[m,f]=function(t,n,i){var r;const s=p.getTokenAtPosition(n,i);let a=[];try{a=e.parse(n,{noLocation:!0}).definitions.filter((t=>t.kind===e.Kind.FRAGMENT_DEFINITION))}catch(e){console.log("[GraphQLSP] ",e)}console.log("fraggers",a.map((t=>e.print(t))).join("\n"));let o=p.getAutocompleteSuggestions(t,n,i),l=function(t,n,i,r,s){if(!r)return[];const a=i.getTypeMap(),o=p.getDefinitionState(t.state);return function(e,t){return function(e,t){return t?O(O(e.map((e=>({proximity:w(j(e.label),t),entry:e}))),(e=>e.proximity<=2)),(e=>!e.entry.isDeprecated)).sort(((e,t)=>(e.entry.isDeprecated?1:0)-(t.entry.isDeprecated?1:0)||e.proximity-t.proximity||e.entry.label.length-t.entry.label.length)).map((e=>e.entry)):O(e,(e=>!e.isDeprecated))}(t,j(e.string))}(t,s.filter((t=>a[t.typeCondition.name.value]&&!(o&&o.kind===p.RuleKinds.FRAGMENT_DEFINITION&&o.name===t.name.value)&&e.isCompositeType(n.parentType)&&e.isCompositeType(a[t.typeCondition.name.value])&&e.doTypesOverlap(i,n.parentType,a[t.typeCondition.name.value]))).map((e=>({label:e.name.value,detail:String(a[e.typeCondition.name.value]),documentation:`fragment ${e.name.value} on ${e.typeCondition.name.value}`,kind:p.CompletionItemKind.Field,type:a[e.typeCondition.name.value]}))))}(s,p.getTypeInfo(t,s.state),t,n,a);console.log(JSON.stringify(l,null,2));const c="Invalid"===s.state.kind?s.state.prevState:s.state,g=null===(r=R(s.state,p.RuleKinds.FIELD))||void 0===r?void 0:r.name;if(c&&g){const{kind:e}=c;if(e===p.RuleKinds.ARGUMENTS||e===p.RuleKinds.ARGUMENT){const e=new Set;q(n,((t,n)=>{if(n.kind===p.RuleKinds.ARGUMENT){const t=R(n,p.RuleKinds.FIELD);g&&n.name&&(null==t?void 0:t.name)===g&&e.add(n.name)}})),o=o.filter((t=>!e.has(t.label)))}if(e===p.RuleKinds.SELECTION_SET||e===p.RuleKinds.FIELD||e===p.RuleKinds.ALIASED_FIELD){const e=new Set,t=P(n,g);q(n,((t,n)=>{if(n.kind===p.RuleKinds.FIELD||n.kind===p.RuleKinds.ALIASED_FIELD){const t=R(n,p.RuleKinds.FIELD);t&&t.name===g&&n.name&&e.add(n.name)}})),o=o.filter((t=>!e.has(t.label))),l=l.filter((e=>!t.has(e.label)))}if(e===p.RuleKinds.FRAGMENT_SPREAD){const e=P(n,g);o=o.filter((t=>!e.has(t.label))),l=l.filter((t=>!e.has(t.label)))}}return[o,l]}(i.current,g,u);return{isGlobalCompletion:!1,isMemberCompletion:!1,isNewIdentifierLocation:!1,entries:[...m.map((e=>{var t;return{...e,kind:c.ScriptElementKind.variableElement,name:e.label,kindModifiers:"declare",sortText:e.sortText||"0",labelDetails:{detail:e.type?" "+(null===(t=e.type)||void 0===t?void 0:t.toString()):void 0,description:e.documentation}}})),...f.map((e=>({...e,kind:c.ScriptElementKind.variableElement,name:e.label,insertText:"..."+e.label,kindModifiers:"declare",sortText:"0",labelDetails:{description:e.documentation}})))]}}(t,n,J,s);return r&&r.entries.length?r:s.languageService.getCompletionsAtPosition(t,n,i)||{isGlobalCompletion:!1,isMemberCompletion:!1,isNewIdentifierLocation:!1,entries:[]}},N.getQuickInfoAtPosition=(e,t)=>{const n=function(e,t,n,i){var r;const s=i.config.template||"gql",a=null!==(r=i.config.templateIsCallExpression)&&void 0!==r&&r,o=T(i,e);if(!o)return;let l,g,u=y(o,t);if(!u)return;if(u=a?L(u):D(u),c.isCallExpression(u)&&a&&u.expression.getText()===s&&u.arguments.length>0&&c.isNoSubstitutionTemplateLiteral(u.arguments[0])){const e=k(u.arguments[0],t);if(!n.current||!e)return;g=u.arguments[0].getText(),l=new A(e.line,e.start-1)}else{if(!c.isTaggedTemplateExpression(u))return;{const{template:r,tag:a}=u;if(!c.isIdentifier(a)||a.text!==s)return;const o=k(r,t);if(!o||!n.current)return;const{combinedText:p,resolvedSpans:d}=F(u,e,i),m=d.filter((e=>e.original.start<t&&e.original.start+e.original.length<t)).reduce(((e,t)=>e+(t.lines-1)),0);o.line=o.line+m,g=p,l=new A(o.line,o.start-1)}}const d=p.getHoverInformation(n.current,g,l);return{kind:c.ScriptElementKind.label,textSpan:{start:t,length:1},kindModifiers:"text",documentation:Array.isArray(d)?d.map((e=>({kind:"text",text:e}))):[{kind:"text",text:d}]}}(e,t,J,s);return n||s.languageService.getQuickInfoAtPosition(e,t)},o("proxy: "+JSON.stringify(N)),N}module.exports=()=>({create:U});

@@ -1,1 +0,1 @@

import{parse as e,printSchema as t,buildClientSchema as n,buildSchema as i,getIntrospectionQuery as r,print as a,isCompositeType as s,doTypesOverlap as o,Kind as l,visit as c}from"graphql";import p from"node-fetch";import g,{posix as u}from"path";import m from"fs";import{codegen as d}from"@graphql-codegen/core";import*as f from"@graphql-codegen/typescript";import*as h from"@graphql-codegen/typescript-operations";import*as x from"@graphql-codegen/typed-document-node";import*as S from"@graphql-codegen/add";import T from"typescript/lib/tsserverlibrary";import{onlineParser as v,CharacterStream as y,getDefinitionState as E,RuleKinds as N,CompletionItemKind as b,getTokenAtPosition as I,getAutocompleteSuggestions as C,getTypeInfo as D,getHoverInformation as L,getDiagnostics as F}from"graphql-language-service";import{LRUCache as k}from"lru-cache";import A from"@sindresorhus/fnv1a";const O=async(n,i,r,a)=>{if(!n)return;const s={documents:[],config:{scalars:r,avoidOptionals:!1,enumsAsTypes:!0,globalNamespace:!0,nonOptionalTypename:!0},filename:i,schema:e(t(n)),plugins:[{typescript:{}},a&&{add:{content:a}}].filter(Boolean),pluginMap:a?{typescript:f,add:S}:{typescript:f}},o=await d(s);let l=i.split("/");l.pop();const c=u.join(l.join("/"));m.existsSync(c)||m.mkdirSync(c),m.writeFile(u.join(i),o,"utf8",(e=>{console.error(e)}))};function w(e,t){const n=m.readFileSync(e,"utf-8");return t.getFullText()!==n}function j(e,t){const n=e.languageService.getProgram();if(n)return n.getSourceFile(t)||void 0}function P(e,t){return function e(n){if(t>=n.getStart()&&t<n.getEnd())return T.forEachChild(n,e)||n}(e)}function G(e,t){const n=[];return function e(i){T.isTaggedTemplateExpression(i)&&i.tag.getText()===t||T.isNoSubstitutionTemplateLiteral(i)&&T.isTaggedTemplateExpression(i.parent)&&i.parent.tag.getText()===t?n.push(i):T.forEachChild(i,e)}(e),n}function $(e,t,n,i=!0){const r=[];let a=[],s=!i;return function i(o){if(T.isCallExpression(o)&&o.expression.getText()===t){s||(s=!0,a=_(e.fileName,o,n));const[t]=o.arguments;t&&T.isNoSubstitutionTemplateLiteral(t)&&r.push(t)}else T.forEachChild(o,i)}(e),{nodes:r,fragments:a}}function _(t,n,i){let r=[];const a=i.languageService.getDefinitionAtPosition(t,n.expression.getStart());if(!a)return r;const s=j(i,a[0].fileName);return s?(T.forEachChild(s,(t=>{if(T.isVariableStatement(t)&&t.declarationList&&"documents"===t.declarationList.declarations[0].name.getText()){const[n]=t.declarationList.declarations;n.initializer&&T.isObjectLiteralExpression(n.initializer)&&n.initializer.properties.forEach((t=>{if(T.isPropertyAssignment(t)&&T.isStringLiteral(t.name))try{const n=JSON.parse(`${t.name.getText().replace(/'/g,'"')}`);n.includes("fragment ")&&n.includes(" on ")&&e(n,{noLocation:!0}).definitions.forEach((e=>{"FragmentDefinition"===e.kind&&r.push(e)}))}catch(e){}}))}})),r):r}function M(e){return e.statements.filter(T.isImportDeclaration)}function B(e){for(;T.isNoSubstitutionTemplateLiteral(e)||T.isToken(e)||T.isTemplateExpression(e)||T.isTemplateSpan(e);)e=e.parent;return e}function R(e){for(;T.isNoSubstitutionTemplateLiteral(e)||T.isToken(e)||T.isTemplateExpression(e)||T.isTemplateSpan(e);)e=e.parent;return e}class q{constructor(e,t){this.line=e,this.character=t}setLine(e){this.line=e}setCharacter(e){this.character=e}lessThanOrEqualTo(e){return this.line<e.line||this.line===e.line&&this.character<=e.character}}function z(e,t,n){if(T.isNoSubstitutionTemplateLiteral(e))return{combinedText:e.getText().slice(1,-1),resolvedSpans:[]};let i=e.template.getText().slice(1,-1);if(T.isNoSubstitutionTemplateLiteral(e.template)||0===e.template.templateSpans.length)return{combinedText:i,resolvedSpans:[]};let r=0;const s=e.template.templateSpans.map((e=>{if(T.isIdentifier(e.expression)){const s=n.languageService.getDefinitionAtPosition(t,e.expression.getStart());if(!s)return;const o=s[0],l=j(n,o.fileName);if(!l)return;const c=P(l,o.textSpan.start);if(!c||!c.parent)return;const p=c.parent;if(T.isVariableDeclaration(p)){const t=e.expression.escapedText,s=e.expression.getStart()-2,l={start:s,length:e.expression.end-s+1};if(p.initializer&&T.isTaggedTemplateExpression(p.initializer)){const a=z(p.initializer,o.fileName,n);i=i.replace("${"+e.expression.escapedText+"}",a.combinedText);const s={lines:a.combinedText.split("\n").length,identifier:t,original:l,new:{start:l.start+r,length:a.combinedText.length}};return r+=a.combinedText.length-l.length,s}if(p.initializer&&T.isAsExpression(p.initializer)&&T.isTaggedTemplateExpression(p.initializer.expression)){const a=z(p.initializer.expression,o.fileName,n);i=i.replace("${"+e.expression.escapedText+"}",a.combinedText);const s={lines:a.combinedText.split("\n").length,identifier:t,original:l,new:{start:l.start+r,length:a.combinedText.length}};return r+=a.combinedText.length-l.length,s}if(p.initializer&&T.isAsExpression(p.initializer)&&T.isAsExpression(p.initializer.expression)&&T.isObjectLiteralExpression(p.initializer.expression.expression)){const n=JSON.parse(p.initializer.expression.expression.getText()),s=a(n);i=i.replace("${"+e.expression.escapedText+"}",s);const o={lines:s.split("\n").length,identifier:t,original:l,new:{start:l.start+r,length:s.length}};return r+=s.length-l.length,o}return}}})).filter(Boolean);return{combinedText:i,resolvedSpans:s}}const U=(e,t)=>{const n=e.getText().slice(1,-1).split("\n"),i=v(),r=i.startState();let a,s=e.pos+1;for(let e=0;e<n.length;e++){const o=s-1,l=new y(n[e]);for(;!l.eol();){const n=i.token(l,r),s=l.current();if(s&&o+l.getStartOfToken()<=t&&o+l.getCurrentPosition()>=t){a={line:e,start:l.getStartOfToken()+1,end:l.getCurrentPosition(),string:s,state:r,tokenKind:n};break}}s+=n[e].length+1}return a};function J(e,t){const n=e.filter(t);return 0===n.length?e:n}function Q(e){return e.toLowerCase().replace(/\W/g,"")}function V(e,t){let n=function(e,t){let n,i;const r=[],a=e.length,s=t.length;for(n=0;n<=a;n++)r[n]=[n];for(i=1;i<=s;i++)r[0][i]=i;for(n=1;n<=a;n++)for(i=1;i<=s;i++){const a=e[n-1]===t[i-1]?0:1;r[n][i]=Math.min(r[n-1][i]+1,r[n][i-1]+1,r[n-1][i-1]+a),n>1&&i>1&&e[n-1]===t[i-2]&&e[n-2]===t[i-1]&&(r[n][i]=Math.min(r[n][i],r[n-2][i-2]+a))}return r[a][s]}(t,e);return e.length>t.length&&(n-=e.length-t.length-1,n+=0===e.indexOf(t)?0:.5),n}function W(e,t){const n=new Set;return H(e,((e,i)=>{if(i.kind===N.FRAGMENT_SPREAD&&i.name){const e=K(i,N.FIELD);t&&(null==e?void 0:e.name)===t&&n.add(i.name)}})),n}function K(e,t){var n,i,r,a,s,o,l,c,p,g;return(null===(n=e.prevState)||void 0===n?void 0:n.kind)===t?e.prevState:(null===(r=null===(i=e.prevState)||void 0===i?void 0:i.prevState)||void 0===r?void 0:r.kind)===t?e.prevState.prevState:(null===(o=null===(s=null===(a=e.prevState)||void 0===a?void 0:a.prevState)||void 0===s?void 0:s.prevState)||void 0===o?void 0:o.kind)===t?e.prevState.prevState.prevState:(null===(g=null===(p=null===(c=null===(l=e.prevState)||void 0===l?void 0:l.prevState)||void 0===c?void 0:c.prevState)||void 0===p?void 0:p.prevState)||void 0===g?void 0:g.kind)===t?e.prevState.prevState.prevState.prevState:void 0}function H(e,t){const n=e.split("\n"),i=v();let r=i.startState(),a="",s=new y("");for(let e=0;e<n.length;e++){for(s=new y(n[e]);!s.eol()&&(a=i.token(s,r),"BREAK"!==t(s,r,a,e)););t(s,r,a,e),r.kind||(r=i.startState())}return{start:s.getStartOfToken(),end:s.getCurrentPosition(),string:s.current(),state:r,style:a}}const X=(e,t,n,i,r)=>{const a=[];for(const s of e.elements)if(T.isObjectBindingPattern(s.name)){const e=[...t];s.propertyName&&n.includes(s.propertyName.getText())&&!t.includes(s.propertyName.getText())&&e.push(s.propertyName.getText());const o=X(s.name,e,n,i,r);a.push(...o)}else if(T.isIdentifier(s.name)){const e=[...t];s.propertyName&&n.includes(s.propertyName.getText())&&!t.includes(s.propertyName.getText())?e.push(s.propertyName.getText()):e.push(s.name.getText());const o=Y(s.name,e,n,i,r);a.push(...o)}return a},Y=(e,t,n,i,r)=>{let a=[];const s=r.languageService.getReferencesAtPosition(i.fileName,e.getStart());return s?(a=s.flatMap((a=>{if(a.fileName!==i.fileName)return[];if(e.getStart()<=a.textSpan.start&&e.getEnd()>=a.textSpan.start+a.textSpan.length)return[];let s=P(i,a.textSpan.start);if(!s)return[];const o=[...t];for(;T.isIdentifier(s)||T.isPropertyAccessExpression(s)||T.isElementAccessExpression(s)||T.isVariableDeclaration(s)||T.isBinaryExpression(s);){if(T.isVariableDeclaration(s)){if(T.isIdentifier(s.name))return Y(s.name,o,n,i,r);if(T.isObjectBindingPattern(s.name))return X(s.name,o,n,i,r)}else T.isIdentifier(s)&&n.includes(s.text)&&!o.includes(s.text)?o.push(s.text):T.isPropertyAccessExpression(s)&&n.includes(s.name.text)&&!o.includes(s.name.text)?o.push(s.name.text):T.isElementAccessExpression(s)&&T.isStringLiteral(s.argumentExpression)&&n.includes(s.argumentExpression.text)&&!o.includes(s.argumentExpression.text)&&o.push(s.argumentExpression.text);s=s.parent}return o.join(".")})),a):a};function Z(t,n){let i=[];return $(t,n.config.template||"gql",n,!1).nodes.forEach((r=>{const a=z(r,t.fileName,n).combinedText;try{const t=e(a,{noLocation:!0});t.definitions.every((e=>e.kind===l.FRAGMENT_DEFINITION))&&(i=i.concat(t.definitions))}catch(e){return}})),i}const ee=new Set(["populate","client","_optional","_required","arguments","argumentDefinitions","connection","refetchable","relay","required","inline"]),te=/Unknown directive "@([^)]+)"/g;let ne=!1;const ie=new k({ttl:9e5,max:5e3});function re(f){var v;const y=e=>f.project.projectService.logger.info(`[GraphQLSP] ${e}`),k=f.config;if(y("config: "+JSON.stringify(k)),!k.schema)throw y('Missing "schema" option in configuration.'),new Error("Please provide a GraphQL Schema!");y("Setting up the GraphQL Plugin");const re=k.scalars||{},ae=k.extraTypes||"",se=null!==(v=k.disableTypegen)&&void 0!==v&&v,oe=function(e){const t=Object.create(null);for(let n of Object.keys(e.languageService)){const i=e.languageService[n];t[n]=(...t)=>i.apply(e.languageService,t)}return t}(f),le=f.project.getCurrentDirectory()+"/__generated__/baseGraphQLSP.ts",ce=((e,t,a,s,o,l,c)=>{const u={current:null,version:0};let d,f;try{"object"==typeof t?(d=new URL(t.url),f={headers:t.headers}):d=new URL(t)}catch(e){}if(d){const e=()=>{a(`Fetching introspection from ${d.toString()}`),p(d.toString(),{method:"POST",headers:f?{...f.headers||{},"Content-Type":"application/json"}:{"Content-Type":"application/json"},body:JSON.stringify({query:r({descriptions:!0,schemaDescription:!1,inputValueDeprecation:!1,directiveIsRepeatable:!1,specifiedByUrl:!1})})}).then((e=>(a(`Got response ${e.statusText} ${e.status}`),e.ok?e.json():e.text()))).then((e=>{if(a(`Got result ${JSON.stringify(e)}`),"string"==typeof e)a(`Got error while fetching introspection ${e}`);else if(e.data)try{u.current=n(e.data),u.version=u.version+1,a(`Got schema for ${d.toString()}`),o&&O(u.current,s,l,c)}catch(e){a(`Got schema error for ${e.message}`)}else a(`Got invalid response ${JSON.stringify(e)}`)}))};e(),setInterval((()=>{e()}),6e4)}else if("string"==typeof t){const r=t.endsWith("json"),p=g.resolve(g.dirname(e),t);a(`Getting schema from ${p}`);const d=m.readFileSync(p,"utf-8");m.watchFile(p,(()=>{const e=m.readFileSync(p,"utf-8");u.current=r?n(JSON.parse(e)):i(e),u.version=u.version+1,o&&O(u.current,s,l)})),u.current=r?n(JSON.parse(d)):i(d),u.version=u.version+1,o&&O(u.current,s,l,c),a(`Got schema and initialized watcher for ${t}`)}return u})(f.project.getProjectName(),k.schema,y,le,!se,re,ae);return oe.getSemanticDiagnostics=n=>{const i=f.languageService.getSemanticDiagnostics(n),r=function(n,i,r,s,o){var p;const g=o.config.template||"gql",f=null!==(p=o.config.templateIsCallExpression)&&void 0!==p&&p;let v=j(o,i);if(!v)return;let y,E=[];if(f){const e=$(v,g,o);E=e.fragments,y=e.nodes}else y=G(v,g);const N=y.map((e=>{if((T.isNoSubstitutionTemplateLiteral(e)||T.isTemplateExpression(e))&&!f){if(!T.isTaggedTemplateExpression(e.parent))return;e=e.parent}return z(e,i,o).combinedText}));let b=[];const I=A(f?v.getText()+E.map((e=>a(e))).join("-")+s.version:N.join("-")+s.version);return ie.has(I)?b=ie.get(I):(b=((t,{nodes:n,fragments:i},r,a)=>{var s,o;const p=a.config.template||"gql",g=t.fileName,u=null!==(s=a.config.templateIsCallExpression)&&void 0!==s&&s,m=n.map((t=>{let n=t;if(!u&&(T.isNoSubstitutionTemplateLiteral(n)||T.isTemplateExpression(n))){if(!T.isTaggedTemplateExpression(n.parent))return;n=n.parent}const{combinedText:s,resolvedSpans:o}=z(n,g,a),c=s.split("\n");let m=!1;T.isAsExpression(n.parent)?T.isExpressionStatement(n.parent.parent)&&(m=!0):T.isExpressionStatement(n.parent)&&(m=!0);let d=n.pos+(u?0:p.length+(m?2:1));const f=d+n.getText().length;let h=[...i];if(u)try{const t=e(s,{noLocation:!0}).definitions.filter((e=>e.kind===l.FRAGMENT_DEFINITION));h=h.filter((e=>!t.some((t=>t.kind===l.FRAGMENT_DEFINITION&&t.name.value===e.name.value))))}catch(e){}const x=F(s,r.current,void 0,void 0,h).filter((e=>{if(!e.message.includes("Unknown directive"))return!0;const[t]=e.message.split("("),n=te.exec(t);return!n||!ee.has(n[1])})).map((e=>{const{start:t,end:n}=e.range;let i=d+t.line;for(let e=0;e<=t.line;e++)i+=e===t.line?t.character:c[e].length;let r=d+n.line;for(let e=0;e<=n.line;e++)r+=e===n.line?n.character:c[e].length;const a=o.find((e=>i>=e.new.start&&r<=e.new.start+e.new.length));if(a)return{...e,start:a.original.start,length:a.original.length};if(i>f){const t=o.filter((e=>e.new.start+e.new.length<i)).reduce(((e,t)=>e+(t.new.length-t.original.length)),0);return i-=t,r-=t,{...e,start:i+1,length:r-i}}return{...e,start:i+1,length:r-i}})).filter((e=>e.start+e.length<=f));try{const i=e(s,{noLocation:!0});i.definitions.some((e=>e.kind===l.OPERATION_DEFINITION))&&(i.definitions.find((e=>e.kind===l.OPERATION_DEFINITION)).name||x.push({message:"Operation needs a name for types to be generated.",start:n.pos,code:52002,length:t.getText().length,range:{},severity:2}))}catch(e){}return x})).flat().filter(Boolean).map((e=>({file:t,length:e.length,start:e.start,category:2===e.severity?T.DiagnosticCategory.Warning:T.DiagnosticCategory.Error,code:"number"==typeof e.code?e.code:2===e.severity?52004:52001,messageText:e.message.split("\n")[0]})));if(u){const i=((t,n,i)=>{var r;const a=[];return null!==(r=i.config.trackFieldUsage)&&void 0!==r&&r?(n.forEach((n=>{const r=n.getText();if(r.includes("mutation")||r.includes("subscription"))return;const s=(e=>{let t=e,n=0;for(;!T.isVariableDeclaration(t)&&t.parent&&n<5;)t=t.parent,n++;return t})(n);if(!T.isVariableDeclaration(s))return;const o=i.languageService.getReferencesAtPosition(t.fileName,s.name.getStart());o&&o.forEach((r=>{if(r.fileName!==t.fileName)return;let o=P(t,r.textSpan.start);for(;o&&!T.isVariableStatement(o);)o=o.parent;if(!o||!T.isVariableStatement(o))return;const[l]=o.declarationList.declarations;if(l.name.getText()===s.name.getText())return;const p=[],g=[],u=[],m=["id","__typename"],d=new Map;c(e(n.getText().slice(1,-1)),{Field:{enter:e=>{if(m.includes(e.name.value)||u.push(e.name.value),e.selectionSet||m.includes(e.name.value))e.selectionSet&&p.push(e.name.value);else{let t;t=p.length?p.join(".")+"."+e.name.value:e.name.value,g.push(t),d.set(t,{start:e.name.loc.start,length:e.name.loc.end-e.name.loc.start})}},leave:e=>{e.selectionSet&&p.pop()}}});let f=l.name;T.isArrayBindingPattern(f)&&T.isBindingElement(f.elements[0])&&(f=f.elements[0].name);let h=[];h=T.isObjectBindingPattern(f)?X(f,[],u,t,i):Y(f,[],u,t,i),g.filter((e=>!h.includes(e))).forEach((e=>{const i=d.get(e);i&&a.push({file:t,length:i.length,start:n.getStart()+i.start+1,category:T.DiagnosticCategory.Warning,code:52005,messageText:`Field '${e}' is not used.`})}))}))})),a):a})(t,n,a),r=null!==(o=a.config.shouldCheckForColocatedFragments)&&void 0!==o&&o;let s=[];if(console.log("[GraphhQLSP] Checking for colocated fragments ",!!r),r){const i=((e,t)=>{const n=M(e),i={};return n.length&&n.forEach((n=>{if(n.importClause){if(n.importClause.name){const r=t.languageService.getDefinitionAtPosition(e.fileName,n.importClause.name.getStart());if(r&&r.length){const[e]=r;if(e.fileName.includes("node_modules"))return;const a=j(t,e.fileName);if(!a)return;const s=Z(a,t).map((e=>e.name.value));s.length&&!i[n.moduleSpecifier.getText()]?i[n.moduleSpecifier.getText()]={start:n.moduleSpecifier.getStart(),length:n.moduleSpecifier.getText().length,fragments:s}:s.length&&(i[n.moduleSpecifier.getText()].fragments=i[n.moduleSpecifier.getText()].fragments.concat(s))}}if(n.importClause.namedBindings&&T.isNamespaceImport(n.importClause.namedBindings)){const r=t.languageService.getDefinitionAtPosition(e.fileName,n.importClause.namedBindings.getStart());if(r&&r.length){const[e]=r;if(e.fileName.includes("node_modules"))return;const a=j(t,e.fileName);if(!a)return;const s=Z(a,t).map((e=>e.name.value));s.length&&!i[n.moduleSpecifier.getText()]?i[n.moduleSpecifier.getText()]={start:n.moduleSpecifier.getStart(),length:n.moduleSpecifier.getText().length,fragments:s}:s.length&&(i[n.moduleSpecifier.getText()].fragments=i[n.moduleSpecifier.getText()].fragments.concat(s))}}else n.importClause.namedBindings&&T.isNamedImportBindings(n.importClause.namedBindings)&&n.importClause.namedBindings.elements.forEach((r=>{const a=t.languageService.getDefinitionAtPosition(e.fileName,r.getStart());if(a&&a.length){const[e]=a;if(e.fileName.includes("node_modules"))return;const r=j(t,e.fileName);if(!r)return;const s=Z(r,t).map((e=>e.name.value));s.length&&!i[n.moduleSpecifier.getText()]?i[n.moduleSpecifier.getText()]={start:n.moduleSpecifier.getStart(),length:n.moduleSpecifier.getText().length,fragments:s}:s.length&&(i[n.moduleSpecifier.getText()].fragments=i[n.moduleSpecifier.getText()].fragments.concat(s))}}))}})),i})(t,a);console.log("[GraphhQLSP] Checking for colocated fragments ",JSON.stringify(i,null,2));const r=new Set;n.forEach((t=>{try{const n=e(t.getText().slice(1,-1),{noLocation:!0});c(n,{FragmentSpread:e=>{r.add(e.name.value)}})}catch(e){}})),Object.keys(i).forEach((e=>{const{fragments:n,start:a,length:o}=i[e],l=n.filter((e=>!r.has(e)));l.length&&s.push({file:t,length:o,start:a,category:T.DiagnosticCategory.Warning,code:52003,messageText:`Unused co-located fragment definition(s) "${l.join(", ")}" in ${e}`})}))}return[...m,...i,...s]}{const n=((t,n)=>{var i,r;const a=M(t),s=n.config.template||"gql",o=null!==(i=n.config.shouldCheckForColocatedFragments)&&void 0!==i&&i,c=[];if(a.length&&o){const i=null===(r=n.languageService.getProgram())||void 0===r?void 0:r.getTypeChecker();a.forEach((r=>{var a;if(!r.importClause)return;const o=[];if(r.importClause.name&&o.push(null===(a=r.importClause)||void 0===a?void 0:a.name.text),r.importClause.namedBindings&&T.isNamespaceImport(r.importClause.namedBindings))return;r.importClause.namedBindings&&T.isNamedImportBindings(r.importClause.namedBindings)&&r.importClause.namedBindings.elements.forEach((e=>{o.push(e.name.text)}));const p=null==i?void 0:i.getSymbolAtLocation(r.moduleSpecifier);if(!p)return;const g=null==i?void 0:i.getExportsOfModule(p);if(!g)return;const u=g.map((t=>{if(o.includes(t.name))return;const i=t.getDeclarations(),r=null==i?void 0:i.find((e=>!0));if(!r)return;const[a]=G(r,s);if(a){let i=a;if(T.isNoSubstitutionTemplateLiteral(i)||T.isTemplateExpression(i)){if(!T.isTaggedTemplateExpression(i.parent))return;i=i.parent}const r=z(i,i.getSourceFile().fileName,n).combinedText;try{if(e(r,{noLocation:!0}).definitions.every((e=>e.kind===l.FRAGMENT_DEFINITION)))return`'${t.name}'`}catch(e){return}}})).filter(Boolean);u.length&&c.push({file:t,length:r.getText().length,start:r.getStart(),category:T.DiagnosticCategory.Message,code:52003,messageText:`Missing Fragment import(s) ${u.join(", ")} from ${r.moduleSpecifier.getText()}.`})}))}return c})(t,a);return[...m,...n]}})(v,{nodes:y,fragments:E},s,o),ie.set(I,b)),((n,i,r,a,s,o,c,p)=>{var g;const f=c.fileName,v=p.config.scalars||{},y=null!==(g=p.config.disableTypegen)&&void 0!==g&&g;let E=c;if(!a.filter((e=>e.category===T.DiagnosticCategory.Error||e.category===T.DiagnosticCategory.Warning)).length&&!y)try{if(w(f,E)&&!ne)return;ne=!0;const a=E.fileName.split("/"),c=a[a.length-1].split(".");c[c.length-1]="generated.ts",a[a.length-1]=c.join("."),(async(n,i,r,a,s)=>{try{if(!n)return{success:!1};const o=i.split("/");o.pop();let l=u.relative(o.join("/"),s).replace(".ts","");"__generated__/baseGraphQLSP"===l&&(l="./"+l);const c={documents:[{location:"operation.graphql",document:e(r)}],config:{scalars:a,avoidOptionals:!1,enumsAsTypes:!0,nonOptionalTypename:!0,namespacedImportName:"Types"},filename:i,schema:e(t(n)),plugins:[{"typescript-operations":{}},{"typed-document-node":{}},{add:{content:`import * as Types from "${l}"`}}],pluginMap:{"typescript-operations":h,"typed-document-node":x,add:S}},p=await d(c);return m.writeFile(u.join(i),p,"utf8",(e=>{console.error(e)})),{success:!0}}catch(e){return{success:!1}}})(r.current,a.join("/"),i.join("\n"),v,o).then((({success:t})=>{if(!t||s)return;if(E=j(p,f),!E||w(f,E))return;let r=0;const a=n.reduce(((t,n,a)=>{var s;if(E=j(p,f),!E)return t;const o=e(i[a]||"",{noLocation:!0}),g=o.definitions.every((e=>e.kind===l.FRAGMENT_DEFINITION));let u="";if(u=g?o.definitions[0].name.value:(null===(s=o.definitions[0].name)||void 0===s?void 0:s.value)||"",!u)return t;u=u.charAt(0).toUpperCase()+u.slice(1);const m=n.parent.getChildren(),d=g?`${u}FragmentDoc`:`${u}Document`;let h=` as typeof import('./${c.join(".").replace(".ts","")}').${d}\n`;const x=m.find((e=>T.isImportTypeNode(e)));if(x&&x.getText().includes(d))return t;const S={length:1,start:n.end};let v="";if(x){const e=x.getText().split(".").pop();h=h.slice(4),h=h.substring(0,h.length-1);const i=n.getStart();v=t.slice(0,i)+t.slice(i).replace(x.getText(),h),S.length=h.length+((e||"").length-d.length)}else v=t.substring(0,S.start)+h+t.substring(S.start+S.length,t.length);return t=v,r+=h.length,E.hasBeenIncrementallyParsed=!1,E.update(v,{span:S,newLength:h.length}),E.text=v,t}),E.text),o=p.project.projectService.getScriptInfo(f),g=o.getSnapshot();o.editContent(0,g.getLength(),a),p.languageServiceHost.writeFile(E.fileName,a),o.reloadFromFile(),o.registerFileUpdate(),ne=!1}))}catch(e){p.project.projectService.getScriptInfo(f).reloadFromFile(),ne=!1}})(y,N,s,b,n,r,v,o),b}(i.length>0,n,le,ce,f);return r?[...r,...i]:i},oe.getCompletionsAtPosition=(t,n,i)=>{const r=function(t,n,i,r){var c;const p=r.config.template||"gql",g=null!==(c=r.config.templateIsCallExpression)&&void 0!==c&&c,u=j(r,t);if(!u)return;let m,d,f=P(u,n);if(!f)return;if(f=g?R(f):B(f),T.isCallExpression(f)&&g&&f.expression.getText()===p&&f.arguments.length>0&&T.isNoSubstitutionTemplateLiteral(f.arguments[0])){const e=U(f.arguments[0],n);if(!i.current||!e)return;m=`${f.arguments[0].getText().slice(1,-1)}\n${_(t,f,r).map((e=>a(e))).join("\n")}`,d=new q(e.line,e.start-1)}else{if(!T.isTaggedTemplateExpression(f))return;{const{template:e,tag:a}=f;if(!T.isIdentifier(a)||a.text!==p)return;const s=U(e,n);if(!s||!i.current)return;const{combinedText:o,resolvedSpans:l}=z(f,t,r),c=l.filter((e=>e.original.start<n&&e.original.start+e.original.length<n)).reduce(((e,t)=>e+(t.lines-1)),0);s.line=s.line+c,m=o,d=new q(s.line,s.start-1)}}const[h,x]=function(t,n,i){var r;const c=I(n,i);let p=[];try{p=e(n,{noLocation:!0}).definitions.filter((e=>e.kind===l.FRAGMENT_DEFINITION))}catch(e){console.log("[GraphQLSP] ",e)}console.log("fraggers",p.map((e=>a(e))).join("\n"));let g=C(t,n,i),u=function(e,t,n,i,r){if(!i)return[];const a=n.getTypeMap(),l=E(e.state);return function(e,t){return function(e,t){return t?J(J(e.map((e=>({proximity:V(Q(e.label),t),entry:e}))),(e=>e.proximity<=2)),(e=>!e.entry.isDeprecated)).sort(((e,t)=>(e.entry.isDeprecated?1:0)-(t.entry.isDeprecated?1:0)||e.proximity-t.proximity||e.entry.label.length-t.entry.label.length)).map((e=>e.entry)):J(e,(e=>!e.isDeprecated))}(t,Q(e.string))}(e,r.filter((e=>a[e.typeCondition.name.value]&&!(l&&l.kind===N.FRAGMENT_DEFINITION&&l.name===e.name.value)&&s(t.parentType)&&s(a[e.typeCondition.name.value])&&o(n,t.parentType,a[e.typeCondition.name.value]))).map((e=>({label:e.name.value,detail:String(a[e.typeCondition.name.value]),documentation:`fragment ${e.name.value} on ${e.typeCondition.name.value}`,kind:b.Field,type:a[e.typeCondition.name.value]}))))}(c,D(t,c.state),t,n,p);console.log(JSON.stringify(u,null,2));const m="Invalid"===c.state.kind?c.state.prevState:c.state,d=null===(r=K(c.state,N.FIELD))||void 0===r?void 0:r.name;if(m&&d){const{kind:e}=m;if(e===N.ARGUMENTS||e===N.ARGUMENT){const e=new Set;H(n,((t,n)=>{if(n.kind===N.ARGUMENT){const t=K(n,N.FIELD);d&&n.name&&(null==t?void 0:t.name)===d&&e.add(n.name)}})),g=g.filter((t=>!e.has(t.label)))}if(e===N.SELECTION_SET||e===N.FIELD||e===N.ALIASED_FIELD){const e=new Set,t=W(n,d);H(n,((t,n)=>{if(n.kind===N.FIELD||n.kind===N.ALIASED_FIELD){const t=K(n,N.FIELD);t&&t.name===d&&n.name&&e.add(n.name)}})),g=g.filter((t=>!e.has(t.label))),u=u.filter((e=>!t.has(e.label)))}if(e===N.FRAGMENT_SPREAD){const e=W(n,d);g=g.filter((t=>!e.has(t.label))),u=u.filter((t=>!e.has(t.label)))}}return[g,u]}(i.current,m,d);return{isGlobalCompletion:!1,isMemberCompletion:!1,isNewIdentifierLocation:!1,entries:[...h.map((e=>{var t;return{...e,kind:T.ScriptElementKind.variableElement,name:e.label,kindModifiers:"declare",sortText:e.sortText||"0",labelDetails:{detail:e.type?" "+(null===(t=e.type)||void 0===t?void 0:t.toString()):void 0,description:e.documentation}}})),...x.map((e=>({...e,kind:T.ScriptElementKind.variableElement,name:e.label,insertText:"..."+e.label,kindModifiers:"declare",sortText:"0",labelDetails:{description:e.documentation}})))]}}(t,n,ce,f);return r&&r.entries.length?r:f.languageService.getCompletionsAtPosition(t,n,i)||{isGlobalCompletion:!1,isMemberCompletion:!1,isNewIdentifierLocation:!1,entries:[]}},oe.getQuickInfoAtPosition=(e,t)=>{const n=function(e,t,n,i){var r;const a=i.config.template||"gql",s=null!==(r=i.config.templateIsCallExpression)&&void 0!==r&&r,o=j(i,e);if(!o)return;let l,c,p=P(o,t);if(!p)return;if(p=s?R(p):B(p),T.isCallExpression(p)&&s&&p.expression.getText()===a&&p.arguments.length>0&&T.isNoSubstitutionTemplateLiteral(p.arguments[0])){const e=U(p.arguments[0],t);if(!n.current||!e)return;c=p.arguments[0].getText(),l=new q(e.line,e.start-1)}else{if(!T.isTaggedTemplateExpression(p))return;{const{template:r,tag:s}=p;if(!T.isIdentifier(s)||s.text!==a)return;const o=U(r,t);if(!o||!n.current)return;const{combinedText:g,resolvedSpans:u}=z(p,e,i),m=u.filter((e=>e.original.start<t&&e.original.start+e.original.length<t)).reduce(((e,t)=>e+(t.lines-1)),0);o.line=o.line+m,c=g,l=new q(o.line,o.start-1)}}const g=L(n.current,c,l);return{kind:T.ScriptElementKind.label,textSpan:{start:t,length:1},kindModifiers:"text",documentation:Array.isArray(g)?g.map((e=>({kind:"text",text:e}))):[{kind:"text",text:g}]}}(e,t,ce,f);return n||f.languageService.getQuickInfoAtPosition(e,t)},y("proxy: "+JSON.stringify(oe)),oe}const ae=()=>({create:re});export{ae as default};
import{parse as e,printSchema as t,buildClientSchema as n,buildSchema as i,getIntrospectionQuery as r,print as a,isCompositeType as s,doTypesOverlap as o,Kind as l,visit as c}from"graphql";import p from"node-fetch";import g,{posix as u}from"path";import m from"fs";import{codegen as f}from"@graphql-codegen/core";import*as d from"@graphql-codegen/typescript";import*as h from"@graphql-codegen/typescript-operations";import*as x from"@graphql-codegen/typed-document-node";import*as S from"@graphql-codegen/add";import T from"typescript/lib/tsserverlibrary";import{onlineParser as v,CharacterStream as y,getDefinitionState as E,RuleKinds as N,CompletionItemKind as b,getTokenAtPosition as I,getAutocompleteSuggestions as C,getTypeInfo as D,getHoverInformation as L,getDiagnostics as F}from"graphql-language-service";import{LRUCache as A}from"lru-cache";import k from"@sindresorhus/fnv1a";const O=async(n,i,r,a)=>{if(!n)return;const s={documents:[],config:{scalars:r,avoidOptionals:!1,enumsAsTypes:!0,globalNamespace:!0,nonOptionalTypename:!0},filename:i,schema:e(t(n)),plugins:[{typescript:{}},a&&{add:{content:a}}].filter(Boolean),pluginMap:a?{typescript:d,add:S}:{typescript:d}},o=await f(s);let l=i.split("/");l.pop();const c=u.join(l.join("/"));m.existsSync(c)||m.mkdirSync(c),m.writeFile(u.join(i),o,"utf8",(e=>{console.error(e)}))};function w(e,t){const n=m.readFileSync(e,"utf-8");return t.getFullText()!==n}function j(e,t){const n=e.languageService.getProgram();if(n)return n.getSourceFile(t)||void 0}function P(e,t){return function e(n){if(t>=n.getStart()&&t<n.getEnd())return T.forEachChild(n,e)||n}(e)}function $(e,t){const n=[];return function e(i){T.isTaggedTemplateExpression(i)&&i.tag.getText()===t||T.isNoSubstitutionTemplateLiteral(i)&&T.isTaggedTemplateExpression(i.parent)&&i.parent.tag.getText()===t?n.push(i):T.forEachChild(i,e)}(e),n}function G(t,n,i){const r=[],a=i.languageService.getDefinitionAtPosition(t.getSourceFile().fileName,t.getStart());if(!a)return r;const[s]=a,o=j(i,s.fileName);if(!o)return r;let l=P(o,s.textSpan.start);if(!l)return r;if(T.isVariableDeclaration(l.parent)&&l.parent.initializer&&T.isCallExpression(l.parent.initializer)&&(l=l.parent.initializer),T.isCallExpression(l)&&l.expression.getText()===n){const[t,a]=l.arguments;a&&T.isArrayLiteralExpression(a)&&a.elements.forEach((e=>{T.isIdentifier(e)&&r.push(...G(e,n,i))}));try{e(t.getText().slice(1,-1),{noLocation:!0}).definitions.forEach((e=>{"FragmentDefinition"===e.kind&&r.push(e)}))}catch(e){}}return r}function _(e,t,n,i=!0){const r=[];let a=[],s=!i;return function i(o){if(T.isCallExpression(o)&&o.expression.getText()===t){const[i,l]=o.arguments;return s||l?l&&T.isArrayLiteralExpression(l)&&l.elements.forEach((e=>{T.isIdentifier(e)&&a.push(...G(e,t,n))})):(s=!0,a=M(e.fileName,o,n)),void(i&&T.isNoSubstitutionTemplateLiteral(i)&&r.push(i))}T.forEachChild(o,i)}(e),{nodes:r,fragments:a}}function M(t,n,i){const r=i.config.template||"gql";let a=[];const s=i.languageService.getDefinitionAtPosition(t,n.expression.getStart());if(!s)return a;if(n.arguments[1]&&T.isArrayLiteralExpression(n.arguments[1]))return n.arguments[1].elements.forEach((e=>{T.isIdentifier(e)&&a.push(...G(e,r,i))})),a;const o=j(i,s[0].fileName);return o?(T.forEachChild(o,(t=>{if(T.isVariableStatement(t)&&t.declarationList&&"documents"===t.declarationList.declarations[0].name.getText()){const[n]=t.declarationList.declarations;n.initializer&&T.isObjectLiteralExpression(n.initializer)&&n.initializer.properties.forEach((t=>{if(T.isPropertyAssignment(t)&&T.isStringLiteral(t.name))try{const n=JSON.parse(`${t.name.getText().replace(/'/g,'"')}`);n.includes("fragment ")&&n.includes(" on ")&&e(n,{noLocation:!0}).definitions.forEach((e=>{"FragmentDefinition"===e.kind&&a.push(e)}))}catch(e){}}))}})),a):a}function B(e){return e.statements.filter(T.isImportDeclaration)}function R(e){for(;T.isNoSubstitutionTemplateLiteral(e)||T.isToken(e)||T.isTemplateExpression(e)||T.isTemplateSpan(e);)e=e.parent;return e}function q(e){for(;T.isNoSubstitutionTemplateLiteral(e)||T.isToken(e)||T.isTemplateExpression(e)||T.isTemplateSpan(e);)e=e.parent;return e}class z{constructor(e,t){this.line=e,this.character=t}setLine(e){this.line=e}setCharacter(e){this.character=e}lessThanOrEqualTo(e){return this.line<e.line||this.line===e.line&&this.character<=e.character}}function U(e,t,n){if(T.isNoSubstitutionTemplateLiteral(e))return{combinedText:e.getText().slice(1,-1),resolvedSpans:[]};let i=e.template.getText().slice(1,-1);if(T.isNoSubstitutionTemplateLiteral(e.template)||0===e.template.templateSpans.length)return{combinedText:i,resolvedSpans:[]};let r=0;const s=e.template.templateSpans.map((e=>{if(T.isIdentifier(e.expression)){const s=n.languageService.getDefinitionAtPosition(t,e.expression.getStart());if(!s)return;const o=s[0],l=j(n,o.fileName);if(!l)return;const c=P(l,o.textSpan.start);if(!c||!c.parent)return;const p=c.parent;if(T.isVariableDeclaration(p)){const t=e.expression.escapedText,s=e.expression.getStart()-2,l={start:s,length:e.expression.end-s+1};if(p.initializer&&T.isTaggedTemplateExpression(p.initializer)){const a=U(p.initializer,o.fileName,n);i=i.replace("${"+e.expression.escapedText+"}",a.combinedText);const s={lines:a.combinedText.split("\n").length,identifier:t,original:l,new:{start:l.start+r,length:a.combinedText.length}};return r+=a.combinedText.length-l.length,s}if(p.initializer&&T.isAsExpression(p.initializer)&&T.isTaggedTemplateExpression(p.initializer.expression)){const a=U(p.initializer.expression,o.fileName,n);i=i.replace("${"+e.expression.escapedText+"}",a.combinedText);const s={lines:a.combinedText.split("\n").length,identifier:t,original:l,new:{start:l.start+r,length:a.combinedText.length}};return r+=a.combinedText.length-l.length,s}if(p.initializer&&T.isAsExpression(p.initializer)&&T.isAsExpression(p.initializer.expression)&&T.isObjectLiteralExpression(p.initializer.expression.expression)){const n=JSON.parse(p.initializer.expression.expression.getText()),s=a(n);i=i.replace("${"+e.expression.escapedText+"}",s);const o={lines:s.split("\n").length,identifier:t,original:l,new:{start:l.start+r,length:s.length}};return r+=s.length-l.length,o}return}}})).filter(Boolean);return{combinedText:i,resolvedSpans:s}}const J=(e,t)=>{const n=e.getText().slice(1,-1).split("\n"),i=v(),r=i.startState();let a,s=e.pos+1;for(let e=0;e<n.length;e++){const o=s-1,l=new y(n[e]);for(;!l.eol();){const n=i.token(l,r),s=l.current();if(s&&o+l.getStartOfToken()<=t&&o+l.getCurrentPosition()>=t){a={line:e,start:l.getStartOfToken()+1,end:l.getCurrentPosition(),string:s,state:r,tokenKind:n};break}}s+=n[e].length+1}return a};function V(e,t){const n=e.filter(t);return 0===n.length?e:n}function Q(e){return e.toLowerCase().replace(/\W/g,"")}function W(e,t){let n=function(e,t){let n,i;const r=[],a=e.length,s=t.length;for(n=0;n<=a;n++)r[n]=[n];for(i=1;i<=s;i++)r[0][i]=i;for(n=1;n<=a;n++)for(i=1;i<=s;i++){const a=e[n-1]===t[i-1]?0:1;r[n][i]=Math.min(r[n-1][i]+1,r[n][i-1]+1,r[n-1][i-1]+a),n>1&&i>1&&e[n-1]===t[i-2]&&e[n-2]===t[i-1]&&(r[n][i]=Math.min(r[n][i],r[n-2][i-2]+a))}return r[a][s]}(t,e);return e.length>t.length&&(n-=e.length-t.length-1,n+=0===e.indexOf(t)?0:.5),n}function K(e,t){const n=new Set;return X(e,((e,i)=>{if(i.kind===N.FRAGMENT_SPREAD&&i.name){const e=H(i,N.FIELD);t&&(null==e?void 0:e.name)===t&&n.add(i.name)}})),n}function H(e,t){var n,i,r,a,s,o,l,c,p,g;return(null===(n=e.prevState)||void 0===n?void 0:n.kind)===t?e.prevState:(null===(r=null===(i=e.prevState)||void 0===i?void 0:i.prevState)||void 0===r?void 0:r.kind)===t?e.prevState.prevState:(null===(o=null===(s=null===(a=e.prevState)||void 0===a?void 0:a.prevState)||void 0===s?void 0:s.prevState)||void 0===o?void 0:o.kind)===t?e.prevState.prevState.prevState:(null===(g=null===(p=null===(c=null===(l=e.prevState)||void 0===l?void 0:l.prevState)||void 0===c?void 0:c.prevState)||void 0===p?void 0:p.prevState)||void 0===g?void 0:g.kind)===t?e.prevState.prevState.prevState.prevState:void 0}function X(e,t){const n=e.split("\n"),i=v();let r=i.startState(),a="",s=new y("");for(let e=0;e<n.length;e++){for(s=new y(n[e]);!s.eol()&&(a=i.token(s,r),"BREAK"!==t(s,r,a,e)););t(s,r,a,e),r.kind||(r=i.startState())}return{start:s.getStartOfToken(),end:s.getCurrentPosition(),string:s.current(),state:r,style:a}}const Y=(e,t,n,i,r)=>{const a=[];for(const s of e.elements)if(T.isObjectBindingPattern(s.name)){const e=[...t];s.propertyName&&n.includes(s.propertyName.getText())&&!t.includes(s.propertyName.getText())&&e.push(s.propertyName.getText());const o=Y(s.name,e,n,i,r);a.push(...o)}else if(T.isIdentifier(s.name)){const e=[...t];s.propertyName&&n.includes(s.propertyName.getText())&&!t.includes(s.propertyName.getText())?e.push(s.propertyName.getText()):e.push(s.name.getText());const o=Z(s.name,e,n,i,r);a.push(...o)}return a},Z=(e,t,n,i,r)=>{let a=[];const s=r.languageService.getReferencesAtPosition(i.fileName,e.getStart());return s?(a=s.flatMap((a=>{if(a.fileName!==i.fileName)return[];if(e.getStart()<=a.textSpan.start&&e.getEnd()>=a.textSpan.start+a.textSpan.length)return[];let s=P(i,a.textSpan.start);if(!s)return[];const o=[...t];for(;T.isIdentifier(s)||T.isPropertyAccessExpression(s)||T.isElementAccessExpression(s)||T.isVariableDeclaration(s)||T.isBinaryExpression(s);){if(T.isVariableDeclaration(s)){if(T.isIdentifier(s.name))return Z(s.name,o,n,i,r);if(T.isObjectBindingPattern(s.name))return Y(s.name,o,n,i,r)}else T.isIdentifier(s)&&n.includes(s.text)&&!o.includes(s.text)?o.push(s.text):T.isPropertyAccessExpression(s)&&n.includes(s.name.text)&&!o.includes(s.name.text)?o.push(s.name.text):T.isElementAccessExpression(s)&&T.isStringLiteral(s.argumentExpression)&&n.includes(s.argumentExpression.text)&&!o.includes(s.argumentExpression.text)&&o.push(s.argumentExpression.text);s=s.parent}return o.join(".")})),a):a};function ee(t,n){let i=[];return _(t,n.config.template||"gql",n,!1).nodes.forEach((r=>{const a=U(r,t.fileName,n).combinedText;try{const t=e(a,{noLocation:!0});t.definitions.every((e=>e.kind===l.FRAGMENT_DEFINITION))&&(i=i.concat(t.definitions))}catch(e){return}})),i}const te=new Set(["populate","client","_optional","_required","arguments","argumentDefinitions","connection","refetchable","relay","required","inline"]),ne=/Unknown directive "@([^)]+)"/g;let ie=!1;const re=new A({ttl:9e5,max:5e3});function ae(d){var v;const y=e=>d.project.projectService.logger.info(`[GraphQLSP] ${e}`),A=d.config;if(y("config: "+JSON.stringify(A)),!A.schema)throw y('Missing "schema" option in configuration.'),new Error("Please provide a GraphQL Schema!");y("Setting up the GraphQL Plugin");const G=A.scalars||{},ae=A.extraTypes||"",se=null!==(v=A.disableTypegen)&&void 0!==v&&v,oe=function(e){const t=Object.create(null);for(let n of Object.keys(e.languageService)){const i=e.languageService[n];t[n]=(...t)=>i.apply(e.languageService,t)}return t}(d),le=d.project.getCurrentDirectory()+"/__generated__/baseGraphQLSP.ts",ce=((e,t,a,s,o,l,c)=>{const u={current:null,version:0};let f,d;try{"object"==typeof t?(f=new URL(t.url),d={headers:t.headers}):f=new URL(t)}catch(e){}if(f){const e=()=>{a(`Fetching introspection from ${f.toString()}`),p(f.toString(),{method:"POST",headers:d?{...d.headers||{},"Content-Type":"application/json"}:{"Content-Type":"application/json"},body:JSON.stringify({query:r({descriptions:!0,schemaDescription:!1,inputValueDeprecation:!1,directiveIsRepeatable:!1,specifiedByUrl:!1})})}).then((e=>(a(`Got response ${e.statusText} ${e.status}`),e.ok?e.json():e.text()))).then((e=>{if(a(`Got result ${JSON.stringify(e)}`),"string"==typeof e)a(`Got error while fetching introspection ${e}`);else if(e.data)try{u.current=n(e.data),u.version=u.version+1,a(`Got schema for ${f.toString()}`),o&&O(u.current,s,l,c)}catch(e){a(`Got schema error for ${e.message}`)}else a(`Got invalid response ${JSON.stringify(e)}`)}))};e(),setInterval((()=>{e()}),6e4)}else if("string"==typeof t){const r=t.endsWith("json"),p=g.resolve(g.dirname(e),t);a(`Getting schema from ${p}`);const f=m.readFileSync(p,"utf-8");m.watchFile(p,(()=>{const e=m.readFileSync(p,"utf-8");u.current=r?n(JSON.parse(e)):i(e),u.version=u.version+1,o&&O(u.current,s,l)})),u.current=r?n(JSON.parse(f)):i(f),u.version=u.version+1,o&&O(u.current,s,l,c),a(`Got schema and initialized watcher for ${t}`)}return u})(d.project.getProjectName(),A.schema,y,le,!se,G,ae);return oe.getSemanticDiagnostics=n=>{const i=d.languageService.getSemanticDiagnostics(n),r=function(n,i,r,s,o){var p;const g=o.config.template||"gql",d=null!==(p=o.config.templateIsCallExpression)&&void 0!==p&&p;let v=j(o,i);if(!v)return;let y,E=[];if(d){const e=_(v,g,o);E=e.fragments,y=e.nodes}else y=$(v,g);const N=y.map((e=>{if((T.isNoSubstitutionTemplateLiteral(e)||T.isTemplateExpression(e))&&!d){if(!T.isTaggedTemplateExpression(e.parent))return;e=e.parent}return U(e,i,o).combinedText}));let b=[];const I=k(d?v.getText()+E.map((e=>a(e))).join("-")+s.version:N.join("-")+s.version);return re.has(I)?b=re.get(I):(b=((t,{nodes:n,fragments:i},r,a)=>{var s,o;const p=a.config.template||"gql",g=t.fileName,u=null!==(s=a.config.templateIsCallExpression)&&void 0!==s&&s,m=n.map((t=>{let n=t;if(!u&&(T.isNoSubstitutionTemplateLiteral(n)||T.isTemplateExpression(n))){if(!T.isTaggedTemplateExpression(n.parent))return;n=n.parent}const{combinedText:s,resolvedSpans:o}=U(n,g,a),c=s.split("\n");let m=!1;T.isAsExpression(n.parent)?T.isExpressionStatement(n.parent.parent)&&(m=!0):T.isExpressionStatement(n.parent)&&(m=!0);let f=n.pos+(u?0:p.length+(m?2:1));const d=f+n.getText().length;let h=[...i];if(u)try{const t=e(s,{noLocation:!0}).definitions.filter((e=>e.kind===l.FRAGMENT_DEFINITION));h=h.filter((e=>!t.some((t=>t.kind===l.FRAGMENT_DEFINITION&&t.name.value===e.name.value))))}catch(e){}const x=F(s,r.current,void 0,void 0,h).filter((e=>{if(!e.message.includes("Unknown directive"))return!0;const[t]=e.message.split("("),n=ne.exec(t);return!n||!te.has(n[1])})).map((e=>{const{start:t,end:n}=e.range;let i=f+t.line;for(let e=0;e<=t.line;e++)i+=e===t.line?t.character:c[e].length;let r=f+n.line;for(let e=0;e<=n.line;e++)r+=e===n.line?n.character:c[e].length;const a=o.find((e=>i>=e.new.start&&r<=e.new.start+e.new.length));if(a)return{...e,start:a.original.start,length:a.original.length};if(i>d){const t=o.filter((e=>e.new.start+e.new.length<i)).reduce(((e,t)=>e+(t.new.length-t.original.length)),0);return i-=t,r-=t,{...e,start:i+1,length:r-i}}return{...e,start:i+1,length:r-i}})).filter((e=>e.start+e.length<=d));try{const i=e(s,{noLocation:!0});i.definitions.some((e=>e.kind===l.OPERATION_DEFINITION))&&(i.definitions.find((e=>e.kind===l.OPERATION_DEFINITION)).name||x.push({message:"Operation needs a name for types to be generated.",start:n.pos,code:52002,length:t.getText().length,range:{},severity:2}))}catch(e){}return x})).flat().filter(Boolean).map((e=>({file:t,length:e.length,start:e.start,category:2===e.severity?T.DiagnosticCategory.Warning:T.DiagnosticCategory.Error,code:"number"==typeof e.code?e.code:2===e.severity?52004:52001,messageText:e.message.split("\n")[0]})));if(u){const i=((t,n,i)=>{var r;const a=[];return null!==(r=i.config.trackFieldUsage)&&void 0!==r&&r?(n.forEach((n=>{const r=n.getText();if(r.includes("mutation")||r.includes("subscription"))return;const s=(e=>{let t=e,n=0;for(;!T.isVariableDeclaration(t)&&t.parent&&n<5;)t=t.parent,n++;return t})(n);if(!T.isVariableDeclaration(s))return;const o=i.languageService.getReferencesAtPosition(t.fileName,s.name.getStart());o&&o.forEach((r=>{if(r.fileName!==t.fileName)return;let o=P(t,r.textSpan.start);for(;o&&!T.isVariableStatement(o);)o=o.parent;if(!o||!T.isVariableStatement(o))return;const[l]=o.declarationList.declarations;if(l.name.getText()===s.name.getText())return;const p=[],g=[],u=[],m=["id","__typename"],f=new Map;c(e(n.getText().slice(1,-1)),{Field:{enter:e=>{if(m.includes(e.name.value)||u.push(e.name.value),e.selectionSet||m.includes(e.name.value))e.selectionSet&&p.push(e.name.value);else{let t;t=p.length?p.join(".")+"."+e.name.value:e.name.value,g.push(t),f.set(t,{start:e.name.loc.start,length:e.name.loc.end-e.name.loc.start})}},leave:e=>{e.selectionSet&&p.pop()}}});let d=l.name;T.isArrayBindingPattern(d)&&T.isBindingElement(d.elements[0])&&(d=d.elements[0].name);let h=[];h=T.isObjectBindingPattern(d)?Y(d,[],u,t,i):Z(d,[],u,t,i),g.filter((e=>!h.includes(e))).forEach((e=>{const i=f.get(e);i&&a.push({file:t,length:i.length,start:n.getStart()+i.start+1,category:T.DiagnosticCategory.Warning,code:52005,messageText:`Field '${e}' is not used.`})}))}))})),a):a})(t,n,a),r=null!==(o=a.config.shouldCheckForColocatedFragments)&&void 0!==o&&o;let s=[];if(console.log("[GraphhQLSP] Checking for colocated fragments ",!!r),r){const i=((e,t)=>{const n=B(e),i={};return n.length&&n.forEach((n=>{if(n.importClause){if(n.importClause.name){const r=t.languageService.getDefinitionAtPosition(e.fileName,n.importClause.name.getStart());if(r&&r.length){const[e]=r;if(e.fileName.includes("node_modules"))return;const a=j(t,e.fileName);if(!a)return;const s=ee(a,t).map((e=>e.name.value));s.length&&!i[n.moduleSpecifier.getText()]?i[n.moduleSpecifier.getText()]={start:n.moduleSpecifier.getStart(),length:n.moduleSpecifier.getText().length,fragments:s}:s.length&&(i[n.moduleSpecifier.getText()].fragments=i[n.moduleSpecifier.getText()].fragments.concat(s))}}if(n.importClause.namedBindings&&T.isNamespaceImport(n.importClause.namedBindings)){const r=t.languageService.getDefinitionAtPosition(e.fileName,n.importClause.namedBindings.getStart());if(r&&r.length){const[e]=r;if(e.fileName.includes("node_modules"))return;const a=j(t,e.fileName);if(!a)return;const s=ee(a,t).map((e=>e.name.value));s.length&&!i[n.moduleSpecifier.getText()]?i[n.moduleSpecifier.getText()]={start:n.moduleSpecifier.getStart(),length:n.moduleSpecifier.getText().length,fragments:s}:s.length&&(i[n.moduleSpecifier.getText()].fragments=i[n.moduleSpecifier.getText()].fragments.concat(s))}}else n.importClause.namedBindings&&T.isNamedImportBindings(n.importClause.namedBindings)&&n.importClause.namedBindings.elements.forEach((r=>{const a=t.languageService.getDefinitionAtPosition(e.fileName,r.getStart());if(a&&a.length){const[e]=a;if(e.fileName.includes("node_modules"))return;const r=j(t,e.fileName);if(!r)return;const s=ee(r,t).map((e=>e.name.value));s.length&&!i[n.moduleSpecifier.getText()]?i[n.moduleSpecifier.getText()]={start:n.moduleSpecifier.getStart(),length:n.moduleSpecifier.getText().length,fragments:s}:s.length&&(i[n.moduleSpecifier.getText()].fragments=i[n.moduleSpecifier.getText()].fragments.concat(s))}}))}})),i})(t,a),r=new Set;n.forEach((t=>{try{const n=e(t.getText().slice(1,-1),{noLocation:!0});c(n,{FragmentSpread:e=>{r.add(e.name.value)}})}catch(e){}})),Object.keys(i).forEach((e=>{const{fragments:n,start:a,length:o}=i[e],l=Array.from(new Set(n.filter((e=>!r.has(e)))));l.length&&s.push({file:t,length:o,start:a,category:T.DiagnosticCategory.Warning,code:52003,messageText:`Unused co-located fragment definition(s) "${l.join(", ")}" in ${e}`})}))}return[...m,...i,...s]}{const n=((t,n)=>{var i,r;const a=B(t),s=n.config.template||"gql",o=null!==(i=n.config.shouldCheckForColocatedFragments)&&void 0!==i&&i,c=[];if(a.length&&o){const i=null===(r=n.languageService.getProgram())||void 0===r?void 0:r.getTypeChecker();a.forEach((r=>{var a;if(!r.importClause)return;const o=[];if(r.importClause.name&&o.push(null===(a=r.importClause)||void 0===a?void 0:a.name.text),r.importClause.namedBindings&&T.isNamespaceImport(r.importClause.namedBindings))return;r.importClause.namedBindings&&T.isNamedImportBindings(r.importClause.namedBindings)&&r.importClause.namedBindings.elements.forEach((e=>{o.push(e.name.text)}));const p=null==i?void 0:i.getSymbolAtLocation(r.moduleSpecifier);if(!p)return;const g=null==i?void 0:i.getExportsOfModule(p);if(!g)return;const u=new Set;g.forEach((t=>{if(o.includes(t.name))return;const i=t.getDeclarations(),r=null==i?void 0:i.find((e=>!0));if(!r)return;const[a]=$(r,s);if(a){let i=a;if(T.isNoSubstitutionTemplateLiteral(i)||T.isTemplateExpression(i)){if(!T.isTaggedTemplateExpression(i.parent))return;i=i.parent}const r=U(i,i.getSourceFile().fileName,n).combinedText;try{e(r,{noLocation:!0}).definitions.every((e=>e.kind===l.FRAGMENT_DEFINITION))&&u.add(`'${t.name}'`)}catch(e){return}}}));const m=Array.from(u);m.length&&c.push({file:t,length:r.getText().length,start:r.getStart(),category:T.DiagnosticCategory.Message,code:52003,messageText:`Missing Fragment import(s) ${m.join(", ")} from ${r.moduleSpecifier.getText()}.`})}))}return c})(t,a);return[...m,...n]}})(v,{nodes:y,fragments:E},s,o),re.set(I,b)),((n,i,r,a,s,o,c,p)=>{var g;const d=c.fileName,v=p.config.scalars||{},y=null!==(g=p.config.disableTypegen)&&void 0!==g&&g;let E=c;if(!a.filter((e=>e.category===T.DiagnosticCategory.Error||e.category===T.DiagnosticCategory.Warning)).length&&!y)try{if(w(d,E)&&!ie)return;ie=!0;const a=E.fileName.split("/"),c=a[a.length-1].split(".");c[c.length-1]="generated.ts",a[a.length-1]=c.join("."),(async(n,i,r,a,s)=>{try{if(!n)return{success:!1};const o=i.split("/");o.pop();let l=u.relative(o.join("/"),s).replace(".ts","");"__generated__/baseGraphQLSP"===l&&(l="./"+l);const c={documents:[{location:"operation.graphql",document:e(r)}],config:{scalars:a,avoidOptionals:!1,enumsAsTypes:!0,nonOptionalTypename:!0,namespacedImportName:"Types"},filename:i,schema:e(t(n)),plugins:[{"typescript-operations":{}},{"typed-document-node":{}},{add:{content:`import * as Types from "${l}"`}}],pluginMap:{"typescript-operations":h,"typed-document-node":x,add:S}},p=await f(c);return m.writeFile(u.join(i),p,"utf8",(e=>{console.error(e)})),{success:!0}}catch(e){return{success:!1}}})(r.current,a.join("/"),i.join("\n"),v,o).then((({success:t})=>{if(!t||s)return;if(E=j(p,d),!E||w(d,E))return;let r=0;const a=n.reduce(((t,n,a)=>{var s;if(E=j(p,d),!E)return t;const o=e(i[a]||"",{noLocation:!0}),g=o.definitions.every((e=>e.kind===l.FRAGMENT_DEFINITION));let u="";if(u=g?o.definitions[0].name.value:(null===(s=o.definitions[0].name)||void 0===s?void 0:s.value)||"",!u)return t;u=u.charAt(0).toUpperCase()+u.slice(1);const m=n.parent.getChildren(),f=g?`${u}FragmentDoc`:`${u}Document`;let h=` as typeof import('./${c.join(".").replace(".ts","")}').${f}\n`;const x=m.find((e=>T.isImportTypeNode(e)));if(x&&x.getText().includes(f))return t;const S={length:1,start:n.end};let v="";if(x){const e=x.getText().split(".").pop();h=h.slice(4),h=h.substring(0,h.length-1);const i=n.getStart();v=t.slice(0,i)+t.slice(i).replace(x.getText(),h),S.length=h.length+((e||"").length-f.length)}else v=t.substring(0,S.start)+h+t.substring(S.start+S.length,t.length);return t=v,r+=h.length,E.hasBeenIncrementallyParsed=!1,E.update(v,{span:S,newLength:h.length}),E.text=v,t}),E.text),o=p.project.projectService.getScriptInfo(d),g=o.getSnapshot();o.editContent(0,g.getLength(),a),p.languageServiceHost.writeFile(E.fileName,a),o.reloadFromFile(),o.registerFileUpdate(),ie=!1}))}catch(e){p.project.projectService.getScriptInfo(d).reloadFromFile(),ie=!1}})(y,N,s,b,n,r,v,o),b}(i.length>0,n,le,ce,d);return r?[...r,...i]:i},oe.getCompletionsAtPosition=(t,n,i)=>{const r=function(t,n,i,r){var c;const p=r.config.template||"gql",g=null!==(c=r.config.templateIsCallExpression)&&void 0!==c&&c,u=j(r,t);if(!u)return;let m,f,d=P(u,n);if(!d)return;if(d=g?q(d):R(d),T.isCallExpression(d)&&g&&d.expression.getText()===p&&d.arguments.length>0&&T.isNoSubstitutionTemplateLiteral(d.arguments[0])){const e=J(d.arguments[0],n);if(!i.current||!e)return;m=`${d.arguments[0].getText().slice(1,-1)}\n${M(t,d,r).map((e=>a(e))).join("\n")}`,f=new z(e.line,e.start-1)}else{if(!T.isTaggedTemplateExpression(d))return;{const{template:e,tag:a}=d;if(!T.isIdentifier(a)||a.text!==p)return;const s=J(e,n);if(!s||!i.current)return;const{combinedText:o,resolvedSpans:l}=U(d,t,r),c=l.filter((e=>e.original.start<n&&e.original.start+e.original.length<n)).reduce(((e,t)=>e+(t.lines-1)),0);s.line=s.line+c,m=o,f=new z(s.line,s.start-1)}}const[h,x]=function(t,n,i){var r;const c=I(n,i);let p=[];try{p=e(n,{noLocation:!0}).definitions.filter((e=>e.kind===l.FRAGMENT_DEFINITION))}catch(e){console.log("[GraphQLSP] ",e)}console.log("fraggers",p.map((e=>a(e))).join("\n"));let g=C(t,n,i),u=function(e,t,n,i,r){if(!i)return[];const a=n.getTypeMap(),l=E(e.state);return function(e,t){return function(e,t){return t?V(V(e.map((e=>({proximity:W(Q(e.label),t),entry:e}))),(e=>e.proximity<=2)),(e=>!e.entry.isDeprecated)).sort(((e,t)=>(e.entry.isDeprecated?1:0)-(t.entry.isDeprecated?1:0)||e.proximity-t.proximity||e.entry.label.length-t.entry.label.length)).map((e=>e.entry)):V(e,(e=>!e.isDeprecated))}(t,Q(e.string))}(e,r.filter((e=>a[e.typeCondition.name.value]&&!(l&&l.kind===N.FRAGMENT_DEFINITION&&l.name===e.name.value)&&s(t.parentType)&&s(a[e.typeCondition.name.value])&&o(n,t.parentType,a[e.typeCondition.name.value]))).map((e=>({label:e.name.value,detail:String(a[e.typeCondition.name.value]),documentation:`fragment ${e.name.value} on ${e.typeCondition.name.value}`,kind:b.Field,type:a[e.typeCondition.name.value]}))))}(c,D(t,c.state),t,n,p);console.log(JSON.stringify(u,null,2));const m="Invalid"===c.state.kind?c.state.prevState:c.state,f=null===(r=H(c.state,N.FIELD))||void 0===r?void 0:r.name;if(m&&f){const{kind:e}=m;if(e===N.ARGUMENTS||e===N.ARGUMENT){const e=new Set;X(n,((t,n)=>{if(n.kind===N.ARGUMENT){const t=H(n,N.FIELD);f&&n.name&&(null==t?void 0:t.name)===f&&e.add(n.name)}})),g=g.filter((t=>!e.has(t.label)))}if(e===N.SELECTION_SET||e===N.FIELD||e===N.ALIASED_FIELD){const e=new Set,t=K(n,f);X(n,((t,n)=>{if(n.kind===N.FIELD||n.kind===N.ALIASED_FIELD){const t=H(n,N.FIELD);t&&t.name===f&&n.name&&e.add(n.name)}})),g=g.filter((t=>!e.has(t.label))),u=u.filter((e=>!t.has(e.label)))}if(e===N.FRAGMENT_SPREAD){const e=K(n,f);g=g.filter((t=>!e.has(t.label))),u=u.filter((t=>!e.has(t.label)))}}return[g,u]}(i.current,m,f);return{isGlobalCompletion:!1,isMemberCompletion:!1,isNewIdentifierLocation:!1,entries:[...h.map((e=>{var t;return{...e,kind:T.ScriptElementKind.variableElement,name:e.label,kindModifiers:"declare",sortText:e.sortText||"0",labelDetails:{detail:e.type?" "+(null===(t=e.type)||void 0===t?void 0:t.toString()):void 0,description:e.documentation}}})),...x.map((e=>({...e,kind:T.ScriptElementKind.variableElement,name:e.label,insertText:"..."+e.label,kindModifiers:"declare",sortText:"0",labelDetails:{description:e.documentation}})))]}}(t,n,ce,d);return r&&r.entries.length?r:d.languageService.getCompletionsAtPosition(t,n,i)||{isGlobalCompletion:!1,isMemberCompletion:!1,isNewIdentifierLocation:!1,entries:[]}},oe.getQuickInfoAtPosition=(e,t)=>{const n=function(e,t,n,i){var r;const a=i.config.template||"gql",s=null!==(r=i.config.templateIsCallExpression)&&void 0!==r&&r,o=j(i,e);if(!o)return;let l,c,p=P(o,t);if(!p)return;if(p=s?q(p):R(p),T.isCallExpression(p)&&s&&p.expression.getText()===a&&p.arguments.length>0&&T.isNoSubstitutionTemplateLiteral(p.arguments[0])){const e=J(p.arguments[0],t);if(!n.current||!e)return;c=p.arguments[0].getText(),l=new z(e.line,e.start-1)}else{if(!T.isTaggedTemplateExpression(p))return;{const{template:r,tag:s}=p;if(!T.isIdentifier(s)||s.text!==a)return;const o=J(r,t);if(!o||!n.current)return;const{combinedText:g,resolvedSpans:u}=U(p,e,i),m=u.filter((e=>e.original.start<t&&e.original.start+e.original.length<t)).reduce(((e,t)=>e+(t.lines-1)),0);o.line=o.line+m,c=g,l=new z(o.line,o.start-1)}}const g=L(n.current,c,l);return{kind:T.ScriptElementKind.label,textSpan:{start:t,length:1},kindModifiers:"text",documentation:Array.isArray(g)?g.map((e=>({kind:"text",text:e}))):[{kind:"text",text:g}]}}(e,t,ce,d);return n||d.languageService.getQuickInfoAtPosition(e,t)},y("proxy: "+JSON.stringify(oe)),oe}const se=()=>({create:ae});export{se as default};
{
"name": "@0no-co/graphqlsp",
"version": "0.14.1",
"version": "0.15.0",
"description": "TypeScript LSP plugin that finds GraphQL documents in your code and provides hints and auto-generates types.",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc