@@ -85,8 +85,8 @@ describe('ParseGraphQLServer', () => {
85
85
86
86
it ( 'should initialize parseGraphQLSchema with a log controller' , async ( ) => {
87
87
const loggerAdapter = {
88
- log : ( ) => { } ,
89
- error : ( ) => { } ,
88
+ log : ( ) => { } ,
89
+ error : ( ) => { } ,
90
90
} ;
91
91
const parseServer = await global . reconfigureServer ( {
92
92
loggerAdapter,
@@ -98,6 +98,21 @@ describe('ParseGraphQLServer', () => {
98
98
} ) ;
99
99
} ) ;
100
100
101
+ describe ( '_getServer' , ( ) => {
102
+ it ( 'should only return new server on schema changes' , async ( ) => {
103
+ parseGraphQLServer . server = undefined ;
104
+ const server1 = await parseGraphQLServer . _getServer ( ) ;
105
+ const server2 = await parseGraphQLServer . _getServer ( ) ;
106
+ expect ( server1 ) . toBe ( server2 ) ;
107
+
108
+ parseGraphQLServer . parseGraphQLSchema . schemaCache . clear ( ) ;
109
+ const server3 = await parseGraphQLServer . _getServer ( ) ;
110
+ const server4 = await parseGraphQLServer . _getServer ( ) ;
111
+ expect ( server3 ) . not . toBe ( server2 ) ;
112
+ expect ( server3 ) . toBe ( server4 ) ;
113
+ } ) ;
114
+ } ) ;
115
+
101
116
describe ( '_getGraphQLOptions' , ( ) => {
102
117
const req = {
103
118
info : new Object ( ) ,
@@ -107,6 +122,9 @@ describe('ParseGraphQLServer', () => {
107
122
108
123
it ( "should return schema and context with req's info, config and auth" , async ( ) => {
109
124
const options = await parseGraphQLServer . _getGraphQLOptions ( ) ;
125
+ expect ( options . multipart ) . toEqual ( {
126
+ fileSize : 20971520 ,
127
+ } ) ;
110
128
expect ( options . schema ) . toEqual ( parseGraphQLServer . parseGraphQLSchema . graphQLSchema ) ;
111
129
const contextResponse = options . context ( { req } ) ;
112
130
expect ( contextResponse . info ) . toEqual ( req . info ) ;
@@ -441,8 +459,8 @@ describe('ParseGraphQLServer', () => {
441
459
} ,
442
460
} ,
443
461
} ) ;
444
- spyOn ( console , 'warn' ) . and . callFake ( ( ) => { } ) ;
445
- spyOn ( console , 'error' ) . and . callFake ( ( ) => { } ) ;
462
+ spyOn ( console , 'warn' ) . and . callFake ( ( ) => { } ) ;
463
+ spyOn ( console , 'error' ) . and . callFake ( ( ) => { } ) ;
446
464
} ) ;
447
465
448
466
afterEach ( async ( ) => {
@@ -821,7 +839,7 @@ describe('ParseGraphQLServer', () => {
821
839
} ) ;
822
840
823
841
it ( 'should have clientMutationId in call function input' , async ( ) => {
824
- Parse . Cloud . define ( 'hello' , ( ) => { } ) ;
842
+ Parse . Cloud . define ( 'hello' , ( ) => { } ) ;
825
843
826
844
const callFunctionInputFields = (
827
845
await apolloClient . query ( {
@@ -843,7 +861,7 @@ describe('ParseGraphQLServer', () => {
843
861
} ) ;
844
862
845
863
it ( 'should have clientMutationId in call function payload' , async ( ) => {
846
- Parse . Cloud . define ( 'hello' , ( ) => { } ) ;
864
+ Parse . Cloud . define ( 'hello' , ( ) => { } ) ;
847
865
848
866
const callFunctionPayloadFields = (
849
867
await apolloClient . query ( {
@@ -3301,7 +3319,6 @@ describe('ParseGraphQLServer', () => {
3301
3319
} ) ;
3302
3320
fail ( 'should fail' ) ;
3303
3321
} catch ( e ) {
3304
- console . log ( e ) ;
3305
3322
expect ( e . graphQLErrors [ 0 ] . extensions . code ) . toEqual ( Parse . Error . OPERATION_FORBIDDEN ) ;
3306
3323
expect ( e . graphQLErrors [ 0 ] . message ) . toEqual ( 'unauthorized: master key is required' ) ;
3307
3324
}
@@ -6512,7 +6529,7 @@ describe('ParseGraphQLServer', () => {
6512
6529
) ;
6513
6530
expect (
6514
6531
( await deleteObject ( object4 . className , object4 . id ) ) . data . delete [
6515
- object4 . className . charAt ( 0 ) . toLowerCase ( ) + object4 . className . slice ( 1 )
6532
+ object4 . className . charAt ( 0 ) . toLowerCase ( ) + object4 . className . slice ( 1 )
6516
6533
]
6517
6534
) . toEqual ( { objectId : object4 . id , __typename : 'PublicClass' } ) ;
6518
6535
await expectAsync ( object4 . fetch ( { useMasterKey : true } ) ) . toBeRejectedWith (
@@ -6799,7 +6816,7 @@ describe('ParseGraphQLServer', () => {
6799
6816
6800
6817
expect ( queryResult . data . customers . edges . length ) . toEqual ( 1 ) ;
6801
6818
} catch ( e ) {
6802
- console . log ( JSON . stringify ( e ) ) ;
6819
+ console . error ( JSON . stringify ( e ) ) ;
6803
6820
}
6804
6821
} ) ;
6805
6822
} ) ;
@@ -7242,9 +7259,9 @@ describe('ParseGraphQLServer', () => {
7242
7259
it ( 'should send reset password' , async ( ) => {
7243
7260
const clientMutationId = uuidv4 ( ) ;
7244
7261
const emailAdapter = {
7245
- sendVerificationEmail : ( ) => { } ,
7262
+ sendVerificationEmail : ( ) => { } ,
7246
7263
sendPasswordResetEmail : ( ) => Promise . resolve ( ) ,
7247
- sendMail : ( ) => { } ,
7264
+ sendMail : ( ) => { } ,
7248
7265
} ;
7249
7266
parseServer = await global . reconfigureServer ( {
7250
7267
appName : 'test' ,
@@ -7282,11 +7299,11 @@ describe('ParseGraphQLServer', () => {
7282
7299
const clientMutationId = uuidv4 ( ) ;
7283
7300
let resetPasswordToken ;
7284
7301
const emailAdapter = {
7285
- sendVerificationEmail : ( ) => { } ,
7302
+ sendVerificationEmail : ( ) => { } ,
7286
7303
sendPasswordResetEmail : ( { link } ) => {
7287
7304
resetPasswordToken = link . split ( 'token=' ) [ 1 ] . split ( '&' ) [ 0 ] ;
7288
7305
} ,
7289
- sendMail : ( ) => { } ,
7306
+ sendMail : ( ) => { } ,
7290
7307
} ;
7291
7308
parseServer = await global . reconfigureServer ( {
7292
7309
appName : 'test' ,
@@ -7351,9 +7368,9 @@ describe('ParseGraphQLServer', () => {
7351
7368
it ( 'should send verification email again' , async ( ) => {
7352
7369
const clientMutationId = uuidv4 ( ) ;
7353
7370
const emailAdapter = {
7354
- sendVerificationEmail : ( ) => { } ,
7371
+ sendVerificationEmail : ( ) => { } ,
7355
7372
sendPasswordResetEmail : ( ) => Promise . resolve ( ) ,
7356
- sendMail : ( ) => { } ,
7373
+ sendMail : ( ) => { } ,
7357
7374
} ;
7358
7375
parseServer = await global . reconfigureServer ( {
7359
7376
appName : 'test' ,
@@ -9109,7 +9126,7 @@ describe('ParseGraphQLServer', () => {
9109
9126
expect ( result6 [ 0 ] . node . name ) . toEqual ( 'imACountry3' ) ;
9110
9127
} ) ;
9111
9128
9112
- fit ( 'should support files' , async ( ) => {
9129
+ it ( 'should support files' , async ( ) => {
9113
9130
try {
9114
9131
parseServer = await global . reconfigureServer ( {
9115
9132
publicServerURL : 'http://localhost:13377/parse' ,
@@ -9152,7 +9169,6 @@ describe('ParseGraphQLServer', () => {
9152
9169
9153
9170
const result = JSON . parse ( await res . text ( ) ) ;
9154
9171
9155
- console . log ( result . errors )
9156
9172
expect ( result . data . createFile . fileInfo . name ) . toEqual (
9157
9173
jasmine . stringMatching ( / _ m y F i l e N a m e .t x t $ / )
9158
9174
) ;
@@ -9358,6 +9374,51 @@ describe('ParseGraphQLServer', () => {
9358
9374
}
9359
9375
} ) ;
9360
9376
9377
+ it ( 'should not upload if file is too large' , async ( ) => {
9378
+ parseGraphQLServer . parseServer . config . maxUploadSize = '1kb' ;
9379
+
9380
+ const body = new FormData ( ) ;
9381
+ body . append (
9382
+ 'operations' ,
9383
+ JSON . stringify ( {
9384
+ query : `
9385
+ mutation CreateFile($input: CreateFileInput!) {
9386
+ createFile(input: $input) {
9387
+ fileInfo {
9388
+ name
9389
+ url
9390
+ }
9391
+ }
9392
+ }
9393
+ ` ,
9394
+ variables : {
9395
+ input : {
9396
+ upload : null ,
9397
+ } ,
9398
+ } ,
9399
+ } )
9400
+ ) ;
9401
+ body . append ( 'map' , JSON . stringify ( { 1 : [ 'variables.input.upload' ] } ) ) ;
9402
+ body . append (
9403
+ '1' ,
9404
+ Buffer . alloc ( parseGraphQLServer . _transformMaxUploadSizeToBytes ( '2kb' ) , 1 ) ,
9405
+ {
9406
+ filename : 'myFileName.txt' ,
9407
+ contentType : 'text/plain' ,
9408
+ }
9409
+ ) ;
9410
+
9411
+ const res = await fetch ( 'http://localhost:13377/graphql' , {
9412
+ method : 'POST' ,
9413
+ headers,
9414
+ body,
9415
+ } ) ;
9416
+
9417
+ expect ( res . status ) . toEqual ( 200 ) ;
9418
+ const result = JSON . parse ( await res . text ( ) ) ;
9419
+ expect ( result . errors ) . toBeDefined ( ) ;
9420
+ } ) ;
9421
+
9361
9422
it ( 'should support object values' , async ( ) => {
9362
9423
try {
9363
9424
const someObjectFieldValue = {
@@ -10549,25 +10610,25 @@ describe('ParseGraphQLServer', () => {
10549
10610
} ,
10550
10611
} ) ;
10551
10612
const SomeClassType = new GraphQLObjectType ( {
10552
- name : 'SomeClass' ,
10553
- fields : {
10554
- nameUpperCase : {
10555
- type : new GraphQLNonNull ( GraphQLString ) ,
10556
- resolve : p => p . name . toUpperCase ( ) ,
10557
- } ,
10558
- type : { type : TypeEnum } ,
10559
- language : {
10560
- type : new GraphQLEnumType ( {
10561
- name : 'LanguageEnum' ,
10562
- values : {
10563
- fr : { value : 'fr' } ,
10564
- en : { value : 'en' } ,
10565
- } ,
10566
- } ) ,
10567
- resolve : ( ) => 'fr' ,
10613
+ name : 'SomeClass' ,
10614
+ fields : {
10615
+ nameUpperCase : {
10616
+ type : new GraphQLNonNull ( GraphQLString ) ,
10617
+ resolve : p => p . name . toUpperCase ( ) ,
10618
+ } ,
10619
+ type : { type : TypeEnum } ,
10620
+ language : {
10621
+ type : new GraphQLEnumType ( {
10622
+ name : 'LanguageEnum' ,
10623
+ values : {
10624
+ fr : { value : 'fr' } ,
10625
+ en : { value : 'en' } ,
10626
+ } ,
10627
+ } ) ,
10628
+ resolve : ( ) => 'fr' ,
10629
+ } ,
10568
10630
} ,
10569
- } ,
10570
- } ) ,
10631
+ } ) ,
10571
10632
parseGraphQLServer = new ParseGraphQLServer ( parseServer , {
10572
10633
graphQLPath : '/graphql' ,
10573
10634
graphQLCustomTypeDefs : new GraphQLSchema ( {
0 commit comments