Skip to content

Commit 312a4bc

Browse files
authored
Switch ACL to Relay Global Id (#6495)
1 parent 1b8f057 commit 312a4bc

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

spec/ParseGraphQLServer.spec.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const { SubscriptionClient } = require('subscriptions-transport-ws');
1717
const { WebSocketLink } = require('apollo-link-ws');
1818
const ApolloClient = require('apollo-client').default;
1919
const gql = require('graphql-tag');
20+
const { toGlobalId } = require('graphql-relay');
2021
const {
2122
GraphQLObjectType,
2223
GraphQLString,
@@ -8284,6 +8285,18 @@ describe('ParseGraphQLServer', () => {
82848285

82858286
await parseGraphQLServer.parseGraphQLSchema.databaseController.schemaCache.clear();
82868287

8288+
const gqlUser = (
8289+
await apolloClient.query({
8290+
query: gql`
8291+
query getUser($id: ID!) {
8292+
user(id: $id) {
8293+
id
8294+
}
8295+
}
8296+
`,
8297+
variables: { id: user.id },
8298+
})
8299+
).data.user;
82878300
const {
82888301
data: { createSomeClass },
82898302
} = await apolloClient.mutate({
@@ -8317,7 +8330,7 @@ describe('ParseGraphQLServer', () => {
83178330
fields: {
83188331
ACL: {
83198332
users: [
8320-
{ userId: user.id, read: true, write: true },
8333+
{ userId: gqlUser.id, read: true, write: true },
83218334
{ userId: user2.id, read: true, write: false },
83228335
],
83238336
roles: [
@@ -8334,13 +8347,13 @@ describe('ParseGraphQLServer', () => {
83348347
__typename: 'ACL',
83358348
users: [
83368349
{
8337-
userId: user.id,
8350+
userId: toGlobalId('_User', user.id),
83388351
read: true,
83398352
write: true,
83408353
__typename: 'UserACL',
83418354
},
83428355
{
8343-
userId: user2.id,
8356+
userId: toGlobalId('_User', user2.id),
83448357
read: true,
83458358
write: false,
83468359
__typename: 'UserACL',

src/GraphQL/loaders/defaultGraphQLTypes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
GraphQLBoolean,
1515
GraphQLUnionType,
1616
} from 'graphql';
17+
import { toGlobalId } from 'graphql-relay';
1718
import { GraphQLUpload } from 'graphql-upload';
1819

1920
class TypeValidationError extends Error {
@@ -553,7 +554,7 @@ const ACL = new GraphQLObjectType({
553554
Object.keys(p).forEach(rule => {
554555
if (rule !== '*' && rule.indexOf('role:') !== 0) {
555556
users.push({
556-
userId: rule,
557+
userId: toGlobalId('_User', rule),
557558
read: p[rule].read ? true : false,
558559
write: p[rule].write ? true : false,
559560
});

src/GraphQL/transformers/mutation.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ const transformers = {
9999
}
100100
if (value.users) {
101101
value.users.forEach(rule => {
102+
const globalIdObject = fromGlobalId(rule.userId);
103+
if (globalIdObject.type === '_User') {
104+
rule.userId = globalIdObject.id;
105+
}
102106
parseACL[rule.userId] = {
103107
read: rule.read,
104108
write: rule.write,

0 commit comments

Comments
 (0)