@@ -1016,6 +1016,115 @@ describe('ParseGraphQLServer', () => {
10161016 expect ( introspection . data ) . toBeDefined ( ) ;
10171017 expect ( introspection . data . __type ) . toBeDefined ( ) ;
10181018 } ) ;
1019+
1020+ it ( 'should strip "Did you mean" field suggestions from validation errors without master or maintenance key' , async ( ) => {
1021+ try {
1022+ await apolloClient . query ( {
1023+ query : gql `
1024+ query Typo {
1025+ healt
1026+ }
1027+ ` ,
1028+ } ) ;
1029+ fail ( 'should have thrown a validation error' ) ;
1030+ } catch ( e ) {
1031+ const message = e . networkError . result . errors [ 0 ] . message ;
1032+ expect ( message ) . toContain ( 'Cannot query field "healt"' ) ;
1033+ expect ( message ) . not . toMatch ( / D i d y o u m e a n / ) ;
1034+ expect ( message ) . not . toContain ( 'health' ) ;
1035+ }
1036+ } ) ;
1037+
1038+ it ( 'should strip "Did you mean" argument suggestions from validation errors without master or maintenance key' , async ( ) => {
1039+ try {
1040+ await apolloClient . query ( {
1041+ query : gql `
1042+ query UnknownArg {
1043+ users(wher: {}) {
1044+ edges {
1045+ node {
1046+ id
1047+ }
1048+ }
1049+ }
1050+ }
1051+ ` ,
1052+ } ) ;
1053+ fail ( 'should have thrown a validation error' ) ;
1054+ } catch ( e ) {
1055+ const message = e . networkError . result . errors [ 0 ] . message ;
1056+ expect ( message ) . toContain ( 'Unknown argument "wher"' ) ;
1057+ expect ( message ) . not . toMatch ( / D i d y o u m e a n / ) ;
1058+ expect ( message ) . not . toContain ( '"where"' ) ;
1059+ }
1060+ } ) ;
1061+
1062+ it ( 'should keep "Did you mean" suggestions with master key' , async ( ) => {
1063+ try {
1064+ await apolloClient . query ( {
1065+ query : gql `
1066+ query Typo {
1067+ healt
1068+ }
1069+ ` ,
1070+ context : {
1071+ headers : {
1072+ 'X-Parse-Master-Key' : 'test' ,
1073+ } ,
1074+ } ,
1075+ } ) ;
1076+ fail ( 'should have thrown a validation error' ) ;
1077+ } catch ( e ) {
1078+ const message = e . networkError . result . errors [ 0 ] . message ;
1079+ expect ( message ) . toContain ( 'Cannot query field "healt"' ) ;
1080+ expect ( message ) . toMatch ( / D i d y o u m e a n / ) ;
1081+ expect ( message ) . toContain ( 'health' ) ;
1082+ }
1083+ } ) ;
1084+
1085+ it ( 'should keep "Did you mean" suggestions with maintenance key' , async ( ) => {
1086+ try {
1087+ await apolloClient . query ( {
1088+ query : gql `
1089+ query Typo {
1090+ healt
1091+ }
1092+ ` ,
1093+ context : {
1094+ headers : {
1095+ 'X-Parse-Maintenance-Key' : 'test2' ,
1096+ } ,
1097+ } ,
1098+ } ) ;
1099+ fail ( 'should have thrown a validation error' ) ;
1100+ } catch ( e ) {
1101+ const message = e . networkError . result . errors [ 0 ] . message ;
1102+ expect ( message ) . toContain ( 'Cannot query field "healt"' ) ;
1103+ expect ( message ) . toMatch ( / D i d y o u m e a n / ) ;
1104+ expect ( message ) . toContain ( 'health' ) ;
1105+ }
1106+ } ) ;
1107+
1108+ it ( 'should keep "Did you mean" suggestions when public introspection is enabled' , async ( ) => {
1109+ const parseServer = await reconfigureServer ( ) ;
1110+ await createGQLFromParseServer ( parseServer , { graphQLPublicIntrospection : true } ) ;
1111+
1112+ try {
1113+ await apolloClient . query ( {
1114+ query : gql `
1115+ query Typo {
1116+ healt
1117+ }
1118+ ` ,
1119+ } ) ;
1120+ fail ( 'should have thrown a validation error' ) ;
1121+ } catch ( e ) {
1122+ const message = e . networkError . result . errors [ 0 ] . message ;
1123+ expect ( message ) . toContain ( 'Cannot query field "healt"' ) ;
1124+ expect ( message ) . toMatch ( / D i d y o u m e a n / ) ;
1125+ expect ( message ) . toContain ( 'health' ) ;
1126+ }
1127+ } ) ;
10191128 } ) ;
10201129
10211130
0 commit comments