@gql.tada/cli-utils 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @gql.tada/cli-utils
|
|
2
2
|
|
|
3
|
+
## 1.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ⚠️ Fix hash parsing in `generate-persisted` command
|
|
8
|
+
Submitted by [@kitten](https://github.com/kitten) (See [#212](https://github.com/0no-co/gql.tada/pull/212))
|
|
9
|
+
|
|
3
10
|
## 1.0.0
|
|
4
11
|
|
|
5
12
|
**Read the full release announcement post at: https://gql-tada.0no.co/devlog/2024-04-15**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-chunk.js","sources":["../../src/commands/generate-persisted/thread.ts"],"sourcesContent":["import * as path from 'node:path';\nimport { print } from '@0no-co/graphql.web';\nimport { Project, ts } from 'ts-morph';\n\nimport type { FragmentDefinitionNode } from '@0no-co/graphql.web';\nimport type { GraphQLSPConfig } from '@gql.tada/internal';\n\nimport {\n init,\n findAllPersistedCallExpressions,\n getDocumentReferenceFromTypeQuery,\n getDocumentReferenceFromDocumentNode,\n unrollTadaFragments,\n} from '@0no-co/graphqlsp/api';\n\nimport { createPluginInfo, getFilePosition } from '../../ts';\nimport { expose } from '../../threads';\n\nimport type { PersistedSignal, PersistedWarning } from './types';\n\nexport interface PersistedParams {\n rootPath: string;\n configPath: string;\n pluginConfig: GraphQLSPConfig;\n}\n\nasync function* _runPersisted(params: PersistedParams): AsyncIterableIterator<PersistedSignal> {\n init({ typescript: ts as any });\n\n const projectPath = path.dirname(params.configPath);\n const project = new Project({ tsConfigFilePath: params.configPath });\n const pluginInfo = createPluginInfo(project, params.pluginConfig, projectPath);\n\n // Filter source files by whether they're under the relevant root path\n const sourceFiles = project.getSourceFiles().filter((sourceFile) => {\n const filePath = path.resolve(projectPath, sourceFile.getFilePath());\n const relative = path.relative(params.rootPath, filePath);\n return !relative.startsWith('..');\n });\n\n yield {\n kind: 'FILE_COUNT',\n fileCount: sourceFiles.length,\n };\n\n for (const { compilerNode: sourceFile } of sourceFiles) {\n const filePath = sourceFile.fileName;\n const documents: Record<string, string> = {};\n const warnings: PersistedWarning[] = [];\n\n const calls = findAllPersistedCallExpressions(sourceFile);\n for (const call of calls) {\n const position = getFilePosition(sourceFile, call.getStart());\n const hashArg = call.arguments[0];\n const docArg = call.arguments[1];\n const typeQuery = call.typeArguments && call.typeArguments[0];\n if (!hashArg || !ts.isStringLiteral(hashArg)) {\n warnings.push({\n message:\n '\"graphql.persisted\" must be called with a string literal as the first argument.',\n file: filePath,\n line: position.line,\n col: position.col,\n });\n continue;\n } else if (!docArg && !typeQuery) {\n warnings.push({\n message:\n '\"graphql.persisted\" is missing a document.\\n' +\n 'This may be passed as a generic such as `graphql.persisted<typeof document>` or as the second argument.',\n file: filePath,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n let foundNode: ts.CallExpression | null = null;\n let referencingNode: ts.Node = call;\n if (docArg && (ts.isCallExpression(docArg) || ts.isIdentifier(docArg))) {\n const result = getDocumentReferenceFromDocumentNode(docArg, filePath, pluginInfo);\n foundNode = result.node;\n referencingNode = docArg;\n } else if (typeQuery && ts.isTypeQueryNode(typeQuery)) {\n const result = getDocumentReferenceFromTypeQuery(typeQuery, filePath, pluginInfo);\n foundNode = result.node;\n referencingNode = typeQuery;\n }\n\n if (!foundNode) {\n warnings.push({\n message:\n `Could not find reference for \"${referencingNode.getText()}\".\\n` +\n 'If this is unexpected, please file an issue describing your case.',\n file: filePath,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n if (\n !foundNode ||\n !ts.isCallExpression(foundNode) ||\n (!ts.isNoSubstitutionTemplateLiteral(foundNode.arguments[0]) &&\n !ts.isStringLiteral(foundNode.arguments[0]))\n ) {\n warnings.push({\n message:\n `The referenced document of \"${referencingNode.getText()}\" contains no document string literal.\\n` +\n 'If this is unexpected, please file an issue describing your case.',\n file: filePath,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n const fragments: FragmentDefinitionNode[] = [];\n const operation = foundNode.arguments[0].getText().slice(1, -1);\n if (foundNode.arguments[1] && ts.isArrayLiteralExpression(foundNode.arguments[1])) {\n unrollTadaFragments(foundNode.arguments[1], fragments, pluginInfo);\n }\n\n let document = operation;\n for (const fragment of fragments) document += '\\n\\n' + print(fragment);\n documents[
|
|
1
|
+
{"version":3,"file":"thread-chunk.js","sources":["../../src/commands/generate-persisted/thread.ts"],"sourcesContent":["import * as path from 'node:path';\nimport { print } from '@0no-co/graphql.web';\nimport { Project, ts } from 'ts-morph';\n\nimport type { FragmentDefinitionNode } from '@0no-co/graphql.web';\nimport type { GraphQLSPConfig } from '@gql.tada/internal';\n\nimport {\n init,\n findAllPersistedCallExpressions,\n getDocumentReferenceFromTypeQuery,\n getDocumentReferenceFromDocumentNode,\n unrollTadaFragments,\n} from '@0no-co/graphqlsp/api';\n\nimport { createPluginInfo, getFilePosition } from '../../ts';\nimport { expose } from '../../threads';\n\nimport type { PersistedSignal, PersistedWarning } from './types';\n\nexport interface PersistedParams {\n rootPath: string;\n configPath: string;\n pluginConfig: GraphQLSPConfig;\n}\n\nasync function* _runPersisted(params: PersistedParams): AsyncIterableIterator<PersistedSignal> {\n init({ typescript: ts as any });\n\n const projectPath = path.dirname(params.configPath);\n const project = new Project({ tsConfigFilePath: params.configPath });\n const pluginInfo = createPluginInfo(project, params.pluginConfig, projectPath);\n\n // Filter source files by whether they're under the relevant root path\n const sourceFiles = project.getSourceFiles().filter((sourceFile) => {\n const filePath = path.resolve(projectPath, sourceFile.getFilePath());\n const relative = path.relative(params.rootPath, filePath);\n return !relative.startsWith('..');\n });\n\n yield {\n kind: 'FILE_COUNT',\n fileCount: sourceFiles.length,\n };\n\n for (const { compilerNode: sourceFile } of sourceFiles) {\n const filePath = sourceFile.fileName;\n const documents: Record<string, string> = {};\n const warnings: PersistedWarning[] = [];\n\n const calls = findAllPersistedCallExpressions(sourceFile);\n for (const call of calls) {\n const position = getFilePosition(sourceFile, call.getStart());\n const hashArg = call.arguments[0];\n const docArg = call.arguments[1];\n const typeQuery = call.typeArguments && call.typeArguments[0];\n if (!hashArg || !ts.isStringLiteral(hashArg)) {\n warnings.push({\n message:\n '\"graphql.persisted\" must be called with a string literal as the first argument.',\n file: filePath,\n line: position.line,\n col: position.col,\n });\n continue;\n } else if (!docArg && !typeQuery) {\n warnings.push({\n message:\n '\"graphql.persisted\" is missing a document.\\n' +\n 'This may be passed as a generic such as `graphql.persisted<typeof document>` or as the second argument.',\n file: filePath,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n let foundNode: ts.CallExpression | null = null;\n let referencingNode: ts.Node = call;\n if (docArg && (ts.isCallExpression(docArg) || ts.isIdentifier(docArg))) {\n const result = getDocumentReferenceFromDocumentNode(docArg, filePath, pluginInfo);\n foundNode = result.node;\n referencingNode = docArg;\n } else if (typeQuery && ts.isTypeQueryNode(typeQuery)) {\n const result = getDocumentReferenceFromTypeQuery(typeQuery, filePath, pluginInfo);\n foundNode = result.node;\n referencingNode = typeQuery;\n }\n\n if (!foundNode) {\n warnings.push({\n message:\n `Could not find reference for \"${referencingNode.getText()}\".\\n` +\n 'If this is unexpected, please file an issue describing your case.',\n file: filePath,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n if (\n !foundNode ||\n !ts.isCallExpression(foundNode) ||\n (!ts.isNoSubstitutionTemplateLiteral(foundNode.arguments[0]) &&\n !ts.isStringLiteral(foundNode.arguments[0]))\n ) {\n warnings.push({\n message:\n `The referenced document of \"${referencingNode.getText()}\" contains no document string literal.\\n` +\n 'If this is unexpected, please file an issue describing your case.',\n file: filePath,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n const fragments: FragmentDefinitionNode[] = [];\n const operation = foundNode.arguments[0].getText().slice(1, -1);\n if (foundNode.arguments[1] && ts.isArrayLiteralExpression(foundNode.arguments[1])) {\n unrollTadaFragments(foundNode.arguments[1], fragments, pluginInfo);\n }\n\n let document = operation;\n for (const fragment of fragments) document += '\\n\\n' + print(fragment);\n documents[hashArg.getText().slice(1, -1)] = document;\n }\n\n yield {\n kind: 'FILE_PERSISTED',\n filePath,\n documents,\n warnings,\n };\n }\n}\n\nexport const runPersisted = expose(_runPersisted);\n"],"names":["runPersisted","expose","async","_runPersisted","params","init","typescript","ts","projectPath","path","dirname","configPath","project","Project","tsConfigFilePath","pluginInfo","createPluginInfo","pluginConfig","sourceFiles","getSourceFiles","filter","sourceFile","filePath","resolve","getFilePath","relative","rootPath","startsWith","kind","fileCount","length","compilerNode","fileName","documents","warnings","calls","findAllPersistedCallExpressions","call","position","getFilePosition","getStart","hashArg","arguments","docArg","typeQuery","typeArguments","isStringLiteral","push","message","file","line","col","foundNode","referencingNode","isCallExpression","isIdentifier","getDocumentReferenceFromDocumentNode","node","isTypeQueryNode","getDocumentReferenceFromTypeQuery","getText","isNoSubstitutionTemplateLiteral","fragments","operation","slice","isArrayLiteralExpression","unrollTadaFragments","document","fragment","print"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA0IaA,IAAeC,EAAMA,QAhHlCC,gBAAgBC,cAAcC;EAC5BC,OAAK;IAAEC,YAAYC,EAAAA;;EAEnB,IAAMC,IAAcC,EAAKC,QAAQN,EAAOO;EACxC,IAAMC,IAAU,IAAIC,UAAQ;IAAEC,kBAAkBV,EAAOO;;EACvD,IAAMI,IAAaC,EAAAA,iBAAiBJ,GAASR,EAAOa,cAAcT;EAGlE,IAAMU,IAAcN,EAAQO,iBAAiBC,QAAQC;IACnD,IAAMC,IAAWb,EAA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EhB;AACF;MAEA,KACGC,MACA7C,KAAG+C,iBAAiBF,OACnB7C,EAAEA,GAACsD,gCAAgCT,EAAUV,UAAU,QACtDnC,EAAEA,GAACuC,gBAAgBM,EAAUV,UAAU,KAC1C;QACAR,EAASa,KAAK;UACZC,SACG,+BAA8BK,EAAgBO;UAEjDX,MAAM3B;UACN4B,MAAMZ,EAASY;UACfC,KAAKb,EAASa;;QAEhB;AACF;MAEA,IAAMW,IAAsC;MAC5C,IAAMC,IAAYX,EAAUV,UAAU,GAAGkB,UAAUI,MAAM,IAAI;MAC7D,IAAIZ,EAAUV,UAAU,MAAMnC,EAAAA,GAAG0D,yBAAyBb,EAAUV,UAAU;QAC5EwB,EAAmBA,oBAACd,EAAUV,UAAU,IAAIoB,GAAW/C;;MAGzD,IAAIoD,IAAWJ;MACf,KAAK,IAAMK,KAAYN;QAAWK,KAAY,SAASE,MAAMD;;MAC7DnC,EAAUQ,EAAQmB,UAAUI,MAAM,IAAI,MAAMG;AAC9C;UAEM;MACJvC,MAAM;MACNN;MACAW;MACAC;;AAEJ;AACF;;"}
|
|
@@ -179,24 +179,24 @@ var p = o((async function* _runPersisted(o) {
|
|
|
179
179
|
var S = [];
|
|
180
180
|
var y = r(p);
|
|
181
181
|
for (var b of y) {
|
|
182
|
-
var
|
|
183
|
-
var
|
|
182
|
+
var D = u(p, b.getStart());
|
|
183
|
+
var J = b.arguments[0];
|
|
184
184
|
var V = b.arguments[1];
|
|
185
185
|
var F = b.typeArguments && b.typeArguments[0];
|
|
186
|
-
if (!
|
|
186
|
+
if (!J || !i.isStringLiteral(J)) {
|
|
187
187
|
S.push({
|
|
188
188
|
message: '"graphql.persisted" must be called with a string literal as the first argument.',
|
|
189
189
|
file: d,
|
|
190
|
-
line:
|
|
191
|
-
col:
|
|
190
|
+
line: D.line,
|
|
191
|
+
col: D.col
|
|
192
192
|
});
|
|
193
193
|
continue;
|
|
194
194
|
} else if (!V && !F) {
|
|
195
195
|
S.push({
|
|
196
196
|
message: '"graphql.persisted" is missing a document.\nThis may be passed as a generic such as `graphql.persisted<typeof document>` or as the second argument.',
|
|
197
197
|
file: d,
|
|
198
|
-
line:
|
|
199
|
-
col:
|
|
198
|
+
line: D.line,
|
|
199
|
+
col: D.col
|
|
200
200
|
});
|
|
201
201
|
continue;
|
|
202
202
|
}
|
|
@@ -213,8 +213,8 @@ var p = o((async function* _runPersisted(o) {
|
|
|
213
213
|
S.push({
|
|
214
214
|
message: `Could not find reference for "${T.getText()}".\nIf this is unexpected, please file an issue describing your case.`,
|
|
215
215
|
file: d,
|
|
216
|
-
line:
|
|
217
|
-
col:
|
|
216
|
+
line: D.line,
|
|
217
|
+
col: D.col
|
|
218
218
|
});
|
|
219
219
|
continue;
|
|
220
220
|
}
|
|
@@ -222,8 +222,8 @@ var p = o((async function* _runPersisted(o) {
|
|
|
222
222
|
S.push({
|
|
223
223
|
message: `The referenced document of "${T.getText()}" contains no document string literal.\nIf this is unexpected, please file an issue describing your case.`,
|
|
224
224
|
file: d,
|
|
225
|
-
line:
|
|
226
|
-
col:
|
|
225
|
+
line: D.line,
|
|
226
|
+
col: D.col
|
|
227
227
|
});
|
|
228
228
|
continue;
|
|
229
229
|
}
|
|
@@ -236,7 +236,7 @@ var p = o((async function* _runPersisted(o) {
|
|
|
236
236
|
for (var E of C) {
|
|
237
237
|
x += "\n\n" + print(E);
|
|
238
238
|
}
|
|
239
|
-
h[
|
|
239
|
+
h[J.getText().slice(1, -1)] = x;
|
|
240
240
|
}
|
|
241
241
|
yield {
|
|
242
242
|
kind: "FILE_PERSISTED",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-chunk.mjs","sources":["../../src/commands/generate-persisted/thread.ts"],"sourcesContent":["import * as path from 'node:path';\nimport { print } from '@0no-co/graphql.web';\nimport { Project, ts } from 'ts-morph';\n\nimport type { FragmentDefinitionNode } from '@0no-co/graphql.web';\nimport type { GraphQLSPConfig } from '@gql.tada/internal';\n\nimport {\n init,\n findAllPersistedCallExpressions,\n getDocumentReferenceFromTypeQuery,\n getDocumentReferenceFromDocumentNode,\n unrollTadaFragments,\n} from '@0no-co/graphqlsp/api';\n\nimport { createPluginInfo, getFilePosition } from '../../ts';\nimport { expose } from '../../threads';\n\nimport type { PersistedSignal, PersistedWarning } from './types';\n\nexport interface PersistedParams {\n rootPath: string;\n configPath: string;\n pluginConfig: GraphQLSPConfig;\n}\n\nasync function* _runPersisted(params: PersistedParams): AsyncIterableIterator<PersistedSignal> {\n init({ typescript: ts as any });\n\n const projectPath = path.dirname(params.configPath);\n const project = new Project({ tsConfigFilePath: params.configPath });\n const pluginInfo = createPluginInfo(project, params.pluginConfig, projectPath);\n\n // Filter source files by whether they're under the relevant root path\n const sourceFiles = project.getSourceFiles().filter((sourceFile) => {\n const filePath = path.resolve(projectPath, sourceFile.getFilePath());\n const relative = path.relative(params.rootPath, filePath);\n return !relative.startsWith('..');\n });\n\n yield {\n kind: 'FILE_COUNT',\n fileCount: sourceFiles.length,\n };\n\n for (const { compilerNode: sourceFile } of sourceFiles) {\n const filePath = sourceFile.fileName;\n const documents: Record<string, string> = {};\n const warnings: PersistedWarning[] = [];\n\n const calls = findAllPersistedCallExpressions(sourceFile);\n for (const call of calls) {\n const position = getFilePosition(sourceFile, call.getStart());\n const hashArg = call.arguments[0];\n const docArg = call.arguments[1];\n const typeQuery = call.typeArguments && call.typeArguments[0];\n if (!hashArg || !ts.isStringLiteral(hashArg)) {\n warnings.push({\n message:\n '\"graphql.persisted\" must be called with a string literal as the first argument.',\n file: filePath,\n line: position.line,\n col: position.col,\n });\n continue;\n } else if (!docArg && !typeQuery) {\n warnings.push({\n message:\n '\"graphql.persisted\" is missing a document.\\n' +\n 'This may be passed as a generic such as `graphql.persisted<typeof document>` or as the second argument.',\n file: filePath,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n let foundNode: ts.CallExpression | null = null;\n let referencingNode: ts.Node = call;\n if (docArg && (ts.isCallExpression(docArg) || ts.isIdentifier(docArg))) {\n const result = getDocumentReferenceFromDocumentNode(docArg, filePath, pluginInfo);\n foundNode = result.node;\n referencingNode = docArg;\n } else if (typeQuery && ts.isTypeQueryNode(typeQuery)) {\n const result = getDocumentReferenceFromTypeQuery(typeQuery, filePath, pluginInfo);\n foundNode = result.node;\n referencingNode = typeQuery;\n }\n\n if (!foundNode) {\n warnings.push({\n message:\n `Could not find reference for \"${referencingNode.getText()}\".\\n` +\n 'If this is unexpected, please file an issue describing your case.',\n file: filePath,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n if (\n !foundNode ||\n !ts.isCallExpression(foundNode) ||\n (!ts.isNoSubstitutionTemplateLiteral(foundNode.arguments[0]) &&\n !ts.isStringLiteral(foundNode.arguments[0]))\n ) {\n warnings.push({\n message:\n `The referenced document of \"${referencingNode.getText()}\" contains no document string literal.\\n` +\n 'If this is unexpected, please file an issue describing your case.',\n file: filePath,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n const fragments: FragmentDefinitionNode[] = [];\n const operation = foundNode.arguments[0].getText().slice(1, -1);\n if (foundNode.arguments[1] && ts.isArrayLiteralExpression(foundNode.arguments[1])) {\n unrollTadaFragments(foundNode.arguments[1], fragments, pluginInfo);\n }\n\n let document = operation;\n for (const fragment of fragments) document += '\\n\\n' + print(fragment);\n documents[
|
|
1
|
+
{"version":3,"file":"thread-chunk.mjs","sources":["../../src/commands/generate-persisted/thread.ts"],"sourcesContent":["import * as path from 'node:path';\nimport { print } from '@0no-co/graphql.web';\nimport { Project, ts } from 'ts-morph';\n\nimport type { FragmentDefinitionNode } from '@0no-co/graphql.web';\nimport type { GraphQLSPConfig } from '@gql.tada/internal';\n\nimport {\n init,\n findAllPersistedCallExpressions,\n getDocumentReferenceFromTypeQuery,\n getDocumentReferenceFromDocumentNode,\n unrollTadaFragments,\n} from '@0no-co/graphqlsp/api';\n\nimport { createPluginInfo, getFilePosition } from '../../ts';\nimport { expose } from '../../threads';\n\nimport type { PersistedSignal, PersistedWarning } from './types';\n\nexport interface PersistedParams {\n rootPath: string;\n configPath: string;\n pluginConfig: GraphQLSPConfig;\n}\n\nasync function* _runPersisted(params: PersistedParams): AsyncIterableIterator<PersistedSignal> {\n init({ typescript: ts as any });\n\n const projectPath = path.dirname(params.configPath);\n const project = new Project({ tsConfigFilePath: params.configPath });\n const pluginInfo = createPluginInfo(project, params.pluginConfig, projectPath);\n\n // Filter source files by whether they're under the relevant root path\n const sourceFiles = project.getSourceFiles().filter((sourceFile) => {\n const filePath = path.resolve(projectPath, sourceFile.getFilePath());\n const relative = path.relative(params.rootPath, filePath);\n return !relative.startsWith('..');\n });\n\n yield {\n kind: 'FILE_COUNT',\n fileCount: sourceFiles.length,\n };\n\n for (const { compilerNode: sourceFile } of sourceFiles) {\n const filePath = sourceFile.fileName;\n const documents: Record<string, string> = {};\n const warnings: PersistedWarning[] = [];\n\n const calls = findAllPersistedCallExpressions(sourceFile);\n for (const call of calls) {\n const position = getFilePosition(sourceFile, call.getStart());\n const hashArg = call.arguments[0];\n const docArg = call.arguments[1];\n const typeQuery = call.typeArguments && call.typeArguments[0];\n if (!hashArg || !ts.isStringLiteral(hashArg)) {\n warnings.push({\n message:\n '\"graphql.persisted\" must be called with a string literal as the first argument.',\n file: filePath,\n line: position.line,\n col: position.col,\n });\n continue;\n } else if (!docArg && !typeQuery) {\n warnings.push({\n message:\n '\"graphql.persisted\" is missing a document.\\n' +\n 'This may be passed as a generic such as `graphql.persisted<typeof document>` or as the second argument.',\n file: filePath,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n let foundNode: ts.CallExpression | null = null;\n let referencingNode: ts.Node = call;\n if (docArg && (ts.isCallExpression(docArg) || ts.isIdentifier(docArg))) {\n const result = getDocumentReferenceFromDocumentNode(docArg, filePath, pluginInfo);\n foundNode = result.node;\n referencingNode = docArg;\n } else if (typeQuery && ts.isTypeQueryNode(typeQuery)) {\n const result = getDocumentReferenceFromTypeQuery(typeQuery, filePath, pluginInfo);\n foundNode = result.node;\n referencingNode = typeQuery;\n }\n\n if (!foundNode) {\n warnings.push({\n message:\n `Could not find reference for \"${referencingNode.getText()}\".\\n` +\n 'If this is unexpected, please file an issue describing your case.',\n file: filePath,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n if (\n !foundNode ||\n !ts.isCallExpression(foundNode) ||\n (!ts.isNoSubstitutionTemplateLiteral(foundNode.arguments[0]) &&\n !ts.isStringLiteral(foundNode.arguments[0]))\n ) {\n warnings.push({\n message:\n `The referenced document of \"${referencingNode.getText()}\" contains no document string literal.\\n` +\n 'If this is unexpected, please file an issue describing your case.',\n file: filePath,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n const fragments: FragmentDefinitionNode[] = [];\n const operation = foundNode.arguments[0].getText().slice(1, -1);\n if (foundNode.arguments[1] && ts.isArrayLiteralExpression(foundNode.arguments[1])) {\n unrollTadaFragments(foundNode.arguments[1], fragments, pluginInfo);\n }\n\n let document = operation;\n for (const fragment of fragments) document += '\\n\\n' + print(fragment);\n documents[hashArg.getText().slice(1, -1)] = document;\n }\n\n yield {\n kind: 'FILE_PERSISTED',\n filePath,\n documents,\n warnings,\n };\n }\n}\n\nexport const runPersisted = expose(_runPersisted);\n"],"names":["runPersisted","expose","async","_runPersisted","params","init","typescript","ts","projectPath","path","dirname","configPath","project","Project","tsConfigFilePath","pluginInfo","createPluginInfo","pluginConfig","sourceFiles","getSourceFiles","filter","sourceFile","filePath","resolve","getFilePath","relative","rootPath","startsWith","kind","fileCount","length","compilerNode","fileName","documents","warnings","calls","findAllPersistedCallExpressions","call","position","getFilePosition","getStart","hashArg","arguments","docArg","typeQuery","typeArguments","isStringLiteral","push","message","file","line","col","foundNode","referencingNode","isCallExpression","isIdentifier","getDocumentReferenceFromDocumentNode","node","isTypeQueryNode","getDocumentReferenceFromTypeQuery","getText","isNoSubstitutionTemplateLiteral","fragments","operation","slice","isArrayLiteralExpression","unrollTadaFragments","document","fragment","print"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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