Skip to content

Commit

Permalink
Use languagePlugin for writer
Browse files Browse the repository at this point in the history
  • Loading branch information
danielholmes committed Dec 7, 2018
1 parent 0802409 commit 135a508
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
14 changes: 4 additions & 10 deletions dist/getWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ exports.default = getWriter;

var _relayCompiler = require("relay-compiler");

var _formatGeneratedModule = _interopRequireDefault(require("relay-compiler/lib/formatGeneratedModule"));

var _RelayFlowGenerator = _interopRequireDefault(require("relay-compiler/lib/RelayFlowGenerator"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
Expand All @@ -24,7 +18,7 @@ const commonTransforms = _relayCompiler.IRTransforms.commonTransforms,
queryTransforms = _relayCompiler.IRTransforms.queryTransforms,
schemaExtensions = _relayCompiler.IRTransforms.schemaExtensions;

function getWriter(baseDir) {
function getWriter(languagePlugin, baseDir) {
return (config, ...args) => {
const cfg = typeof config === 'object' ? config : {
onlyValidate: config,
Expand All @@ -45,11 +39,11 @@ function getWriter(baseDir) {
queryTransforms
},
customScalars: {},
formatModule: _formatGeneratedModule.default,
formatModule: languagePlugin.formatModule,
inputFieldWhiteListForFlow: [],
schemaExtensions,
extension: 'js',
typeGenerator: _RelayFlowGenerator.default,
extension: languagePlugin.outputExtension,
typeGenerator: languagePlugin.typeGenerator,
useHaste: false
}
}));
Expand Down
7 changes: 5 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

var _relayCompiler = require("relay-compiler");

var _RelayLanguagePluginJavaScript = _interopRequireDefault(require("relay-compiler/lib/RelayLanguagePluginJavaScript"));

var _graphqlCompiler = require("graphql-compiler");

var _fs = _interopRequireDefault(require("fs"));
Expand Down Expand Up @@ -29,7 +31,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
// Was using a ConsoleReporter with quiet true (which is essentially a no-op)
// This implements graphql-compiler GraphQLReporter
// https://github.com/facebook/relay/blob/v1.7.0/packages/graphql-compiler/reporters/GraphQLReporter.js
// Not familiar enough with flow yet to get that working
// Wasn't able to find a way to import the GraphQLReporter interface to declare that it is implemented
class TemporaryReporter {
reportMessage(message) {// process.stdout.write('Report message: ' + message + '\n');
}
Expand Down Expand Up @@ -110,7 +112,8 @@ class RelayCompilerWebpackPlugin {
this.parserConfigs.js.baseDir = options.src;
this.parserConfigs.js.getSchema = schemaFn;
this.parserConfigs.js.filepaths = (0, _getFilepathsFromGlob.default)(options.src, fileOptions);
this.writerConfigs.js.getWriter = (0, _getWriter.default)(options.src);
const languagePlugin = (0, _RelayLanguagePluginJavaScript.default)();
this.writerConfigs.js.getWriter = (0, _getWriter.default)(languagePlugin, options.src);
this.parserConfigs.graphql.baseDir = options.src;
this.parserConfigs.graphql.getSchema = schemaFn;
this.parserConfigs.graphql.filepaths = (0, _getFilepathsFromGlob.default)(options.src, _objectSpread({}, fileOptions, {
Expand Down
10 changes: 4 additions & 6 deletions src/getWriter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { FileWriter, IRTransforms } from 'relay-compiler'
import formatGeneratedModule from 'relay-compiler/lib/formatGeneratedModule'
import RelayFlowGenerator from 'relay-compiler/lib/RelayFlowGenerator'
import type { Map } from 'immutable'
import type { GraphQLSchema } from 'graphql'

Expand All @@ -22,7 +20,7 @@ interface WriterConfig {
reporter: any;
}

export default function getWriter (baseDir: string) {
export default function getWriter (languagePlugin: any, baseDir: string) {
return (config: WriterConfig | boolean, ...args) => {
const cfg =
typeof config === 'object'
Expand All @@ -47,11 +45,11 @@ export default function getWriter (baseDir: string) {
queryTransforms
},
customScalars: {},
formatModule: formatGeneratedModule,
formatModule: languagePlugin.formatModule,
inputFieldWhiteListForFlow: [],
schemaExtensions,
extension: 'js',
typeGenerator: RelayFlowGenerator,
extension: languagePlugin.outputExtension,
typeGenerator: languagePlugin.typeGenerator,
useHaste: false
}
})
Expand Down
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow

import { Runner, JSModuleParser } from 'relay-compiler'
import RelayLanguagePluginJavaScript from 'relay-compiler/lib/RelayLanguagePluginJavaScript'
import { DotGraphQLParser } from 'graphql-compiler'

import fs from 'fs'
Expand All @@ -17,7 +18,7 @@ import type { Compiler } from 'webpack'
// Was using a ConsoleReporter with quiet true (which is essentially a no-op)
// This implements graphql-compiler GraphQLReporter
// https://github.com/facebook/relay/blob/v1.7.0/packages/graphql-compiler/reporters/GraphQLReporter.js
// Not familiar enough with flow yet to get that working
// Wasn't able to find a way to import the GraphQLReporter interface to declare that it is implemented
class TemporaryReporter {
reportMessage (message: string): void {
// process.stdout.write('Report message: ' + message + '\n');
Expand Down Expand Up @@ -124,7 +125,8 @@ class RelayCompilerWebpackPlugin {
options.src,
fileOptions
)
this.writerConfigs.js.getWriter = getWriter(options.src)
const languagePlugin = RelayLanguagePluginJavaScript()
this.writerConfigs.js.getWriter = getWriter(languagePlugin, options.src)

this.parserConfigs.graphql.baseDir = options.src
this.parserConfigs.graphql.getSchema = schemaFn
Expand Down

0 comments on commit 135a508

Please sign in to comment.