Skip to content

Commit 2032a0c

Browse files
fix: exclude external service documents from main client type generation (#31)
External service document files were being incorrectly included in the main client type generation and validated against the local server schema, causing validation failures when external service queries referenced fields not present in the local schema. This fix enhances the scanDocs function to filter out documents that match external service document patterns, ensuring they are only validated against their respective external schemas. Resolves GraphQL Document Validation errors like: - Cannot query field "countries" on type "Query" - Cannot query field "country" on type "Query"
1 parent 9d416cb commit 2032a0c

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/utils/index.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,34 @@ export async function scanSchemas(nitro: Nitro) {
173173

174174
export async function scanDocs(nitro: Nitro) {
175175
const files = await scanDir(nitro, nitro.options.rootDir, nitro.graphql.dir.client, '**/*.graphql')
176-
// Filter out files in the external directory
176+
177+
// Get external service document patterns to filter out
178+
const externalServices = nitro.options.graphql?.externalServices || []
179+
const externalPatterns = externalServices.flatMap(service => service.documents || [])
180+
181+
// Filter out files in the external directory and files matching external service patterns
177182
return files
178183
.filter(f => !f.path.startsWith('external/'))
184+
.filter((f) => {
185+
// Check if this file matches any external service document patterns
186+
const relativePath = f.path
187+
188+
for (const pattern of externalPatterns) {
189+
// Remove the leading 'app/graphql/' from patterns to match relative paths
190+
const cleanPattern = pattern.replace(/^app\/graphql\//, '')
191+
192+
// Extract directory name from pattern for matching
193+
const patternDir = cleanPattern.split('/')[0]
194+
const fileDir = relativePath.split('/')[0]
195+
196+
// If the file is in a directory that's part of an external service pattern, exclude it
197+
if (patternDir === fileDir) {
198+
return false
199+
}
200+
}
201+
202+
return true
203+
})
179204
.map(f => f.fullPath)
180205
}
181206

0 commit comments

Comments
 (0)