@@ -50,6 +50,7 @@ describe('ParseGraphQLServer', () => {
50
50
51
51
beforeEach ( async ( ) => {
52
52
parseServer = await global . reconfigureServer ( {
53
+ maintenanceKey : 'test2' ,
53
54
maxUploadSize : '1kb' ,
54
55
} ) ;
55
56
parseGraphQLServer = new ParseGraphQLServer ( parseServer , {
@@ -88,8 +89,8 @@ describe('ParseGraphQLServer', () => {
88
89
89
90
it ( 'should initialize parseGraphQLSchema with a log controller' , async ( ) => {
90
91
const loggerAdapter = {
91
- log : ( ) => { } ,
92
- error : ( ) => { } ,
92
+ log : ( ) => { } ,
93
+ error : ( ) => { } ,
93
94
} ;
94
95
const parseServer = await global . reconfigureServer ( {
95
96
loggerAdapter,
@@ -124,10 +125,10 @@ describe('ParseGraphQLServer', () => {
124
125
info : new Object ( ) ,
125
126
config : new Object ( ) ,
126
127
auth : new Object ( ) ,
127
- get : ( ) => { } ,
128
+ get : ( ) => { } ,
128
129
} ;
129
130
const res = {
130
- set : ( ) => { } ,
131
+ set : ( ) => { } ,
131
132
} ;
132
133
133
134
it_id ( '0696675e-060f-414f-bc77-9d57f31807f5' ) ( it ) ( 'should return schema and context with req\'s info, config and auth' , async ( ) => {
@@ -431,7 +432,7 @@ describe('ParseGraphQLServer', () => {
431
432
objects . push ( object1 , object2 , object3 , object4 ) ;
432
433
}
433
434
434
- async function createGQLFromParseServer ( _parseServer ) {
435
+ async function createGQLFromParseServer ( _parseServer , parseGraphQLServerOptions ) {
435
436
if ( parseLiveQueryServer ) {
436
437
await parseLiveQueryServer . server . close ( ) ;
437
438
}
@@ -448,6 +449,7 @@ describe('ParseGraphQLServer', () => {
448
449
graphQLPath : '/graphql' ,
449
450
playgroundPath : '/playground' ,
450
451
subscriptionsPath : '/subscriptions' ,
452
+ ...parseGraphQLServerOptions ,
451
453
} ) ;
452
454
parseGraphQLServer . applyGraphQL ( expressApp ) ;
453
455
parseGraphQLServer . applyPlayground ( expressApp ) ;
@@ -488,8 +490,8 @@ describe('ParseGraphQLServer', () => {
488
490
} ,
489
491
} ,
490
492
} ) ;
491
- spyOn ( console , 'warn' ) . and . callFake ( ( ) => { } ) ;
492
- spyOn ( console , 'error' ) . and . callFake ( ( ) => { } ) ;
493
+ spyOn ( console , 'warn' ) . and . callFake ( ( ) => { } ) ;
494
+ spyOn ( console , 'error' ) . and . callFake ( ( ) => { } ) ;
493
495
} ) ;
494
496
495
497
afterEach ( async ( ) => {
@@ -605,6 +607,96 @@ describe('ParseGraphQLServer', () => {
605
607
] ) ;
606
608
} ;
607
609
610
+ describe ( 'Introspection' , ( ) => {
611
+ it ( 'should have public introspection disabled by default without master key' , async ( ) => {
612
+
613
+ try {
614
+ await apolloClient . query ( {
615
+ query : gql `
616
+ query Introspection {
617
+ __schema {
618
+ types {
619
+ name
620
+ }
621
+ }
622
+ }
623
+ ` ,
624
+ } )
625
+
626
+ fail ( 'should have thrown an error' ) ;
627
+
628
+ } catch ( e ) {
629
+ expect ( e . message ) . toEqual ( 'Response not successful: Received status code 403' ) ;
630
+ expect ( e . networkError . result . errors [ 0 ] . message ) . toEqual ( 'Introspection is not allowed' ) ;
631
+ }
632
+ } ) ;
633
+
634
+ it ( 'should always work with master key' , async ( ) => {
635
+ const introspection =
636
+ await apolloClient . query ( {
637
+ query : gql `
638
+ query Introspection {
639
+ __schema {
640
+ types {
641
+ name
642
+ }
643
+ }
644
+ }
645
+ ` ,
646
+ context : {
647
+ headers : {
648
+ 'X-Parse-Master-Key' : 'test' ,
649
+ } ,
650
+ }
651
+ } , )
652
+ expect ( introspection . data ) . toBeDefined ( ) ;
653
+ expect ( introspection . errors ) . not . toBeDefined ( ) ;
654
+ } ) ;
655
+
656
+ it ( 'should always work with maintenance key' , async ( ) => {
657
+ const introspection =
658
+ await apolloClient . query ( {
659
+ query : gql `
660
+ query Introspection {
661
+ __schema {
662
+ types {
663
+ name
664
+ }
665
+ }
666
+ }
667
+ ` ,
668
+ context : {
669
+ headers : {
670
+ 'X-Parse-Maintenance-Key' : 'test2' ,
671
+ } ,
672
+ }
673
+ } , )
674
+ expect ( introspection . data ) . toBeDefined ( ) ;
675
+ expect ( introspection . errors ) . not . toBeDefined ( ) ;
676
+ } ) ;
677
+
678
+ it ( 'should have public introspection enabled if enabled' , async ( ) => {
679
+
680
+ const parseServer = await reconfigureServer ( ) ;
681
+ await createGQLFromParseServer ( parseServer , { graphQLPublicIntrospection : true } ) ;
682
+
683
+ const introspection =
684
+ await apolloClient . query ( {
685
+ query : gql `
686
+ query Introspection {
687
+ __schema {
688
+ types {
689
+ name
690
+ }
691
+ }
692
+ }
693
+ ` ,
694
+ } )
695
+ expect ( introspection . data ) . toBeDefined ( ) ;
696
+ } ) ;
697
+ } ) ;
698
+
699
+
608
700
describe ( 'Default Types' , ( ) => {
609
701
it ( 'should have Object scalar type' , async ( ) => {
610
702
const objectType = (
@@ -749,6 +841,11 @@ describe('ParseGraphQLServer', () => {
749
841
}
750
842
}
751
843
` ,
844
+ context : {
845
+ headers : {
846
+ 'X-Parse-Master-Key' : 'test' ,
847
+ } ,
848
+ }
752
849
} )
753
850
) . data [ '__schema' ] . types . map ( type => type . name ) ;
754
851
@@ -780,6 +877,11 @@ describe('ParseGraphQLServer', () => {
780
877
}
781
878
}
782
879
` ,
880
+ context : {
881
+ headers : {
882
+ 'X-Parse-Master-Key' : 'test' ,
883
+ } ,
884
+ }
783
885
} )
784
886
) . data [ '__schema' ] . types . map ( type => type . name ) ;
785
887
@@ -864,7 +966,7 @@ describe('ParseGraphQLServer', () => {
864
966
} ) ;
865
967
866
968
it ( 'should have clientMutationId in call function input' , async ( ) => {
867
- Parse . Cloud . define ( 'hello' , ( ) => { } ) ;
969
+ Parse . Cloud . define ( 'hello' , ( ) => { } ) ;
868
970
869
971
const callFunctionInputFields = (
870
972
await apolloClient . query ( {
@@ -886,7 +988,7 @@ describe('ParseGraphQLServer', () => {
886
988
} ) ;
887
989
888
990
it ( 'should have clientMutationId in call function payload' , async ( ) => {
889
- Parse . Cloud . define ( 'hello' , ( ) => { } ) ;
991
+ Parse . Cloud . define ( 'hello' , ( ) => { } ) ;
890
992
891
993
const callFunctionPayloadFields = (
892
994
await apolloClient . query ( {
@@ -1312,6 +1414,11 @@ describe('ParseGraphQLServer', () => {
1312
1414
}
1313
1415
}
1314
1416
` ,
1417
+ context : {
1418
+ headers : {
1419
+ 'X-Parse-Master-Key' : 'test' ,
1420
+ } ,
1421
+ }
1315
1422
} )
1316
1423
) . data [ '__schema' ] . types . map ( type => type . name ) ;
1317
1424
@@ -7447,9 +7554,9 @@ describe('ParseGraphQLServer', () => {
7447
7554
it ( 'should send reset password' , async ( ) => {
7448
7555
const clientMutationId = uuidv4 ( ) ;
7449
7556
const emailAdapter = {
7450
- sendVerificationEmail : ( ) => { } ,
7557
+ sendVerificationEmail : ( ) => { } ,
7451
7558
sendPasswordResetEmail : ( ) => Promise . resolve ( ) ,
7452
- sendMail : ( ) => { } ,
7559
+ sendMail : ( ) => { } ,
7453
7560
} ;
7454
7561
parseServer = await global . reconfigureServer ( {
7455
7562
appName : 'test' ,
@@ -7488,11 +7595,11 @@ describe('ParseGraphQLServer', () => {
7488
7595
const clientMutationId = uuidv4 ( ) ;
7489
7596
let resetPasswordToken ;
7490
7597
const emailAdapter = {
7491
- sendVerificationEmail : ( ) => { } ,
7598
+ sendVerificationEmail : ( ) => { } ,
7492
7599
sendPasswordResetEmail : ( { link } ) => {
7493
7600
resetPasswordToken = link . split ( 'token=' ) [ 1 ] . split ( '&' ) [ 0 ] ;
7494
7601
} ,
7495
- sendMail : ( ) => { } ,
7602
+ sendMail : ( ) => { } ,
7496
7603
} ;
7497
7604
parseServer = await global . reconfigureServer ( {
7498
7605
appName : 'test' ,
@@ -7558,9 +7665,9 @@ describe('ParseGraphQLServer', () => {
7558
7665
it ( 'should send verification email again' , async ( ) => {
7559
7666
const clientMutationId = uuidv4 ( ) ;
7560
7667
const emailAdapter = {
7561
- sendVerificationEmail : ( ) => { } ,
7668
+ sendVerificationEmail : ( ) => { } ,
7562
7669
sendPasswordResetEmail : ( ) => Promise . resolve ( ) ,
7563
- sendMail : ( ) => { } ,
7670
+ sendMail : ( ) => { } ,
7564
7671
} ;
7565
7672
parseServer = await global . reconfigureServer ( {
7566
7673
appName : 'test' ,
0 commit comments