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

Commit d30921c

Browse files
authored
Merge pull request #78 from koddsson/fix-73
Use `optionalInputFields` instead of `inputFieldWhiteList`
2 parents 6704387 + 2373dd3 commit d30921c

File tree

5 files changed

+20
-31
lines changed

5 files changed

+20
-31
lines changed

package.json

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@
4242
"precommit": "lint-staged"
4343
},
4444
"dependencies": {
45-
"immutable": "^3.7.6",
46-
"invariant": "^2.2.2"
45+
"immutable": "^3.8.2",
46+
"invariant": "^2.2.2",
47+
"jest-cli": "^23.6.0"
4748
},
4849
"peerDependencies": {
4950
"@types/react-relay": ">=1.3.9",
5051
"@types/relay-runtime": ">=1.3.5",
5152
"graphql-compiler": "*",
52-
"relay-compiler": "*",
53+
"relay-compiler": ">=1.7.0",
5354
"relay-runtime": "*",
5455
"typescript": ">=2.9.1"
5556
},
@@ -62,30 +63,17 @@
6263
"@types/relay-runtime": "^1.3.1",
6364
"graphql": "^0.13.2",
6465
"husky": "^1.1.0",
65-
"jest": "^22.1.4",
66+
"jest": "^23.6.0",
6667
"lint-staged": "^7.3.0",
6768
"prettier": "^1.10.2",
68-
"relay-compiler":
69-
"https://github.com/alloy/relay/releases/download/v1.6.1-plugin.1/relay-compiler-1.6.1-plugin.1.tgz",
70-
"relay-runtime":
71-
"https://github.com/alloy/relay/releases/download/v1.6.1-plugin.1/relay-runtime-1.6.1-plugin.1.tgz",
72-
"relay-test-utils":
73-
"https://github.com/alloy/relay/releases/download/v1.6.1-plugin.1/relay-test-utils-1.6.1-plugin.1.tgz",
69+
"relay-compiler": "^2.0.0-rc.1",
70+
"relay-runtime": "^2.0.0-rc.1",
71+
"relay-test-utils": "^2.0.0-rc.1",
7472
"ts-jest": "^22.0.1",
7573
"tslint": "^5.11.0",
7674
"tslint-config-prettier": "^1.15.0",
7775
"typescript": "2.8.1"
7876
},
79-
"resolutions": {
80-
"graphql-compiler":
81-
"https://github.com/alloy/relay/releases/download/v1.6.1-plugin.1/graphql-compiler-1.6.1-plugin.1.tgz",
82-
"relay-compiler":
83-
"https://github.com/alloy/relay/releases/download/v1.6.1-plugin.1/relay-compiler-1.6.1-plugin.1.tgz",
84-
"relay-runtime":
85-
"https://github.com/alloy/relay/releases/download/v1.6.1-plugin.1/relay-runtime-1.6.1-plugin.1.tgz",
86-
"relay-test-utils":
87-
"https://github.com/alloy/relay/releases/download/v1.6.1-plugin.1/relay-test-utils-1.6.1-plugin.1.tgz"
88-
},
8977
"jest": {
9078
"transform": {
9179
"^.+\\.tsx?$": "ts-jest"

src/TypeScriptGenerator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ function createVisitor(options: TypeGeneratorOptions) {
285285
existingFragmentNames: options.existingFragmentNames,
286286
generatedInputObjectTypes: {},
287287
generatedFragments: new Set(),
288-
inputFieldWhiteList: options.inputFieldWhiteList,
288+
optionalInputFields: options.optionalInputFields,
289289
relayRuntimeModule: options.relayRuntimeModule,
290290
usedEnums: {},
291291
usedFragments: new Set(),

src/TypeScriptTypeTransformers.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ function transformNonNullableInputType(type: GraphQLInputType, state: State) {
134134

135135
const props = Object.keys(fields)
136136
.map(key => fields[key])
137-
.filter(field => state.inputFieldWhiteList.indexOf(field.name) < 0)
137+
.filter(
138+
field =>
139+
state.optionalInputFields &&
140+
state.optionalInputFields.indexOf(field.name) < 0
141+
)
138142
.map(field => {
139143
const property = ts.createPropertySignature(
140144
[ts.createToken(ts.SyntaxKind.ReadonlyKeyword)],

test/TypeScriptGenerator-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('TypeScriptGenerator with a single artifact directory', () => {
2121
customScalars: {},
2222
enumsHasteModule: null,
2323
existingFragmentNames: new Set(['PhotoFragment']),
24-
inputFieldWhiteList: [],
24+
optionalInputFields: [],
2525
relayRuntimeModule: 'relay-runtime',
2626
useHaste: false,
2727
useSingleArtifactDirectory: true,
@@ -46,7 +46,7 @@ describe('TypeScriptGenerator without a single artifact directory', () => {
4646
customScalars: {},
4747
enumsHasteModule: null,
4848
existingFragmentNames: new Set(['PhotoFragment']),
49-
inputFieldWhiteList: [],
49+
optionalInputFields: [],
5050
relayRuntimeModule: 'relay-runtime',
5151
useHaste: true,
5252
}),

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RelayConcreteNode } from "relay-runtime";
2-
import { Root, Fragment, IRTransform } from "../../graphql-compiler";
2+
import { Fragment, IRTransform, Root } from "../../graphql-compiler";
33

44
export type GraphQLTag = {
55
keyName: string | null;
@@ -33,23 +33,20 @@ export type FormatModule = (
3333
}
3434
) => string;
3535

36-
export type GraphQLTagFinder = (
37-
text: string,
38-
filePath: string
39-
) => Array<GraphQLTag>;
36+
export type GraphQLTagFinder = (text: string, filePath: string) => GraphQLTag[];
4037

4138
export interface TypeGeneratorOptions {
4239
readonly customScalars: { [type: string]: string };
4340
readonly useHaste: boolean;
4441
readonly enumsHasteModule: string | null;
4542
readonly existingFragmentNames: Set<string>;
46-
readonly inputFieldWhiteList: ReadonlyArray<string>;
43+
readonly optionalInputFields: ReadonlyArray<string>;
4744
readonly relayRuntimeModule: string;
4845
readonly useSingleArtifactDirectory: boolean;
4946
}
5047

5148
export interface TypeGenerator {
52-
transforms: Array<IRTransform>;
49+
transforms: IRTransform[];
5350
generate: (node: Root | Fragment, options: TypeGeneratorOptions) => string;
5451
}
5552

0 commit comments

Comments
 (0)