Skip to content

Commit 72a83ba

Browse files
wincentfacebook-github-bot-8
authored andcommitted
Fail fast if provided with unknown mutation config key
Reviewed By: josephsavona Differential Revision: D2929032 fb-gh-sync-id: 419d3b02ed7b5acce9262bda43203aea4c200bca shipit-source-id: 419d3b02ed7b5acce9262bda43203aea4c200bca
1 parent f51d01a commit 72a83ba

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/mutation/RelayMutationQuery.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,14 @@ var RelayMutationQuery = {
369369
tracker,
370370
}));
371371
break;
372+
373+
default:
374+
invariant(
375+
false,
376+
'RelayMutationQuery: Unrecognized config key `%s` for `%s`.',
377+
config.type,
378+
mutationName
379+
);
372380
}
373381
});
374382

src/mutation/__tests__/RelayMutationQuery-test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,5 +1202,31 @@ describe('RelayMutationQuery', () => {
12021202
expect(query)
12031203
.toEqualQueryNode(expectedMutationQuery);
12041204
});
1205+
1206+
it('complains about unknown config types', () => {
1207+
const fatQuery = fromGraphQL.Fragment(Relay.QL`
1208+
fragment on UnfriendResponsePayload {
1209+
clientMutationId
1210+
}
1211+
`);
1212+
const configs = [
1213+
{
1214+
type: 'COSMIC_RAY_BIT_FLIP',
1215+
},
1216+
];
1217+
1218+
const mutation = Relay.QL`mutation{ unfriend(input: $input) }`;
1219+
const mutationName = 'UnfriendMutation';
1220+
expect(() => RelayMutationQuery.buildQuery({
1221+
tracker,
1222+
fatQuery,
1223+
configs,
1224+
mutationName,
1225+
mutation,
1226+
})).toFailInvariant(
1227+
'RelayMutationQuery: Unrecognized config key `COSMIC_RAY_BIT_FLIP` ' +
1228+
'for `UnfriendMutation`.'
1229+
);
1230+
});
12051231
});
12061232
});

0 commit comments

Comments
 (0)