Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit 7679ee9

Browse files
alloykastermester
authored andcommitted
[PluginInterface] Add type generator options.
1 parent 376bf95 commit 7679ee9

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"main": "index.js",
66
"scripts": {
77
"build": "rm -rf lib && tsc",
8-
"test": "node bin/relay-compiler.js --schema test/schema.graphql --src test/ --outputDir __generated__",
8+
"relay": "node bin/relay-compiler.js --schema test/schema.graphql --src test/ --outputDir __generated__",
9+
"test": "yarn type-check && jest",
910
"type-check": "tsc --noEmit --pretty",
1011
"prettier": "prettier --write '{src,types}/**/*.ts'",
1112
"sync-fixtures": "rsync -avh --delete --stats --progress ../relay/packages/relay-compiler/language/javascript/__tests__/fixtures/flow-generator/*.graphql test/fixtures/type-generator"

src/TypeScriptGenerator.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
transformScalarType,
88
transformInputType,
99
ScalarTypeMapping,
10-
Options,
1110
State
1211
} from "./TypeScriptTypeTransformers";
1312
import {
@@ -25,6 +24,8 @@ import {
2524
Root
2625
} from "relay-compiler/lib/GraphQLCompilerPublic";
2726

27+
import { TypeGeneratorOptions } from 'relay-compiler'
28+
2829
const { isAbstractType } = SchemaUtils;
2930

3031
export const generate: TypeGenerator["generate"] = (node, options) => {
@@ -276,15 +277,15 @@ function importTypes(names: string[], fromModule: string): ts.Statement {
276277
);
277278
}
278279

279-
function createVisitor(options: Options) {
280+
function createVisitor(options: TypeGeneratorOptions) {
280281
const state: State = {
281282
customScalars: options.customScalars,
282283
enumsHasteModule: options.enumsHasteModule,
283284
existingFragmentNames: options.existingFragmentNames,
284285
inputFieldWhiteList: options.inputFieldWhiteList,
285286
relayRuntimeModule: options.relayRuntimeModule,
286-
getGeneratedDirectory: options.getGeneratedDirectory,
287-
destinationDirectory: options.destinationDirectory,
287+
getGeneratedDirectory: undefined,
288+
destinationDirectory: undefined,
288289
usedEnums: {},
289290
usedFragments: new Set(),
290291
useHaste: options.useHaste

src/TypeScriptTypeTransformers.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,20 @@ import {
1313
GraphQLUnionType
1414
} from "graphql";
1515

16+
import { TypeGeneratorOptions } from 'relay-compiler'
17+
1618
export type ScalarTypeMapping = {
1719
[type: string]: string;
1820
};
1921

20-
export interface Options {
21-
customScalars: ScalarTypeMapping;
22-
useHaste: boolean;
23-
enumsHasteModule: string | null | undefined;
24-
existingFragmentNames: Set<string>;
25-
inputFieldWhiteList: ReadonlyArray<string>;
26-
relayRuntimeModule: string;
27-
// TODO: Marking these as optional until we determine how we can best make imports work.
28-
getGeneratedDirectory?: (name: string) => CodegenDirectory;
29-
destinationDirectory?: CodegenDirectory;
30-
}
31-
3222
export type State = {
3323
usedEnums: { [name: string]: GraphQLEnumType };
3424
usedFragments: Set<string>;
35-
} & Options;
25+
// TODO: Marking these as optional and moved from ‘options’ to ‘state’ until we determine how we can best make imports
26+
// work.
27+
getGeneratedDirectory?: (name: string) => CodegenDirectory;
28+
destinationDirectory?: CodegenDirectory;
29+
} & TypeGeneratorOptions;
3630

3731
export function transformScalarType(
3832
type: GraphQLType,

types/relay-compiler/language/RelayLanguagePluginInterface.d.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,18 @@ export type FormatModule = (
3535

3636
export type GraphQLTagFinder = (text: string) => Array<GraphQLTag>;
3737

38+
export interface TypeGeneratorOptions {
39+
readonly customScalars: { [type: string]: string },
40+
readonly useHaste: boolean,
41+
readonly enumsHasteModule: string | null,
42+
readonly existingFragmentNames: Set<string>,
43+
readonly inputFieldWhiteList: ReadonlyArray<string>,
44+
readonly relayRuntimeModule: string,
45+
}
46+
3847
export interface TypeGenerator {
3948
transforms: Array<IRTransform>;
40-
// For now this is an opaque set of options communicated from the bin to the plugin.
41-
generate: (node: Root | Fragment, options: any) => string;
49+
generate: (node: Root | Fragment, options: TypeGeneratorOptions) => string;
4250
}
4351

4452
export interface PluginInterface {

0 commit comments

Comments
 (0)