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

Switch ACL to Relay Global Id #6495

Merged
merged 1 commit into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions spec/ParseGraphQLServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const { SubscriptionClient } = require('subscriptions-transport-ws');
const { WebSocketLink } = require('apollo-link-ws');
const ApolloClient = require('apollo-client').default;
const gql = require('graphql-tag');
const { toGlobalId } = require('graphql-relay');
const {
GraphQLObjectType,
GraphQLString,
Expand Down Expand Up @@ -8284,6 +8285,18 @@ describe('ParseGraphQLServer', () => {

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

const gqlUser = (
await apolloClient.query({
query: gql`
query getUser($id: ID!) {
user(id: $id) {
id
}
}
`,
variables: { id: user.id },
})
).data.user;
const {
data: { createSomeClass },
} = await apolloClient.mutate({
Expand Down Expand Up @@ -8317,7 +8330,7 @@ describe('ParseGraphQLServer', () => {
fields: {
ACL: {
users: [
{ userId: user.id, read: true, write: true },
{ userId: gqlUser.id, read: true, write: true },
{ userId: user2.id, read: true, write: false },
],
roles: [
Expand All @@ -8334,13 +8347,13 @@ describe('ParseGraphQLServer', () => {
__typename: 'ACL',
users: [
{
userId: user.id,
userId: toGlobalId('_User', user.id),
read: true,
write: true,
__typename: 'UserACL',
},
{
userId: user2.id,
userId: toGlobalId('_User', user2.id),
read: true,
write: false,
__typename: 'UserACL',
Expand Down
3 changes: 2 additions & 1 deletion src/GraphQL/loaders/defaultGraphQLTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
GraphQLBoolean,
GraphQLUnionType,
} from 'graphql';
import { toGlobalId } from 'graphql-relay';
import { GraphQLUpload } from 'graphql-upload';

class TypeValidationError extends Error {
Expand Down Expand Up @@ -553,7 +554,7 @@ const ACL = new GraphQLObjectType({
Object.keys(p).forEach(rule => {
if (rule !== '*' && rule.indexOf('role:') !== 0) {
users.push({
userId: rule,
userId: toGlobalId('_User', rule),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make to work with either Relay global id or Parse object id?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its the output type, we should return only the RelayId, otherwise it would be hard in a near further to get off objectId

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. My bad. You're right.

read: p[rule].read ? true : false,
write: p[rule].write ? true : false,
});
Expand Down
4 changes: 4 additions & 0 deletions src/GraphQL/transformers/mutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ const transformers = {
}
if (value.users) {
value.users.forEach(rule => {
const globalIdObject = fromGlobalId(rule.userId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like here. I think here it is working with both ids.

if (globalIdObject.type === '_User') {
rule.userId = globalIdObject.id;
}
parseACL[rule.userId] = {
read: rule.read,
write: rule.write,
Expand Down