@khanacademy/graphql-flow 3.1.1 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @khanacademy/graphql-flow
2
2
 
3
+ ## 3.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 09f72b5: Fix handling of input objects with required attributes that have a default value
8
+
3
9
  ## 3.1.1
4
10
 
5
11
  ### Patch Changes
@@ -27,7 +27,7 @@ const inputObjectToFlow = (ctx, name) => {
27
27
  return babelTypes.tsLiteralType(babelTypes.stringLiteral(`Unknown input object ${name}`));
28
28
  }
29
29
 
30
- return (0, _utils.maybeAddDescriptionComment)(inputObject.description, (0, _utils.objectTypeFromProperties)(inputObject.inputFields.map(vbl => (0, _utils.maybeAddDescriptionComment)(vbl.description, maybeOptionalObjectTypeProperty(vbl.name, inputRefToFlow(ctx, vbl.type))))));
30
+ return (0, _utils.maybeAddDescriptionComment)(inputObject.description, (0, _utils.objectTypeFromProperties)(inputObject.inputFields.map(vbl => (0, _utils.maybeAddDescriptionComment)(vbl.description, maybeOptionalObjectTypeProperty(vbl.name, inputRefToFlow(ctx, vbl.type, vbl.defaultValue != null))))));
31
31
  };
32
32
 
33
33
  exports.inputObjectToFlow = inputObjectToFlow;
@@ -44,9 +44,11 @@ const maybeOptionalObjectTypeProperty = (name, type) => {
44
44
 
45
45
  exports.maybeOptionalObjectTypeProperty = maybeOptionalObjectTypeProperty;
46
46
 
47
- const inputRefToFlow = (ctx, inputRef) => {
47
+ const inputRefToFlow = (ctx, inputRef, hasDefaultValue = false) => {
48
48
  if (inputRef.kind === "NON_NULL") {
49
- return _inputRefToFlow(ctx, inputRef.ofType);
49
+ const result = _inputRefToFlow(ctx, inputRef.ofType);
50
+
51
+ return hasDefaultValue ? (0, _utils.nullableType)(result) : result;
50
52
  }
51
53
 
52
54
  const result = _inputRefToFlow(ctx, inputRef);
package/package.json CHANGED
@@ -1,9 +1,14 @@
1
1
  {
2
2
  "name": "@khanacademy/graphql-flow",
3
- "version": "3.1.1",
3
+ "version": "3.1.2",
4
4
  "bin": {
5
5
  "graphql-flow": "./dist/cli/run.js"
6
6
  },
7
+ "jest": {
8
+ "testPathIgnorePatterns": [
9
+ "dist"
10
+ ]
11
+ },
7
12
  "scripts": {
8
13
  "test": "jest",
9
14
  "publish:ci": "yarn run build && changeset publish",
@@ -60,6 +60,7 @@ input CharacterInput {
60
60
  friends: [ID!]
61
61
  appearsIn: [Episode!]
62
62
  candies: PositiveNumber!
63
+ friendly: Boolean! = true
63
64
  }
64
65
 
65
66
  type Mutation {
@@ -621,6 +621,7 @@ describe("graphql-flow generation", () => {
621
621
  - JEDI*/
622
622
  "NEW_HOPE" | "EMPIRE" | "JEDI"> | null | undefined;
623
623
  candies: number;
624
+ friendly?: boolean | null | undefined;
624
625
  };
625
626
  },
626
627
  response: {
@@ -31,7 +31,7 @@ export const inputObjectToFlow = (
31
31
  vbl.description,
32
32
  maybeOptionalObjectTypeProperty(
33
33
  vbl.name,
34
- inputRefToFlow(ctx, vbl.type),
34
+ inputRefToFlow(ctx, vbl.type, vbl.defaultValue != null),
35
35
  ),
36
36
  ),
37
37
  ),
@@ -58,9 +58,11 @@ export const maybeOptionalObjectTypeProperty = (
58
58
  export const inputRefToFlow = (
59
59
  ctx: Context,
60
60
  inputRef: IntrospectionInputTypeRef,
61
+ hasDefaultValue = false,
61
62
  ): babelTypes.TSType => {
62
63
  if (inputRef.kind === "NON_NULL") {
63
- return _inputRefToFlow(ctx, inputRef.ofType);
64
+ const result = _inputRefToFlow(ctx, inputRef.ofType);
65
+ return hasDefaultValue ? nullableType(result) : result;
64
66
  }
65
67
  const result = _inputRefToFlow(ctx, inputRef);
66
68
  return transferLeadingComments(result, nullableType(result));