Skip to content

Commit 0c84df8

Browse files
committed
#7517: Allow removing a pointer from a field
1 parent 2f557f8 commit 0c84df8

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

spec/ParseGraphQLServer.spec.js

+44
Original file line numberDiff line numberDiff line change
@@ -8323,6 +8323,50 @@ describe('ParseGraphQLServer', () => {
83238323
expect(result.company.name).toEqual('imACompany2');
83248324
});
83258325

8326+
it('should support removing pointer on update', async () => {
8327+
const company = new Parse.Object('Company');
8328+
company.set('name', 'imACompany1');
8329+
await company.save();
8330+
8331+
const country = new Parse.Object('Country');
8332+
country.set('name', 'imACountry');
8333+
country.set('company', company);
8334+
await country.save();
8335+
8336+
await parseGraphQLServer.parseGraphQLSchema.schemaCache.clear();
8337+
8338+
const {
8339+
data: {
8340+
updateCountry: { country: result },
8341+
},
8342+
} = await apolloClient.mutate({
8343+
mutation: gql`
8344+
mutation Update($id: ID!, $fields: UpdateCountryFieldsInput) {
8345+
updateCountry(input: { id: $id, fields: $fields }) {
8346+
country {
8347+
id
8348+
objectId
8349+
company {
8350+
id
8351+
objectId
8352+
name
8353+
}
8354+
}
8355+
}
8356+
}
8357+
`,
8358+
variables: {
8359+
id: country.id,
8360+
fields: {
8361+
company: { unlink: true },
8362+
},
8363+
},
8364+
});
8365+
8366+
expect(result.id).toBeDefined();
8367+
expect(result.company).toBeNull();
8368+
});
8369+
83268370
it_only_db('mongo')('should support relation and nested relation on create', async () => {
83278371
const company = new Parse.Object('Company');
83288372
company.set('name', 'imACompany1');

src/GraphQL/loaders/parseClassTypes.js

+4
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ const load = (parseGraphQLSchema, parseClass, parseClassConfig: ?ParseGraphQLCla
199199
description: `Link an existing object from ${graphQLClassName} class. You can use either the global or the object id.`,
200200
type: GraphQLID,
201201
},
202+
unlink: {
203+
description: `Unlink an existing object from ${graphQLClassName} class.`,
204+
type: GraphQLBoolean,
205+
},
202206
};
203207
if (isCreateEnabled) {
204208
fields['createAndLink'] = {

src/GraphQL/transformers/mutation.js

+3
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ const transformers = {
224224
objectId,
225225
};
226226
}
227+
if (value.unlink) {
228+
return null;
229+
}
227230
},
228231
};
229232

0 commit comments

Comments
 (0)