From 01dd94e9e9339ce4fa1d761a3019d71ceb9cbbdf Mon Sep 17 00:00:00 2001 From: Edvin Eriksson Date: Wed, 7 Feb 2018 11:29:59 -0800 Subject: [PATCH] Add support for client schemas Summary: Makes it possible to have a client schema. Not sure if it should be changed to only allow one schema file or if this is good enough. Forked kassens changes and made some fixes to get it to work. Closes https://github.com/facebook/relay/pull/2264 Reviewed By: kassens Differential Revision: D6770734 Pulled By: jstejada fbshipit-source-id: 9de8f68dc708b6603475d91ae3cf8d19a163a032 --- .../relay-compiler/bin/RelayCompilerBin.js | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/packages/relay-compiler/bin/RelayCompilerBin.js b/packages/relay-compiler/bin/RelayCompilerBin.js index 6826d75606da..2f2e189c7822 100644 --- a/packages/relay-compiler/bin/RelayCompilerBin.js +++ b/packages/relay-compiler/bin/RelayCompilerBin.js @@ -17,6 +17,7 @@ const { CodegenRunner, ConsoleReporter, WatchmanClient, + DotGraphQLParser, } = require('graphql-compiler'); const RelayJSModuleParser = require('../core/RelayJSModuleParser'); @@ -130,22 +131,43 @@ Ensure that one such file exists in ${srcDir} or its parents. const useWatchman = options.watchman && (await WatchmanClient.isAvailable()); + const schema = getSchema(schemaPath); const parserConfigs = { - default: { + js: { baseDir: srcDir, getFileFilter: RelayJSModuleParser.getFileFilter, getParser: RelayJSModuleParser.getParser, - getSchema: () => getSchema(schemaPath), + getSchema: () => schema, watchmanExpression: useWatchman ? buildWatchExpression(options) : null, filepaths: useWatchman ? null : getFilepathsFromGlob(srcDir, options), }, + graphql: { + baseDir: srcDir, + getParser: DotGraphQLParser.getParser, + getSchema: () => schema, + watchmanExpression: useWatchman + ? buildWatchExpression({ + extensions: ['graphql'], + include: options.include, + exclude: options.exclude, + }) + : null, + filepaths: useWatchman + ? null + : getFilepathsFromGlob(srcDir, { + extensions: ['graphql'], + include: options.include, + exclude: options.exclude, + }), + }, }; const writerConfigs = { - default: { + js: { getWriter: getRelayFileWriter(srcDir), isGeneratedFile: (filePath: string) => filePath.endsWith('.js') && filePath.includes('__generated__'), - parser: 'default', + parser: 'js', + baseParsers: ['graphql'], }, }; const codegenRunner = new CodegenRunner({