@graphql-codegen/near-operation-file-preset
Version:
GraphQL Code Generator preset for generating operation code near the operation file
30 lines (29 loc) • 1.33 kB
TypeScript
import { DocumentNode, FragmentDefinitionNode, GraphQLSchema } from 'graphql';
import { Types } from '@graphql-codegen/plugin-helpers';
import { FragmentImport, ImportDeclaration, LoadedFragment, ParsedConfig } from '@graphql-codegen/visitor-plugin-common';
import { DocumentImportResolverOptions } from './resolve-document-imports.js';
export interface NearOperationFileParsedConfig extends ParsedConfig {
importTypesNamespace?: string;
dedupeOperationSuffix: boolean;
omitOperationSuffix: boolean;
fragmentVariablePrefix: string;
fragmentVariableSuffix: string;
}
export type FragmentRegistry = {
[fragmentName: string]: {
filePath: string;
onType: string;
node: FragmentDefinitionNode;
imports: Array<FragmentImport>;
possibleTypes: string[];
};
};
/**
* Builds a fragment "resolver" that collects `externalFragments` definitions and `fragmentImportStatements`
*/
export default function buildFragmentResolver<T>(collectorOptions: DocumentImportResolverOptions, presetOptions: Types.PresetFnArgs<T>, schemaObject: GraphQLSchema, dedupeFragments?: boolean): (generatedFilePath: string, documentFileContent: DocumentNode) => {
externalFragments: LoadedFragment<{
level: number;
}>[];
fragmentImports: ImportDeclaration<FragmentImport>[];
};