Skip to content

feat: allow removing a pointer from a field #7518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ ___
## Breaking Changes
- (none)
## Features
- (none)
- Allow a pointer to be removed using GraphQL (Chris Bland) [#7517](https://github.com/parse-community/parse-server/issues/7517)
## Bug Fixes
- (none)

67 changes: 67 additions & 0 deletions spec/ParseGraphQLServer.spec.js
Original file line number Diff line number Diff line change
@@ -8321,6 +8321,73 @@ describe('ParseGraphQLServer', () => {
expect(result.company.name).toEqual('imACompany2');
});

it('should support removing pointer on update', async () => {
const company = new Parse.Object('Company');
company.set('name', 'imACompany1');
await company.save();

const country = new Parse.Object('Country');
country.set('name', 'imACountry');
country.set('company', company);
await country.save();

await parseGraphQLServer.parseGraphQLSchema.schemaCache.clear();

const {
data: {
updateCountry: { country: result },
},
} = await apolloClient.mutate({
mutation: gql`
mutation Update($id: ID!, $fields: UpdateCountryFieldsInput) {
updateCountry(input: { id: $id, fields: $fields }) {
country {
id
objectId
company {
id
objectId
name
}
}
}
}
`,
variables: {
id: country.id,
fields: {
company: { unlink: true },
},
},
});

expect(result.id).toBeDefined();
expect(result.company).toBeNull();

const {
data: { country: result1 },
} = await apolloClient.query({
query: gql`
query getCountry($id: ID!) {
country(id: $id) {
id
objectId
company {
id
objectId
name
}
}
}
`,
variables: {
id: country.id,
},
});

expect(result1.countries).toBeNull();
});

it_only_db('mongo')('should support relation and nested relation on create', async () => {
const company = new Parse.Object('Company');
company.set('name', 'imACompany1');
4 changes: 4 additions & 0 deletions src/GraphQL/loaders/parseClassTypes.js
Original file line number Diff line number Diff line change
@@ -199,6 +199,10 @@ const load = (parseGraphQLSchema, parseClass, parseClassConfig: ?ParseGraphQLCla
description: `Link an existing object from ${graphQLClassName} class. You can use either the global or the object id.`,
type: GraphQLID,
},
unlink: {
description: `Unlink an existing object from ${graphQLClassName} class.`,
type: GraphQLBoolean,
},
};
if (isCreateEnabled) {
fields['createAndLink'] = {
3 changes: 3 additions & 0 deletions src/GraphQL/transformers/mutation.js
Original file line number Diff line number Diff line change
@@ -224,6 +224,9 @@ const transformers = {
objectId,
};
}
if (value.unlink) {
return { __op: 'Delete' };
}
},
};