Skip to content
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

feat: allow removing a pointer from a field #7518

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ ___
- Added runtime deprecation warnings (Manuel Trezza) [#7451](https://github.com/parse-community/parse-server/pull/7451)
- Add ability to pass context of an object via a header, X-Parse-Cloud-Context, for Cloud Code triggers. The header addition allows client SDK's to add context without injecting _context in the body of JSON objects (Corey Baker) [#7437](https://github.com/parse-community/parse-server/pull/7437)
- Add CI check to add changelog entry (Manuel Trezza) [#7512](https://github.com/parse-community/parse-server/pull/7512)
- Allow a pointer to be removed using GraphQL (Chris Bland) [#7517](https://github.com/parse-community/parse-server/issues/7517)
mtrezza marked this conversation as resolved.
Show resolved Hide resolved

## 4.10.2
[Full Changelog](https://github.com/parse-community/parse-server/compare/4.10.1...4.10.2)
Expand Down
67 changes: 67 additions & 0 deletions spec/ParseGraphQLServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8323,6 +8323,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();
mtrezza marked this conversation as resolved.
Show resolved Hide resolved

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');
Expand Down
4 changes: 4 additions & 0 deletions src/GraphQL/loaders/parseClassTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = {
Expand Down
3 changes: 3 additions & 0 deletions src/GraphQL/transformers/mutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ const transformers = {
objectId,
};
}
if (value.unlink) {
return { __op: 'Delete' };
}
},
};

Expand Down