@@ -98,6 +98,21 @@ 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+ 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+
101116 describe ( '_getGraphQLOptions' , ( ) => {
102117 const req = {
103118 info : new Object ( ) ,
@@ -106,11 +121,15 @@ describe('ParseGraphQLServer', () => {
106121 } ;
107122
108123 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+ } ) ;
110128 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 ) ;
114133 } ) ;
115134
116135 it ( 'should load GraphQL schema in every call' , async ( ) => {
@@ -467,7 +486,7 @@ describe('ParseGraphQLServer', () => {
467486 }
468487 } ) ;
469488
470- it ( 'should be cors enabled' , async ( ) => {
489+ it ( 'should be cors enabled and scope the response within the source origin ' , async ( ) => {
471490 let checked = false ;
472491 const apolloClient = new ApolloClient ( {
473492 link : new ApolloLink ( ( operation , forward ) => {
@@ -476,7 +495,7 @@ describe('ParseGraphQLServer', () => {
476495 const {
477496 response : { headers } ,
478497 } = context ;
479- expect ( headers . get ( 'access-control-allow-origin' ) ) . toEqual ( '* ' ) ;
498+ expect ( headers . get ( 'access-control-allow-origin' ) ) . toEqual ( 'http://someorigin.com ' ) ;
480499 checked = true ;
481500 return response ;
482501 } ) ;
@@ -504,14 +523,25 @@ describe('ParseGraphQLServer', () => {
504523 } ) ;
505524
506525 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' ) ;
508539 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+ } ;
515545 } ;
516546 const health = (
517547 await apolloClient . query ( {
@@ -523,7 +553,7 @@ describe('ParseGraphQLServer', () => {
523553 } )
524554 ) . data . health ;
525555 expect ( health ) . toBeTruthy ( ) ;
526- expect ( checked ) . toBeTruthy ( ) ;
556+ expect ( contextSpy ) . toHaveBeenCalledTimes ( 1 ) ;
527557 parseGraphQLServer . _getGraphQLOptions = originalGetGraphQLOptions ;
528558 } ) ;
529559 } ) ;
@@ -6786,7 +6816,7 @@ describe('ParseGraphQLServer', () => {
67866816
67876817 expect ( queryResult . data . customers . edges . length ) . toEqual ( 1 ) ;
67886818 } catch ( e ) {
6789- console . log ( JSON . stringify ( e ) ) ;
6819+ console . error ( JSON . stringify ( e ) ) ;
67906820 }
67916821 } ) ;
67926822 } ) ;
@@ -9107,15 +9137,15 @@ describe('ParseGraphQLServer', () => {
91079137 'operations' ,
91089138 JSON . stringify ( {
91099139 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+ }
91159146 }
91169147 }
9117- }
9118- ` ,
9148+ ` ,
91199149 variables : {
91209150 input : {
91219151 upload : null ,
@@ -9176,46 +9206,46 @@ describe('ParseGraphQLServer', () => {
91769206 'operations' ,
91779207 JSON . stringify ( {
91789208 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
91869213 ) {
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+ }
91929223 }
91939224 }
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+ }
92039234 }
92049235 }
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+ }
92149245 }
92159246 }
92169247 }
9217- }
9218- ` ,
9248+ ` ,
92199249 variables : {
92209250 fields1 : {
92219251 someField : { file : someFieldValue } ,
@@ -9344,6 +9374,51 @@ describe('ParseGraphQLServer', () => {
93449374 }
93459375 } ) ;
93469376
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+
93479422 it ( 'should support object values' , async ( ) => {
93489423 try {
93499424 const someObjectFieldValue = {
0 commit comments