Skip to content

Commit 2fbeeb9

Browse files
Moumoulsdavimacedo
authored andcommitted
Return specific Type on specific Mutation (parse-community#5893)
* Return specific Type on specific Mutation * Add Optimization on Mutation * Optimize SignUp
1 parent 14c8b26 commit 2fbeeb9

File tree

5 files changed

+259
-95
lines changed

5 files changed

+259
-95
lines changed

spec/ParseGraphQLServer.spec.js

Lines changed: 69 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,9 @@ describe('ParseGraphQLServer', () => {
10041004
query: gql`
10051005
mutation DeleteCustomer($objectId: ID!) {
10061006
objects {
1007-
deleteCustomer(objectId: $objectId)
1007+
deleteCustomer(objectId: $objectId) {
1008+
objectId
1009+
}
10081010
}
10091011
}
10101012
`,
@@ -1094,7 +1096,9 @@ describe('ParseGraphQLServer', () => {
10941096
query: gql`
10951097
mutation DeleteSuperCar($objectId: ID!) {
10961098
objects {
1097-
deleteSuperCar(objectId: $objectId)
1099+
deleteSuperCar(objectId: $objectId) {
1100+
objectId
1101+
}
10981102
}
10991103
}
11001104
`,
@@ -3150,7 +3154,7 @@ describe('ParseGraphQLServer', () => {
31503154
expect(obj.get('someField')).toEqual('someValue');
31513155
});
31523156

3153-
it('should return CreateResult object using class specific mutation', async () => {
3157+
it('should return specific type object using class specific mutation', async () => {
31543158
const customerSchema = new Parse.Schema('Customer');
31553159
customerSchema.addString('someField');
31563160
await customerSchema.save();
@@ -3164,6 +3168,7 @@ describe('ParseGraphQLServer', () => {
31643168
createCustomer(fields: $fields) {
31653169
objectId
31663170
createdAt
3171+
someField
31673172
}
31683173
}
31693174
}
@@ -3176,6 +3181,9 @@ describe('ParseGraphQLServer', () => {
31763181
});
31773182

31783183
expect(result.data.objects.createCustomer.objectId).toBeDefined();
3184+
expect(result.data.objects.createCustomer.someField).toEqual(
3185+
'someValue'
3186+
);
31793187

31803188
const customer = await new Parse.Query('Customer').get(
31813189
result.data.objects.createCustomer.objectId
@@ -3313,7 +3321,7 @@ describe('ParseGraphQLServer', () => {
33133321
expect(obj.get('someField2')).toEqual('someField2Value1');
33143322
});
33153323

3316-
it('should return UpdateResult object using class specific mutation', async () => {
3324+
it('should return specific type object using class specific mutation', async () => {
33173325
const obj = new Parse.Object('Customer');
33183326
obj.set('someField1', 'someField1Value1');
33193327
obj.set('someField2', 'someField2Value1');
@@ -3330,6 +3338,8 @@ describe('ParseGraphQLServer', () => {
33303338
objects {
33313339
updateCustomer(objectId: $objectId, fields: $fields) {
33323340
updatedAt
3341+
someField1
3342+
someField2
33333343
}
33343344
}
33353345
}
@@ -3343,6 +3353,12 @@ describe('ParseGraphQLServer', () => {
33433353
});
33443354

33453355
expect(result.data.objects.updateCustomer.updatedAt).toBeDefined();
3356+
expect(result.data.objects.updateCustomer.someField1).toEqual(
3357+
'someField1Value2'
3358+
);
3359+
expect(result.data.objects.updateCustomer.someField2).toEqual(
3360+
'someField2Value1'
3361+
);
33463362

33473363
await obj.fetch();
33483364

@@ -3737,8 +3753,10 @@ describe('ParseGraphQLServer', () => {
37373753
).toBeRejectedWith(jasmine.stringMatching('Object not found'));
37383754
});
37393755

3740-
it('should return a boolean confirmation using class specific mutation', async () => {
3756+
it('should return a specific type using class specific mutation', async () => {
37413757
const obj = new Parse.Object('Customer');
3758+
obj.set('someField1', 'someField1Value1');
3759+
obj.set('someField2', 'someField2Value1');
37423760
await obj.save();
37433761

37443762
await parseGraphQLServer.parseGraphQLSchema.databaseController.schemaCache.clear();
@@ -3747,7 +3765,11 @@ describe('ParseGraphQLServer', () => {
37473765
mutation: gql`
37483766
mutation DeleteCustomer($objectId: ID!) {
37493767
objects {
3750-
deleteCustomer(objectId: $objectId)
3768+
deleteCustomer(objectId: $objectId) {
3769+
objectId
3770+
someField1
3771+
someField2
3772+
}
37513773
}
37523774
}
37533775
`,
@@ -3756,7 +3778,13 @@ describe('ParseGraphQLServer', () => {
37563778
},
37573779
});
37583780

3759-
expect(result.data.objects.deleteCustomer).toEqual(true);
3781+
expect(result.data.objects.deleteCustomer.objectId).toEqual(obj.id);
3782+
expect(result.data.objects.deleteCustomer.someField1).toEqual(
3783+
'someField1Value1'
3784+
);
3785+
expect(result.data.objects.deleteCustomer.someField2).toEqual(
3786+
'someField2Value1'
3787+
);
37603788

37613789
await expectAsync(
37623790
obj.fetch({ useMasterKey: true })
@@ -3855,7 +3883,9 @@ describe('ParseGraphQLServer', () => {
38553883
$objectId: ID!
38563884
) {
38573885
objects {
3858-
delete${className}(objectId: $objectId)
3886+
delete${className}(objectId: $objectId) {
3887+
objectId
3888+
}
38593889
}
38603890
}
38613891
`,
@@ -3893,32 +3923,32 @@ describe('ParseGraphQLServer', () => {
38933923
expect(
38943924
(await deleteObject(object4.className, object4.id)).data.objects[
38953925
`delete${object4.className}`
3896-
]
3897-
).toEqual(true);
3926+
].objectId
3927+
).toEqual(object4.id);
38983928
await expectAsync(
38993929
object4.fetch({ useMasterKey: true })
39003930
).toBeRejectedWith(jasmine.stringMatching('Object not found'));
39013931
expect(
39023932
(await deleteObject(object1.className, object1.id, {
39033933
'X-Parse-Master-Key': 'test',
3904-
})).data.objects[`delete${object1.className}`]
3905-
).toEqual(true);
3934+
})).data.objects[`delete${object1.className}`].objectId
3935+
).toEqual(object1.id);
39063936
await expectAsync(
39073937
object1.fetch({ useMasterKey: true })
39083938
).toBeRejectedWith(jasmine.stringMatching('Object not found'));
39093939
expect(
39103940
(await deleteObject(object2.className, object2.id, {
39113941
'X-Parse-Session-Token': user2.getSessionToken(),
3912-
})).data.objects[`delete${object2.className}`]
3913-
).toEqual(true);
3942+
})).data.objects[`delete${object2.className}`].objectId
3943+
).toEqual(object2.id);
39143944
await expectAsync(
39153945
object2.fetch({ useMasterKey: true })
39163946
).toBeRejectedWith(jasmine.stringMatching('Object not found'));
39173947
expect(
39183948
(await deleteObject(object3.className, object3.id, {
39193949
'X-Parse-Session-Token': user5.getSessionToken(),
3920-
})).data.objects[`delete${object3.className}`]
3921-
).toEqual(true);
3950+
})).data.objects[`delete${object3.className}`].objectId
3951+
).toEqual(object3.id);
39223952
await expectAsync(
39233953
object3.fetch({ useMasterKey: true })
39243954
).toBeRejectedWith(jasmine.stringMatching('Object not found'));
@@ -4078,12 +4108,17 @@ describe('ParseGraphQLServer', () => {
40784108

40794109
describe('Users Mutations', () => {
40804110
it('should sign user up', async () => {
4111+
const userSchema = new Parse.Schema('_User');
4112+
userSchema.addString('someField');
4113+
await userSchema.update();
4114+
await parseGraphQLServer.parseGraphQLSchema.databaseController.schemaCache.clear();
40814115
const result = await apolloClient.mutate({
40824116
mutation: gql`
40834117
mutation SignUp($fields: _UserSignUpFields) {
40844118
users {
40854119
signUp(fields: $fields) {
40864120
sessionToken
4121+
someField
40874122
}
40884123
}
40894124
}
@@ -4092,38 +4127,45 @@ describe('ParseGraphQLServer', () => {
40924127
fields: {
40934128
username: 'user1',
40944129
password: 'user1',
4130+
someField: 'someValue',
40954131
},
40964132
},
40974133
});
40984134

40994135
expect(result.data.users.signUp.sessionToken).toBeDefined();
4136+
expect(result.data.users.signUp.someField).toEqual('someValue');
41004137
expect(typeof result.data.users.signUp.sessionToken).toBe('string');
41014138
});
41024139

41034140
it('should log the user in', async () => {
41044141
const user = new Parse.User();
41054142
user.setUsername('user1');
41064143
user.setPassword('user1');
4144+
user.set('someField', 'someValue');
41074145
await user.signUp();
41084146
await Parse.User.logOut();
4109-
4147+
await parseGraphQLServer.parseGraphQLSchema.databaseController.schemaCache.clear();
41104148
const result = await apolloClient.mutate({
41114149
mutation: gql`
4112-
mutation LogInUser($username: String!, $password: String!) {
4150+
mutation LogInUser($input: _UserLoginFields) {
41134151
users {
4114-
logIn(username: $username, password: $password) {
4152+
logIn(input: $input) {
41154153
sessionToken
4154+
someField
41164155
}
41174156
}
41184157
}
41194158
`,
41204159
variables: {
4121-
username: 'user1',
4122-
password: 'user1',
4160+
input: {
4161+
username: 'user1',
4162+
password: 'user1',
4163+
},
41234164
},
41244165
});
41254166

41264167
expect(result.data.users.logIn.sessionToken).toBeDefined();
4168+
expect(result.data.users.logIn.someField).toEqual('someValue');
41274169
expect(typeof result.data.users.logIn.sessionToken).toBe('string');
41284170
});
41294171

@@ -4136,17 +4178,19 @@ describe('ParseGraphQLServer', () => {
41364178

41374179
const logIn = await apolloClient.mutate({
41384180
mutation: gql`
4139-
mutation LogInUser($username: String!, $password: String!) {
4181+
mutation LogInUser($input: _UserLoginFields) {
41404182
users {
4141-
logIn(username: $username, password: $password) {
4183+
logIn(input: $input) {
41424184
sessionToken
41434185
}
41444186
}
41454187
}
41464188
`,
41474189
variables: {
4148-
username: 'user1',
4149-
password: 'user1',
4190+
input: {
4191+
username: 'user1',
4192+
password: 'user1',
4193+
},
41504194
},
41514195
});
41524196

0 commit comments

Comments
 (0)