@@ -4,7 +4,7 @@ import { createRequire } from 'module';
44import { resolve } from 'path' ;
55import { cosmiconfig , defaultLoaders } from 'cosmiconfig' ;
66import { GraphQLSchema , GraphQLSchemaExtensions , print } from 'graphql' ;
7- import { GraphQLConfig } from 'graphql-config' ;
7+ import { GraphQLConfig , type Source } from 'graphql-config' ;
88import { createJiti } from 'jiti' ;
99import { env } from 'string-env-interpolation' ;
1010import yaml from 'yaml' ;
@@ -16,6 +16,7 @@ import {
1616 Profiler ,
1717 Types ,
1818} from '@graphql-codegen/plugin-helpers' ;
19+ import type { UnnormalizedTypeDefPointer } from '@graphql-tools/load' ;
1920import { findAndLoadGraphQLConfig } from './graphql-config.js' ;
2021import {
2122 defaultDocumentsLoadOptions ,
@@ -464,18 +465,22 @@ export class CodegenContext {
464465 return addHashToSchema ( loadSchema ( pointer , config ) ) ;
465466 }
466467
467- async loadDocuments ( pointer : Types . OperationDocument [ ] ) : Promise < Types . DocumentFile [ ] > {
468+ async loadDocuments (
469+ pointer : UnnormalizedTypeDefPointer ,
470+ type : 'standard' | 'read-only' ,
471+ ) : Promise < Types . DocumentFile [ ] > {
468472 const config = this . getConfig ( defaultDocumentsLoadOptions ) ;
469473 if ( this . _graphqlConfig ) {
470474 // TODO: pointer won't work here
471475 return addHashToDocumentFiles (
472476 this . _graphqlConfig
473477 . getProject ( this . _project )
474478 . loadDocuments ( pointer , { ...config , ...config . config } ) ,
479+ type ,
475480 ) ;
476481 }
477482
478- return addHashToDocumentFiles ( loadDocuments ( pointer , config ) ) ;
483+ return addHashToDocumentFiles ( loadDocuments ( pointer , config ) , type ) ;
479484 }
480485}
481486
@@ -502,24 +507,27 @@ function addHashToSchema(schemaPromise: Promise<GraphQLSchema>): Promise<GraphQL
502507 } ) ;
503508}
504509
505- function hashDocument ( doc : Types . DocumentFile ) {
506- if ( doc . rawSDL ) {
507- return hashContent ( doc . rawSDL ) ;
508- }
510+ async function addHashToDocumentFiles (
511+ documentFilesPromise : Promise < Source [ ] > ,
512+ type : 'standard' | 'read-only' ,
513+ ) : Promise < Types . DocumentFile [ ] > {
514+ function hashDocument ( doc : Source ) {
515+ if ( doc . rawSDL ) {
516+ return hashContent ( doc . rawSDL ) ;
517+ }
509518
510- if ( doc . document ) {
511- return hashContent ( print ( doc . document ) ) ;
512- }
519+ if ( doc . document ) {
520+ return hashContent ( print ( doc . document ) ) ;
521+ }
513522
514- return null ;
515- }
523+ return null ;
524+ }
516525
517- function addHashToDocumentFiles (
518- documentFilesPromise : Promise < Types . DocumentFile [ ] > ,
519- ) : Promise < Types . DocumentFile [ ] > {
520526 return documentFilesPromise . then ( documentFiles =>
521- documentFiles . map ( doc => {
527+ // Note: `doc` here is technically `Source`, but by the end of the funciton it's `Types.DocumentFile`. This re-declaration makes TypeScript happy.
528+ documentFiles . map ( ( doc : Types . DocumentFile ) : Types . DocumentFile => {
522529 doc . hash = hashDocument ( doc ) ;
530+ doc . type = type ;
523531
524532 return doc ;
525533 } ) ,
0 commit comments