@@ -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 ( ) ,
@@ -106,11 +121,15 @@ describe('ParseGraphQLServer', () => {
106
121
} ;
107
122
108
123
it ( "should return schema and context with req's info, config and auth" , async ( ) => {
109
- const options = await parseGraphQLServer . _getGraphQLOptions ( req ) ;
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
- expect ( options . context . info ) . toEqual ( req . info ) ;
112
- expect ( options . context . config ) . toEqual ( req . config ) ;
113
- expect ( options . context . auth ) . toEqual ( req . auth ) ;
129
+ const contextResponse = options . context ( { req } ) ;
130
+ expect ( contextResponse . info ) . toEqual ( req . info ) ;
131
+ expect ( contextResponse . config ) . toEqual ( req . config ) ;
132
+ expect ( contextResponse . auth ) . toEqual ( req . auth ) ;
114
133
} ) ;
115
134
116
135
it ( 'should load GraphQL schema in every call' , async ( ) => {
@@ -467,7 +486,7 @@ describe('ParseGraphQLServer', () => {
467
486
}
468
487
} ) ;
469
488
470
- it ( 'should be cors enabled' , async ( ) => {
489
+ it ( 'should be cors enabled and scope the response within the source origin ' , async ( ) => {
471
490
let checked = false ;
472
491
const apolloClient = new ApolloClient ( {
473
492
link : new ApolloLink ( ( operation , forward ) => {
@@ -476,7 +495,7 @@ describe('ParseGraphQLServer', () => {
476
495
const {
477
496
response : { headers } ,
478
497
} = context ;
479
- expect ( headers . get ( 'access-control-allow-origin' ) ) . toEqual ( '* ' ) ;
498
+ expect ( headers . get ( 'access-control-allow-origin' ) ) . toEqual ( 'http://someorigin.com ' ) ;
480
499
checked = true ;
481
500
return response ;
482
501
} ) ;
@@ -504,14 +523,25 @@ describe('ParseGraphQLServer', () => {
504
523
} ) ;
505
524
506
525
it ( 'should handle Parse headers' , async ( ) => {
507
- let checked = false ;
526
+ const test = {
527
+ context : ( { req : { info, config, auth } } ) => {
528
+ expect ( req . info ) . toBeDefined ( ) ;
529
+ expect ( req . config ) . toBeDefined ( ) ;
530
+ expect ( req . auth ) . toBeDefined ( ) ;
531
+ return {
532
+ info,
533
+ config,
534
+ auth,
535
+ } ;
536
+ } ,
537
+ } ;
538
+ const contextSpy = spyOn ( test , 'context' ) ;
508
539
const originalGetGraphQLOptions = parseGraphQLServer . _getGraphQLOptions ;
509
- parseGraphQLServer . _getGraphQLOptions = async req => {
510
- expect ( req . info ) . toBeDefined ( ) ;
511
- expect ( req . config ) . toBeDefined ( ) ;
512
- expect ( req . auth ) . toBeDefined ( ) ;
513
- checked = true ;
514
- return await originalGetGraphQLOptions . bind ( parseGraphQLServer ) ( req ) ;
540
+ parseGraphQLServer . _getGraphQLOptions = async ( ) => {
541
+ return {
542
+ schema : await parseGraphQLServer . parseGraphQLSchema . load ( ) ,
543
+ context : test . context ,
544
+ } ;
515
545
} ;
516
546
const health = (
517
547
await apolloClient . query ( {
@@ -523,7 +553,7 @@ describe('ParseGraphQLServer', () => {
523
553
} )
524
554
) . data . health ;
525
555
expect ( health ) . toBeTruthy ( ) ;
526
- expect ( checked ) . toBeTruthy ( ) ;
556
+ expect ( contextSpy ) . toHaveBeenCalledTimes ( 1 ) ;
527
557
parseGraphQLServer . _getGraphQLOptions = originalGetGraphQLOptions ;
528
558
} ) ;
529
559
} ) ;
@@ -6786,7 +6816,7 @@ describe('ParseGraphQLServer', () => {
6786
6816
6787
6817
expect ( queryResult . data . customers . edges . length ) . toEqual ( 1 ) ;
6788
6818
} catch ( e ) {
6789
- console . log ( JSON . stringify ( e ) ) ;
6819
+ console . error ( JSON . stringify ( e ) ) ;
6790
6820
}
6791
6821
} ) ;
6792
6822
} ) ;
@@ -9107,15 +9137,15 @@ describe('ParseGraphQLServer', () => {
9107
9137
'operations' ,
9108
9138
JSON . stringify ( {
9109
9139
query : `
9110
- mutation CreateFile($input: CreateFileInput!) {
9111
- createFile(input: $input) {
9112
- fileInfo {
9113
- name
9114
- url
9140
+ mutation CreateFile($input: CreateFileInput!) {
9141
+ createFile(input: $input) {
9142
+ fileInfo {
9143
+ name
9144
+ url
9145
+ }
9115
9146
}
9116
9147
}
9117
- }
9118
- ` ,
9148
+ ` ,
9119
9149
variables : {
9120
9150
input : {
9121
9151
upload : null ,
@@ -9176,46 +9206,46 @@ describe('ParseGraphQLServer', () => {
9176
9206
'operations' ,
9177
9207
JSON . stringify ( {
9178
9208
query : `
9179
- mutation CreateSomeObject(
9180
- $fields1: CreateSomeClassFieldsInput
9181
- $fields2: CreateSomeClassFieldsInput
9182
- $fields3: CreateSomeClassFieldsInput
9183
- ) {
9184
- createSomeClass1: createSomeClass(
9185
- input: { fields: $fields1 }
9209
+ mutation CreateSomeObject(
9210
+ $fields1: CreateSomeClassFieldsInput
9211
+ $fields2: CreateSomeClassFieldsInput
9212
+ $fields3: CreateSomeClassFieldsInput
9186
9213
) {
9187
- someClass {
9188
- id
9189
- someField {
9190
- name
9191
- url
9214
+ createSomeClass1: createSomeClass(
9215
+ input: { fields: $fields1 }
9216
+ ) {
9217
+ someClass {
9218
+ id
9219
+ someField {
9220
+ name
9221
+ url
9222
+ }
9192
9223
}
9193
9224
}
9194
- }
9195
- createSomeClass2: createSomeClass(
9196
- input: { fields: $fields2 }
9197
- ) {
9198
- someClass {
9199
- id
9200
- someField {
9201
- name
9202
- url
9225
+ createSomeClass2: createSomeClass(
9226
+ input: { fields: $fields2 }
9227
+ ) {
9228
+ someClass {
9229
+ id
9230
+ someField {
9231
+ name
9232
+ url
9233
+ }
9203
9234
}
9204
9235
}
9205
- }
9206
- createSomeClass3: createSomeClass(
9207
- input: { fields: $fields3 }
9208
- ) {
9209
- someClass {
9210
- id
9211
- someField {
9212
- name
9213
- url
9236
+ createSomeClass3: createSomeClass(
9237
+ input: { fields: $fields3 }
9238
+ ) {
9239
+ someClass {
9240
+ id
9241
+ someField {
9242
+ name
9243
+ url
9244
+ }
9214
9245
}
9215
9246
}
9216
9247
}
9217
- }
9218
- ` ,
9248
+ ` ,
9219
9249
variables : {
9220
9250
fields1 : {
9221
9251
someField : { file : someFieldValue } ,
@@ -9344,6 +9374,51 @@ describe('ParseGraphQLServer', () => {
9344
9374
}
9345
9375
} ) ;
9346
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
+ const result = JSON . parse ( await res . text ( ) ) ;
9418
+ expect ( res . status ) . toEqual ( 500 ) ;
9419
+ expect ( result . errors [ 0 ] . message ) . toEqual ( 'File size limit exceeded: 1024 bytes' ) ;
9420
+ } ) ;
9421
+
9347
9422
it ( 'should support object values' , async ( ) => {
9348
9423
try {
9349
9424
const someObjectFieldValue = {
0 commit comments