Skip to content

Commit 88b21f4

Browse files
committed
[FEI-6084] if input attr has default value, make it nullable
1 parent 6dcea5b commit 88b21f4

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"bin": {
55
"graphql-flow": "./dist/cli/run.js"
66
},
7+
"jest": {
8+
"testPathIgnorePatterns": ["dist"]
9+
},
710
"scripts": {
811
"test": "jest",
912
"publish:ci": "yarn run build && changeset publish",

src/__test__/graphql-flow.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ describe("graphql-flow generation", () => {
621621
- JEDI*/
622622
"NEW_HOPE" | "EMPIRE" | "JEDI"> | null | undefined;
623623
candies: number;
624-
friendly?: boolean;
624+
friendly?: boolean | null | undefined;
625625
};
626626
},
627627
response: {

src/generateVariablesType.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const inputObjectToFlow = (
3131
vbl.description,
3232
maybeOptionalObjectTypeProperty(
3333
vbl.name,
34-
inputRefToFlow(ctx, vbl.type),
34+
inputRefToFlow(ctx, vbl.type, vbl.defaultValue != null),
3535
),
3636
),
3737
),
@@ -58,9 +58,11 @@ export const maybeOptionalObjectTypeProperty = (
5858
export const inputRefToFlow = (
5959
ctx: Context,
6060
inputRef: IntrospectionInputTypeRef,
61+
hasDefaultValue = false,
6162
): babelTypes.TSType => {
6263
if (inputRef.kind === "NON_NULL") {
63-
return _inputRefToFlow(ctx, inputRef.ofType);
64+
const result = _inputRefToFlow(ctx, inputRef.ofType);
65+
return hasDefaultValue ? nullableType(result) : result;
6466
}
6567
const result = _inputRefToFlow(ctx, inputRef);
6668
return transferLeadingComments(result, nullableType(result));

0 commit comments

Comments
 (0)