@@ -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,17 +432,33 @@ describe('ParseGraphQLServer', () => {
431
432
objects . push ( object1 , object2 , object3 , object4 ) ;
432
433
}
433
434
434
- beforeEach ( async ( ) => {
435
+ async function createGQLFromParseServer ( _parseServer , parseGraphQLServerOptions ) {
436
+ if ( parseLiveQueryServer ) {
437
+ await parseLiveQueryServer . server . close ( ) ;
438
+ }
439
+ if ( httpServer ) {
440
+ await httpServer . close ( ) ;
441
+ }
435
442
const expressApp = express ( ) ;
436
443
httpServer = http . createServer ( expressApp ) ;
437
444
expressApp . use ( '/parse' , parseServer . app ) ;
438
445
parseLiveQueryServer = await ParseServer . createLiveQueryServer ( httpServer , {
439
446
port : 1338 ,
440
447
} ) ;
448
+ parseGraphQLServer = new ParseGraphQLServer ( _parseServer , {
449
+ graphQLPath : '/graphql' ,
450
+ playgroundPath : '/playground' ,
451
+ subscriptionsPath : '/subscriptions' ,
452
+ ...parseGraphQLServerOptions ,
453
+ } ) ;
441
454
parseGraphQLServer . applyGraphQL ( expressApp ) ;
442
455
parseGraphQLServer . applyPlayground ( expressApp ) ;
443
456
parseGraphQLServer . createSubscriptions ( httpServer ) ;
444
457
await new Promise ( resolve => httpServer . listen ( { port : 13377 } , resolve ) ) ;
458
+ }
459
+
460
+ beforeEach ( async ( ) => {
461
+ await createGQLFromParseServer ( parseServer ) ;
445
462
446
463
const subscriptionClient = new SubscriptionClient (
447
464
'ws://localhost:13377/subscriptions' ,
@@ -473,8 +490,8 @@ describe('ParseGraphQLServer', () => {
473
490
} ,
474
491
} ,
475
492
} ) ;
476
- spyOn ( console , 'warn' ) . and . callFake ( ( ) => { } ) ;
477
- spyOn ( console , 'error' ) . and . callFake ( ( ) => { } ) ;
493
+ spyOn ( console , 'warn' ) . and . callFake ( ( ) => { } ) ;
494
+ spyOn ( console , 'error' ) . and . callFake ( ( ) => { } ) ;
478
495
} ) ;
479
496
480
497
afterEach ( async ( ) => {
@@ -590,6 +607,96 @@ describe('ParseGraphQLServer', () => {
590
607
] ) ;
591
608
} ;
592
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
+
593
700
describe ( 'Default Types' , ( ) => {
594
701
it ( 'should have Object scalar type' , async ( ) => {
595
702
const objectType = (
@@ -734,6 +841,11 @@ describe('ParseGraphQLServer', () => {
734
841
}
735
842
}
736
843
` ,
844
+ context : {
845
+ headers : {
846
+ 'X-Parse-Master-Key' : 'test' ,
847
+ } ,
848
+ }
737
849
} )
738
850
) . data [ '__schema' ] . types . map ( type => type . name ) ;
739
851
@@ -769,6 +881,11 @@ describe('ParseGraphQLServer', () => {
769
881
}
770
882
}
771
883
` ,
884
+ context : {
885
+ headers : {
886
+ 'X-Parse-Master-Key' : 'test' ,
887
+ } ,
888
+ }
772
889
} )
773
890
) . data [ '__schema' ] . types . map ( type => type . name ) ;
774
891
@@ -853,7 +970,7 @@ describe('ParseGraphQLServer', () => {
853
970
} ) ;
854
971
855
972
it ( 'should have clientMutationId in call function input' , async ( ) => {
856
- Parse . Cloud . define ( 'hello' , ( ) => { } ) ;
973
+ Parse . Cloud . define ( 'hello' , ( ) => { } ) ;
857
974
858
975
const callFunctionInputFields = (
859
976
await apolloClient . query ( {
@@ -875,7 +992,7 @@ describe('ParseGraphQLServer', () => {
875
992
} ) ;
876
993
877
994
it ( 'should have clientMutationId in call function payload' , async ( ) => {
878
- Parse . Cloud . define ( 'hello' , ( ) => { } ) ;
995
+ Parse . Cloud . define ( 'hello' , ( ) => { } ) ;
879
996
880
997
const callFunctionPayloadFields = (
881
998
await apolloClient . query ( {
@@ -1301,6 +1418,11 @@ describe('ParseGraphQLServer', () => {
1301
1418
}
1302
1419
}
1303
1420
` ,
1421
+ context : {
1422
+ headers : {
1423
+ 'X-Parse-Master-Key' : 'test' ,
1424
+ } ,
1425
+ }
1304
1426
} )
1305
1427
) . data [ '__schema' ] . types . map ( type => type . name ) ;
1306
1428
@@ -7432,9 +7554,9 @@ describe('ParseGraphQLServer', () => {
7432
7554
it ( 'should send reset password' , async ( ) => {
7433
7555
const clientMutationId = uuidv4 ( ) ;
7434
7556
const emailAdapter = {
7435
- sendVerificationEmail : ( ) => { } ,
7557
+ sendVerificationEmail : ( ) => { } ,
7436
7558
sendPasswordResetEmail : ( ) => Promise . resolve ( ) ,
7437
- sendMail : ( ) => { } ,
7559
+ sendMail : ( ) => { } ,
7438
7560
} ;
7439
7561
parseServer = await global . reconfigureServer ( {
7440
7562
appName : 'test' ,
@@ -7472,11 +7594,11 @@ describe('ParseGraphQLServer', () => {
7472
7594
const clientMutationId = uuidv4 ( ) ;
7473
7595
let resetPasswordToken ;
7474
7596
const emailAdapter = {
7475
- sendVerificationEmail : ( ) => { } ,
7597
+ sendVerificationEmail : ( ) => { } ,
7476
7598
sendPasswordResetEmail : ( { link } ) => {
7477
7599
resetPasswordToken = link . split ( 'token=' ) [ 1 ] . split ( '&' ) [ 0 ] ;
7478
7600
} ,
7479
- sendMail : ( ) => { } ,
7601
+ sendMail : ( ) => { } ,
7480
7602
} ;
7481
7603
parseServer = await global . reconfigureServer ( {
7482
7604
appName : 'test' ,
@@ -7541,9 +7663,9 @@ describe('ParseGraphQLServer', () => {
7541
7663
it ( 'should send verification email again' , async ( ) => {
7542
7664
const clientMutationId = uuidv4 ( ) ;
7543
7665
const emailAdapter = {
7544
- sendVerificationEmail : ( ) => { } ,
7666
+ sendVerificationEmail : ( ) => { } ,
7545
7667
sendPasswordResetEmail : ( ) => Promise . resolve ( ) ,
7546
- sendMail : ( ) => { } ,
7668
+ sendMail : ( ) => { } ,
7547
7669
} ;
7548
7670
parseServer = await global . reconfigureServer ( {
7549
7671
appName : 'test' ,
0 commit comments