Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move check for graphql string in source files to language plugin #2811

Closed
1 change: 1 addition & 0 deletions packages/relay-compiler/bin/RelayCompilerMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ function getCodegenRunner(config: Config): CodegenRunner {
const sourceWriterName = outputExtension;
const sourceModuleParser = RelaySourceModuleParser(
languagePlugin.findGraphQLTags,
languagePlugin.getFileFilter,
);
const providedArtifactDirectory = config.artifactDirectory;
const artifactDirectory =
Expand Down
13 changes: 9 additions & 4 deletions packages/relay-compiler/core/RelaySourceModuleParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ import type {FileFilter} from '../codegen/CodegenWatcher';
import type {GraphQLTagFinder} from '../language/RelayLanguagePluginInterface';
import type {DocumentNode} from 'graphql';

export type GetFileFilter = (baseDir: string) => FileFilter;

export type SourceModuleParser = {|
getFileFilter: (baseDir: string) => FileFilter,
getFileFilter: GetFileFilter,
getParser: (baseDir: string) => ASTCache,
parseFile: (baseDir: string, file: File) => ?DocumentNode,
parseFileWithSources: (
Expand All @@ -42,7 +44,10 @@ export type SourceModuleParser = {|

const parseGraphQL = Profiler.instrument(GraphQL.parse, 'GraphQL.parse');

module.exports = (tagFinder: GraphQLTagFinder): SourceModuleParser => {
module.exports = (
tagFinder: GraphQLTagFinder,
getFileFilter?: GetFileFilter,
): SourceModuleParser => {
const memoizedTagFinder = memoizedFind.bind(null, tagFinder);

function parseFile(baseDir: string, file: File): ?DocumentNode {
Expand Down Expand Up @@ -104,7 +109,7 @@ module.exports = (tagFinder: GraphQLTagFinder): SourceModuleParser => {
});
}

function getFileFilter(baseDir: string): FileFilter {
function defaultGetFileFilter(baseDir: string): FileFilter {
return (file: File) => {
const filePath = path.join(baseDir, file.relPath);
let text = '';
Expand All @@ -123,7 +128,7 @@ module.exports = (tagFinder: GraphQLTagFinder): SourceModuleParser => {

return {
getParser,
getFileFilter,
getFileFilter: getFileFilter || defaultGetFileFilter,
parseFile,
parseFileWithSources,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type {
} from '../codegen/CodegenRunner';
import type {IRTransform} from '../core/CompilerContext';
import type {GeneratedDefinition, Root, Fragment} from '../core/IR';
import type {GetFileFilter} from '../core/RelaySourceModuleParser';
import type {Schema} from '../core/Schema';
import type {ScalarTypeMapping} from './javascript/RelayFlowTypeTransformers';
import type {GeneratedNode} from 'relay-runtime';
Expand All @@ -46,6 +47,7 @@ export type PluginInterface = {
keepExtraFile?: KeepExtraFileFn,
schemaExtensions?: $ReadOnlyArray<string>,
getModuleName?: (operationName: string) => string,
getFileFilter?: GetFileFilter,
...
};

Expand Down