@@ -98,6 +98,24 @@ describe('ParseGraphQLServer', () => {
9898 } ) ;
9999 } ) ;
100100
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+ // Trigger a schema change
109+ const obj = new Parse . Object ( 'SomeClass' ) ;
110+ await obj . save ( ) ;
111+
112+ const server3 = await parseGraphQLServer . _getServer ( ) ;
113+ const server4 = await parseGraphQLServer . _getServer ( ) ;
114+ expect ( server3 ) . not . toBe ( server2 ) ;
115+ expect ( server3 ) . toBe ( server4 ) ;
116+ } ) ;
117+ } ) ;
118+
101119 describe ( '_getGraphQLOptions' , ( ) => {
102120 const req = {
103121 info : new Object ( ) ,
@@ -106,11 +124,15 @@ describe('ParseGraphQLServer', () => {
106124 } ;
107125
108126 it ( "should return schema and context with req's info, config and auth" , async ( ) => {
109- const options = await parseGraphQLServer . _getGraphQLOptions ( req ) ;
127+ const options = await parseGraphQLServer . _getGraphQLOptions ( ) ;
128+ expect ( options . multipart ) . toEqual ( {
129+ fileSize : 20971520 ,
130+ } ) ;
110131 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 ) ;
132+ const contextResponse = options . context ( { req } ) ;
133+ expect ( contextResponse . info ) . toEqual ( req . info ) ;
134+ expect ( contextResponse . config ) . toEqual ( req . config ) ;
135+ expect ( contextResponse . auth ) . toEqual ( req . auth ) ;
114136 } ) ;
115137
116138 it ( 'should load GraphQL schema in every call' , async ( ) => {
@@ -467,7 +489,7 @@ describe('ParseGraphQLServer', () => {
467489 }
468490 } ) ;
469491
470- it ( 'should be cors enabled' , async ( ) => {
492+ it ( 'should be cors enabled and scope the response within the source origin ' , async ( ) => {
471493 let checked = false ;
472494 const apolloClient = new ApolloClient ( {
473495 link : new ApolloLink ( ( operation , forward ) => {
@@ -476,7 +498,7 @@ describe('ParseGraphQLServer', () => {
476498 const {
477499 response : { headers } ,
478500 } = context ;
479- expect ( headers . get ( 'access-control-allow-origin' ) ) . toEqual ( '* ' ) ;
501+ expect ( headers . get ( 'access-control-allow-origin' ) ) . toEqual ( 'http://example.com ' ) ;
480502 checked = true ;
481503 return response ;
482504 } ) ;
@@ -486,7 +508,7 @@ describe('ParseGraphQLServer', () => {
486508 fetch,
487509 headers : {
488510 ...headers ,
489- Origin : 'http://someorigin .com' ,
511+ Origin : 'http://example .com' ,
490512 } ,
491513 } )
492514 ) ,
@@ -504,14 +526,25 @@ describe('ParseGraphQLServer', () => {
504526 } ) ;
505527
506528 it ( 'should handle Parse headers' , async ( ) => {
507- let checked = false ;
529+ const test = {
530+ context : ( { req : { info, config, auth } } ) => {
531+ expect ( req . info ) . toBeDefined ( ) ;
532+ expect ( req . config ) . toBeDefined ( ) ;
533+ expect ( req . auth ) . toBeDefined ( ) ;
534+ return {
535+ info,
536+ config,
537+ auth,
538+ } ;
539+ } ,
540+ } ;
541+ const contextSpy = spyOn ( test , 'context' ) ;
508542 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 ) ;
543+ parseGraphQLServer . _getGraphQLOptions = async ( ) => {
544+ return {
545+ schema : await parseGraphQLServer . parseGraphQLSchema . load ( ) ,
546+ context : test . context ,
547+ } ;
515548 } ;
516549 const health = (
517550 await apolloClient . query ( {
@@ -523,7 +556,7 @@ describe('ParseGraphQLServer', () => {
523556 } )
524557 ) . data . health ;
525558 expect ( health ) . toBeTruthy ( ) ;
526- expect ( checked ) . toBeTruthy ( ) ;
559+ expect ( contextSpy ) . toHaveBeenCalledTimes ( 1 ) ;
527560 parseGraphQLServer . _getGraphQLOptions = originalGetGraphQLOptions ;
528561 } ) ;
529562 } ) ;
@@ -6786,7 +6819,7 @@ describe('ParseGraphQLServer', () => {
67866819
67876820 expect ( queryResult . data . customers . edges . length ) . toEqual ( 1 ) ;
67886821 } catch ( e ) {
6789- console . log ( JSON . stringify ( e ) ) ;
6822+ console . error ( JSON . stringify ( e ) ) ;
67906823 }
67916824 } ) ;
67926825 } ) ;
@@ -9107,15 +9140,15 @@ describe('ParseGraphQLServer', () => {
91079140 'operations' ,
91089141 JSON . stringify ( {
91099142 query : `
9110- mutation CreateFile($input: CreateFileInput!) {
9111- createFile(input: $input) {
9112- fileInfo {
9113- name
9114- url
9143+ mutation CreateFile($input: CreateFileInput!) {
9144+ createFile(input: $input) {
9145+ fileInfo {
9146+ name
9147+ url
9148+ }
91159149 }
91169150 }
9117- }
9118- ` ,
9151+ ` ,
91199152 variables : {
91209153 input : {
91219154 upload : null ,
@@ -9176,46 +9209,46 @@ describe('ParseGraphQLServer', () => {
91769209 'operations' ,
91779210 JSON . stringify ( {
91789211 query : `
9179- mutation CreateSomeObject(
9180- $fields1: CreateSomeClassFieldsInput
9181- $fields2: CreateSomeClassFieldsInput
9182- $fields3: CreateSomeClassFieldsInput
9183- ) {
9184- createSomeClass1: createSomeClass(
9185- input: { fields: $fields1 }
9212+ mutation CreateSomeObject(
9213+ $fields1: CreateSomeClassFieldsInput
9214+ $fields2: CreateSomeClassFieldsInput
9215+ $fields3: CreateSomeClassFieldsInput
91869216 ) {
9187- someClass {
9188- id
9189- someField {
9190- name
9191- url
9217+ createSomeClass1: createSomeClass(
9218+ input: { fields: $fields1 }
9219+ ) {
9220+ someClass {
9221+ id
9222+ someField {
9223+ name
9224+ url
9225+ }
91929226 }
91939227 }
9194- }
9195- createSomeClass2: createSomeClass(
9196- input: { fields: $fields2 }
9197- ) {
9198- someClass {
9199- id
9200- someField {
9201- name
9202- url
9228+ createSomeClass2: createSomeClass(
9229+ input: { fields: $fields2 }
9230+ ) {
9231+ someClass {
9232+ id
9233+ someField {
9234+ name
9235+ url
9236+ }
92039237 }
92049238 }
9205- }
9206- createSomeClass3: createSomeClass(
9207- input: { fields: $fields3 }
9208- ) {
9209- someClass {
9210- id
9211- someField {
9212- name
9213- url
9239+ createSomeClass3: createSomeClass(
9240+ input: { fields: $fields3 }
9241+ ) {
9242+ someClass {
9243+ id
9244+ someField {
9245+ name
9246+ url
9247+ }
92149248 }
92159249 }
92169250 }
9217- }
9218- ` ,
9251+ ` ,
92199252 variables : {
92209253 fields1 : {
92219254 someField : { file : someFieldValue } ,
@@ -9344,6 +9377,51 @@ describe('ParseGraphQLServer', () => {
93449377 }
93459378 } ) ;
93469379
9380+ it_only_node_version ( '<17' ) ( 'should not upload if file is too large' , async ( ) => {
9381+ parseGraphQLServer . parseServer . config . maxUploadSize = '1kb' ;
9382+
9383+ const body = new FormData ( ) ;
9384+ body . append (
9385+ 'operations' ,
9386+ JSON . stringify ( {
9387+ query : `
9388+ mutation CreateFile($input: CreateFileInput!) {
9389+ createFile(input: $input) {
9390+ fileInfo {
9391+ name
9392+ url
9393+ }
9394+ }
9395+ }
9396+ ` ,
9397+ variables : {
9398+ input : {
9399+ upload : null ,
9400+ } ,
9401+ } ,
9402+ } )
9403+ ) ;
9404+ body . append ( 'map' , JSON . stringify ( { 1 : [ 'variables.input.upload' ] } ) ) ;
9405+ body . append (
9406+ '1' ,
9407+ Buffer . alloc ( parseGraphQLServer . _transformMaxUploadSizeToBytes ( '2kb' ) , 1 ) ,
9408+ {
9409+ filename : 'myFileName.txt' ,
9410+ contentType : 'text/plain' ,
9411+ }
9412+ ) ;
9413+
9414+ const res = await fetch ( 'http://localhost:13377/graphql' , {
9415+ method : 'POST' ,
9416+ headers,
9417+ body,
9418+ } ) ;
9419+
9420+ const result = JSON . parse ( await res . text ( ) ) ;
9421+ expect ( res . status ) . toEqual ( 500 ) ;
9422+ expect ( result . errors [ 0 ] . message ) . toEqual ( 'File size limit exceeded: 1024 bytes' ) ;
9423+ } ) ;
9424+
93479425 it ( 'should support object values' , async ( ) => {
93489426 try {
93499427 const someObjectFieldValue = {
0 commit comments