Skip to content

Commit 1e49bd6

Browse files
authored
Merge pull request relay-tools#156 from ascagnel/mutable-mutation-input
feat: make mutation inputs mutable
2 parents 6a735c9 + 2be129b commit 1e49bd6

File tree

2 files changed

+70
-70
lines changed

2 files changed

+70
-70
lines changed

src/TypeScriptTypeTransformers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function transformNonNullableInputType(
133133
state: State
134134
) {
135135
if (schema.isList(type)) {
136-
return ts.createTypeReferenceNode(ts.createIdentifier("ReadonlyArray"), [
136+
return ts.createTypeReferenceNode(ts.createIdentifier("Array"), [
137137
transformInputType(schema, schema.getListItemType(type), state)
138138
]);
139139
} else if (schema.isScalar(type)) {
@@ -156,7 +156,7 @@ function transformNonNullableInputType(
156156
const fieldType = schema.getFieldType(fieldID);
157157
const fieldName = schema.getFieldName(fieldID);
158158
const property = ts.createPropertySignature(
159-
[ts.createToken(ts.SyntaxKind.ReadonlyKeyword)],
159+
undefined,
160160
ts.createIdentifier(fieldName),
161161
state.optionalInputFields.indexOf(fieldName) >= 0 ||
162162
!schema.isNonNull(fieldType)

test/__snapshots__/TypeScriptGenerator-test.ts.snap

Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -695,20 +695,20 @@ mutation CommentCreateMutation(
695695
~~~~~~~~~~ OUTPUT ~~~~~~~~~~
696696
// CommentCreateMutation.graphql
697697
export type CommentCreateInput = {
698-
readonly clientMutationId?: string | null;
699-
readonly feedbackId?: string | null;
700-
readonly feedback?: CommentfeedbackFeedback | null;
698+
clientMutationId?: string | null;
699+
feedbackId?: string | null;
700+
feedback?: CommentfeedbackFeedback | null;
701701
};
702702
export type CommentfeedbackFeedback = {
703-
readonly comment?: FeedbackcommentComment | null;
703+
comment?: FeedbackcommentComment | null;
704704
};
705705
export type FeedbackcommentComment = {
706-
readonly feedback?: CommentfeedbackFeedback | null;
706+
feedback?: CommentfeedbackFeedback | null;
707707
};
708708
export type CommentCreateMutationVariables = {
709709
input: CommentCreateInput;
710710
first?: number | null;
711-
orderBy?: ReadonlyArray<string> | null;
711+
orderBy?: Array<string> | null;
712712
};
713713
export type CommentCreateMutationResponse = {
714714
readonly commentCreate: {
@@ -741,8 +741,8 @@ mutation InputHasArray($input: UpdateAllSeenStateInput) @raw_response_type {
741741
~~~~~~~~~~ OUTPUT ~~~~~~~~~~
742742
// InputHasArray.graphql
743743
export type UpdateAllSeenStateInput = {
744-
readonly clientMutationId?: string | null;
745-
readonly storyIds?: ReadonlyArray<string | null> | null;
744+
clientMutationId?: string | null;
745+
storyIds?: Array<string | null> | null;
746746
};
747747
export type InputHasArrayVariables = {
748748
input?: UpdateAllSeenStateInput | null;
@@ -792,8 +792,8 @@ type Foo {
792792
~~~~~~~~~~ OUTPUT ~~~~~~~~~~
793793
// Test.graphql
794794
export type UpdateAllSeenStateInput = {
795-
readonly clientMutationId?: string | null;
796-
readonly storyIds?: ReadonlyArray<string | null> | null;
795+
clientMutationId?: string | null;
796+
storyIds?: Array<string | null> | null;
797797
};
798798
export type TestVariables = {
799799
input?: UpdateAllSeenStateInput | null;
@@ -860,20 +860,20 @@ fragment FriendFragment on User {
860860
import { FragmentRefs } from "relay-runtime";
861861
export type TestEnums = "mark" | "zuck" | "%future added value";
862862
export type CommentCreateInput = {
863-
readonly clientMutationId?: string | null;
864-
readonly feedbackId?: string | null;
865-
readonly feedback?: CommentfeedbackFeedback | null;
863+
clientMutationId?: string | null;
864+
feedbackId?: string | null;
865+
feedback?: CommentfeedbackFeedback | null;
866866
};
867867
export type CommentfeedbackFeedback = {
868-
readonly comment?: FeedbackcommentComment | null;
868+
comment?: FeedbackcommentComment | null;
869869
};
870870
export type FeedbackcommentComment = {
871-
readonly feedback?: CommentfeedbackFeedback | null;
871+
feedback?: CommentfeedbackFeedback | null;
872872
};
873873
export type CommentCreateMutationVariables = {
874874
input: CommentCreateInput;
875875
first?: number | null;
876-
orderBy?: ReadonlyArray<string> | null;
876+
orderBy?: Array<string> | null;
877877
};
878878
export type CommentCreateMutationResponse = {
879879
readonly commentCreate: {
@@ -974,20 +974,20 @@ fragment FeedbackFragment on Feedback {
974974
// CommentCreateMutation.graphql
975975
import { FragmentRefs } from "relay-runtime";
976976
export type CommentCreateInput = {
977-
readonly clientMutationId?: string | null;
978-
readonly feedbackId?: string | null;
979-
readonly feedback?: CommentfeedbackFeedback | null;
977+
clientMutationId?: string | null;
978+
feedbackId?: string | null;
979+
feedback?: CommentfeedbackFeedback | null;
980980
};
981981
export type CommentfeedbackFeedback = {
982-
readonly comment?: FeedbackcommentComment | null;
982+
comment?: FeedbackcommentComment | null;
983983
};
984984
export type FeedbackcommentComment = {
985-
readonly feedback?: CommentfeedbackFeedback | null;
985+
feedback?: CommentfeedbackFeedback | null;
986986
};
987987
export type CommentCreateMutationVariables = {
988988
input: CommentCreateInput;
989989
first?: number | null;
990-
orderBy?: ReadonlyArray<string> | null;
990+
orderBy?: Array<string> | null;
991991
};
992992
export type CommentCreateMutationResponse = {
993993
readonly commentCreate: {
@@ -1095,15 +1095,15 @@ fragment InlineFragmentWithOverlappingFields on Actor {
10951095
// TestMutation.graphql
10961096
import { FragmentRefs } from "relay-runtime";
10971097
export type CommentCreateInput = {
1098-
readonly clientMutationId?: string | null;
1099-
readonly feedbackId?: string | null;
1100-
readonly feedback?: CommentfeedbackFeedback | null;
1098+
clientMutationId?: string | null;
1099+
feedbackId?: string | null;
1100+
feedback?: CommentfeedbackFeedback | null;
11011101
};
11021102
export type CommentfeedbackFeedback = {
1103-
readonly comment?: FeedbackcommentComment | null;
1103+
comment?: FeedbackcommentComment | null;
11041104
};
11051105
export type FeedbackcommentComment = {
1106-
readonly feedback?: CommentfeedbackFeedback | null;
1106+
feedback?: CommentfeedbackFeedback | null;
11071107
};
11081108
export type TestMutationVariables = {
11091109
input: CommentCreateInput;
@@ -1610,15 +1610,15 @@ export type ExampleFragment$key = {
16101610
16111611
// TestMutation.graphql
16121612
export type CommentCreateInput = {
1613-
readonly clientMutationId?: string | null;
1614-
readonly feedbackId?: string | null;
1615-
readonly feedback?: CommentfeedbackFeedback | null;
1613+
clientMutationId?: string | null;
1614+
feedbackId?: string | null;
1615+
feedback?: CommentfeedbackFeedback | null;
16161616
};
16171617
export type CommentfeedbackFeedback = {
1618-
readonly comment?: FeedbackcommentComment | null;
1618+
comment?: FeedbackcommentComment | null;
16191619
};
16201620
export type FeedbackcommentComment = {
1621-
readonly feedback?: CommentfeedbackFeedback | null;
1621+
feedback?: CommentfeedbackFeedback | null;
16221622
};
16231623
export type TestMutationVariables = {
16241624
input: CommentCreateInput;
@@ -1638,8 +1638,8 @@ export type TestMutation = {
16381638
16391639
// TestSubscription.graphql
16401640
export type FeedbackLikeInput = {
1641-
readonly clientMutationId?: string | null;
1642-
readonly feedbackId?: string | null;
1641+
clientMutationId?: string | null;
1642+
feedbackId?: string | null;
16431643
};
16441644
export type TestSubscriptionVariables = {
16451645
input?: FeedbackLikeInput | null;
@@ -2780,20 +2780,20 @@ mutation CommentCreateMutation(
27802780
~~~~~~~~~~ OUTPUT ~~~~~~~~~~
27812781
// CommentCreateMutation.graphql
27822782
export type CommentCreateInput = {
2783-
readonly clientMutationId?: string | null;
2784-
readonly feedbackId?: string | null;
2785-
readonly feedback?: CommentfeedbackFeedback | null;
2783+
clientMutationId?: string | null;
2784+
feedbackId?: string | null;
2785+
feedback?: CommentfeedbackFeedback | null;
27862786
};
27872787
export type CommentfeedbackFeedback = {
2788-
readonly comment?: FeedbackcommentComment | null;
2788+
comment?: FeedbackcommentComment | null;
27892789
};
27902790
export type FeedbackcommentComment = {
2791-
readonly feedback?: CommentfeedbackFeedback | null;
2791+
feedback?: CommentfeedbackFeedback | null;
27922792
};
27932793
export type CommentCreateMutationVariables = {
27942794
input: CommentCreateInput;
27952795
first?: number | null;
2796-
orderBy?: ReadonlyArray<string> | null;
2796+
orderBy?: Array<string> | null;
27972797
};
27982798
export type CommentCreateMutationResponse = {
27992799
readonly commentCreate: {
@@ -2826,8 +2826,8 @@ mutation InputHasArray($input: UpdateAllSeenStateInput) @raw_response_type {
28262826
~~~~~~~~~~ OUTPUT ~~~~~~~~~~
28272827
// InputHasArray.graphql
28282828
export type UpdateAllSeenStateInput = {
2829-
readonly clientMutationId?: string | null;
2830-
readonly storyIds?: ReadonlyArray<string | null> | null;
2829+
clientMutationId?: string | null;
2830+
storyIds?: Array<string | null> | null;
28312831
};
28322832
export type InputHasArrayVariables = {
28332833
input?: UpdateAllSeenStateInput | null;
@@ -2877,8 +2877,8 @@ type Foo {
28772877
~~~~~~~~~~ OUTPUT ~~~~~~~~~~
28782878
// Test.graphql
28792879
export type UpdateAllSeenStateInput = {
2880-
readonly clientMutationId?: string | null;
2881-
readonly storyIds?: ReadonlyArray<string | null> | null;
2880+
clientMutationId?: string | null;
2881+
storyIds?: Array<string | null> | null;
28822882
};
28832883
export type TestVariables = {
28842884
input?: UpdateAllSeenStateInput | null;
@@ -2945,20 +2945,20 @@ fragment FriendFragment on User {
29452945
import { FragmentRefs } from "relay-runtime";
29462946
export type TestEnums = "mark" | "zuck" | "%future added value";
29472947
export type CommentCreateInput = {
2948-
readonly clientMutationId?: string | null;
2949-
readonly feedbackId?: string | null;
2950-
readonly feedback?: CommentfeedbackFeedback | null;
2948+
clientMutationId?: string | null;
2949+
feedbackId?: string | null;
2950+
feedback?: CommentfeedbackFeedback | null;
29512951
};
29522952
export type CommentfeedbackFeedback = {
2953-
readonly comment?: FeedbackcommentComment | null;
2953+
comment?: FeedbackcommentComment | null;
29542954
};
29552955
export type FeedbackcommentComment = {
2956-
readonly feedback?: CommentfeedbackFeedback | null;
2956+
feedback?: CommentfeedbackFeedback | null;
29572957
};
29582958
export type CommentCreateMutationVariables = {
29592959
input: CommentCreateInput;
29602960
first?: number | null;
2961-
orderBy?: ReadonlyArray<string> | null;
2961+
orderBy?: Array<string> | null;
29622962
};
29632963
export type CommentCreateMutationResponse = {
29642964
readonly commentCreate: {
@@ -3059,20 +3059,20 @@ fragment FeedbackFragment on Feedback {
30593059
// CommentCreateMutation.graphql
30603060
import { FragmentRefs } from "relay-runtime";
30613061
export type CommentCreateInput = {
3062-
readonly clientMutationId?: string | null;
3063-
readonly feedbackId?: string | null;
3064-
readonly feedback?: CommentfeedbackFeedback | null;
3062+
clientMutationId?: string | null;
3063+
feedbackId?: string | null;
3064+
feedback?: CommentfeedbackFeedback | null;
30653065
};
30663066
export type CommentfeedbackFeedback = {
3067-
readonly comment?: FeedbackcommentComment | null;
3067+
comment?: FeedbackcommentComment | null;
30683068
};
30693069
export type FeedbackcommentComment = {
3070-
readonly feedback?: CommentfeedbackFeedback | null;
3070+
feedback?: CommentfeedbackFeedback | null;
30713071
};
30723072
export type CommentCreateMutationVariables = {
30733073
input: CommentCreateInput;
30743074
first?: number | null;
3075-
orderBy?: ReadonlyArray<string> | null;
3075+
orderBy?: Array<string> | null;
30763076
};
30773077
export type CommentCreateMutationResponse = {
30783078
readonly commentCreate: {
@@ -3180,15 +3180,15 @@ fragment InlineFragmentWithOverlappingFields on Actor {
31803180
// TestMutation.graphql
31813181
import { FragmentRefs } from "relay-runtime";
31823182
export type CommentCreateInput = {
3183-
readonly clientMutationId?: string | null;
3184-
readonly feedbackId?: string | null;
3185-
readonly feedback?: CommentfeedbackFeedback | null;
3183+
clientMutationId?: string | null;
3184+
feedbackId?: string | null;
3185+
feedback?: CommentfeedbackFeedback | null;
31863186
};
31873187
export type CommentfeedbackFeedback = {
3188-
readonly comment?: FeedbackcommentComment | null;
3188+
comment?: FeedbackcommentComment | null;
31893189
};
31903190
export type FeedbackcommentComment = {
3191-
readonly feedback?: CommentfeedbackFeedback | null;
3191+
feedback?: CommentfeedbackFeedback | null;
31923192
};
31933193
export type TestMutationVariables = {
31943194
input: CommentCreateInput;
@@ -3695,15 +3695,15 @@ export type ExampleFragment$key = {
36953695
36963696
// TestMutation.graphql
36973697
export type CommentCreateInput = {
3698-
readonly clientMutationId?: string | null;
3699-
readonly feedbackId?: string | null;
3700-
readonly feedback?: CommentfeedbackFeedback | null;
3698+
clientMutationId?: string | null;
3699+
feedbackId?: string | null;
3700+
feedback?: CommentfeedbackFeedback | null;
37013701
};
37023702
export type CommentfeedbackFeedback = {
3703-
readonly comment?: FeedbackcommentComment | null;
3703+
comment?: FeedbackcommentComment | null;
37043704
};
37053705
export type FeedbackcommentComment = {
3706-
readonly feedback?: CommentfeedbackFeedback | null;
3706+
feedback?: CommentfeedbackFeedback | null;
37073707
};
37083708
export type TestMutationVariables = {
37093709
input: CommentCreateInput;
@@ -3723,8 +3723,8 @@ export type TestMutation = {
37233723
37243724
// TestSubscription.graphql
37253725
export type FeedbackLikeInput = {
3726-
readonly clientMutationId?: string | null;
3727-
readonly feedbackId?: string | null;
3726+
clientMutationId?: string | null;
3727+
feedbackId?: string | null;
37283728
};
37293729
export type TestSubscriptionVariables = {
37303730
input?: FeedbackLikeInput | null;

0 commit comments

Comments
 (0)