@@ -17,6 +17,7 @@ const gql = require('graphql-tag');
17
17
const { ParseServer } = require ( '../' ) ;
18
18
const { ParseGraphQLServer } = require ( '../lib/GraphQL/ParseGraphQLServer' ) ;
19
19
const ReadPreference = require ( 'mongodb' ) . ReadPreference ;
20
+ const uuidv4 = require ( 'uuid/v4' ) ;
20
21
21
22
function handleError ( e ) {
22
23
if (
@@ -780,6 +781,45 @@ describe('ParseGraphQLServer', () => {
780
781
expect ( userFields ) . toContain ( 'id' ) ;
781
782
expect ( userFields ) . toContain ( 'objectId' ) ;
782
783
} ) ;
784
+
785
+ it ( 'should have clientMutationId in create file input' , async ( ) => {
786
+ const createFileInputFields = ( await apolloClient . query ( {
787
+ query : gql `
788
+ query {
789
+ __type(name: "CreateFileInput") {
790
+ inputFields {
791
+ name
792
+ }
793
+ }
794
+ }
795
+ ` ,
796
+ } ) ) . data [ '__type' ] . inputFields
797
+ . map ( field => field . name )
798
+ . sort ( ) ;
799
+
800
+ expect ( createFileInputFields ) . toEqual ( [ 'clientMutationId' , 'upload' ] ) ;
801
+ } ) ;
802
+
803
+ it ( 'should have clientMutationId in create file payload' , async ( ) => {
804
+ const createFilePayloadFields = ( await apolloClient . query ( {
805
+ query : gql `
806
+ query {
807
+ __type(name: "CreateFilePayload") {
808
+ fields {
809
+ name
810
+ }
811
+ }
812
+ }
813
+ ` ,
814
+ } ) ) . data [ '__type' ] . fields
815
+ . map ( field => field . name )
816
+ . sort ( ) ;
817
+
818
+ expect ( createFilePayloadFields ) . toEqual ( [
819
+ 'clientMutationId' ,
820
+ 'fileInfo' ,
821
+ ] ) ;
822
+ } ) ;
783
823
} ) ;
784
824
785
825
describe ( 'Parse Class Types' , ( ) => {
@@ -5510,6 +5550,8 @@ describe('ParseGraphQLServer', () => {
5510
5550
describe ( 'Files Mutations' , ( ) => {
5511
5551
describe ( 'Create' , ( ) => {
5512
5552
it ( 'should return File object' , async ( ) => {
5553
+ const clientMutationId = uuidv4 ( ) ;
5554
+
5513
5555
parseServer = await global . reconfigureServer ( {
5514
5556
publicServerURL : 'http://localhost:13377/parse' ,
5515
5557
} ) ;
@@ -5519,19 +5561,28 @@ describe('ParseGraphQLServer', () => {
5519
5561
'operations' ,
5520
5562
JSON . stringify ( {
5521
5563
query : `
5522
- mutation CreateFile($upload: Upload!) {
5523
- createFile(upload: $upload) {
5524
- name
5525
- url
5564
+ mutation CreateFile($input: CreateFileInput!) {
5565
+ createFile(input: $input) {
5566
+ clientMutationId
5567
+ fileInfo {
5568
+ name
5569
+ url
5570
+ }
5526
5571
}
5527
5572
}
5528
5573
` ,
5529
5574
variables : {
5530
- upload : null ,
5575
+ input : {
5576
+ clientMutationId,
5577
+ upload : null ,
5578
+ } ,
5531
5579
} ,
5532
5580
} )
5533
5581
) ;
5534
- body . append ( 'map' , JSON . stringify ( { 1 : [ 'variables.upload' ] } ) ) ;
5582
+ body . append (
5583
+ 'map' ,
5584
+ JSON . stringify ( { 1 : [ 'variables.input.upload' ] } )
5585
+ ) ;
5535
5586
body . append ( '1' , 'My File Content' , {
5536
5587
filename : 'myFileName.txt' ,
5537
5588
contentType : 'text/plain' ,
@@ -5547,14 +5598,17 @@ describe('ParseGraphQLServer', () => {
5547
5598
5548
5599
const result = JSON . parse ( await res . text ( ) ) ;
5549
5600
5550
- expect ( result . data . createFile . name ) . toEqual (
5601
+ expect ( result . data . createFile . clientMutationId ) . toEqual (
5602
+ clientMutationId
5603
+ ) ;
5604
+ expect ( result . data . createFile . fileInfo . name ) . toEqual (
5551
5605
jasmine . stringMatching ( / _ m y F i l e N a m e .t x t $ / )
5552
5606
) ;
5553
- expect ( result . data . createFile . url ) . toEqual (
5607
+ expect ( result . data . createFile . fileInfo . url ) . toEqual (
5554
5608
jasmine . stringMatching ( / _ m y F i l e N a m e .t x t $ / )
5555
5609
) ;
5556
5610
5557
- res = await fetch ( result . data . createFile . url ) ;
5611
+ res = await fetch ( result . data . createFile . fileInfo . url ) ;
5558
5612
5559
5613
expect ( res . status ) . toEqual ( 200 ) ;
5560
5614
expect ( await res . text ( ) ) . toEqual ( 'My File Content' ) ;
@@ -7056,19 +7110,26 @@ describe('ParseGraphQLServer', () => {
7056
7110
'operations' ,
7057
7111
JSON . stringify ( {
7058
7112
query : `
7059
- mutation CreateFile($upload: Upload!) {
7060
- createFile(upload: $upload) {
7061
- name
7062
- url
7113
+ mutation CreateFile($input: CreateFileInput!) {
7114
+ createFile(input: $input) {
7115
+ fileInfo {
7116
+ name
7117
+ url
7118
+ }
7063
7119
}
7064
7120
}
7065
7121
` ,
7066
7122
variables : {
7067
- upload : null ,
7123
+ input : {
7124
+ upload : null ,
7125
+ } ,
7068
7126
} ,
7069
7127
} )
7070
7128
) ;
7071
- body . append ( 'map' , JSON . stringify ( { 1 : [ 'variables.upload' ] } ) ) ;
7129
+ body . append (
7130
+ 'map' ,
7131
+ JSON . stringify ( { 1 : [ 'variables.input.upload' ] } )
7132
+ ) ;
7072
7133
body . append ( '1' , 'My File Content' , {
7073
7134
filename : 'myFileName.txt' ,
7074
7135
contentType : 'text/plain' ,
@@ -7084,14 +7145,14 @@ describe('ParseGraphQLServer', () => {
7084
7145
7085
7146
const result = JSON . parse ( await res . text ( ) ) ;
7086
7147
7087
- expect ( result . data . createFile . name ) . toEqual (
7148
+ expect ( result . data . createFile . fileInfo . name ) . toEqual (
7088
7149
jasmine . stringMatching ( / _ m y F i l e N a m e .t x t $ / )
7089
7150
) ;
7090
- expect ( result . data . createFile . url ) . toEqual (
7151
+ expect ( result . data . createFile . fileInfo . url ) . toEqual (
7091
7152
jasmine . stringMatching ( / _ m y F i l e N a m e .t x t $ / )
7092
7153
) ;
7093
7154
7094
- const someFieldValue = result . data . createFile . name ;
7155
+ const someFieldValue = result . data . createFile . fileInfo . name ;
7095
7156
7096
7157
await apolloClient . mutate ( {
7097
7158
mutation : gql `
@@ -7180,10 +7241,10 @@ describe('ParseGraphQLServer', () => {
7180
7241
7181
7242
expect ( typeof getResult . data . someClass . someField ) . toEqual ( 'object' ) ;
7182
7243
expect ( getResult . data . someClass . someField . name ) . toEqual (
7183
- result . data . createFile . name
7244
+ result . data . createFile . fileInfo . name
7184
7245
) ;
7185
7246
expect ( getResult . data . someClass . someField . url ) . toEqual (
7186
- result . data . createFile . url
7247
+ result . data . createFile . fileInfo . url
7187
7248
) ;
7188
7249
expect ( getResult . data . findSomeClass1 . results . length ) . toEqual ( 1 ) ;
7189
7250
expect ( getResult . data . findSomeClass2 . results . length ) . toEqual ( 1 ) ;
0 commit comments