feat: Add GraphQL query cloudConfig to retrieve and mutation updateCloudConfig to update Cloud Config (#9947)

This commit is contained in:
Lucas Coratger
2025-12-03 19:55:30 +01:00
committed by GitHub
parent 6d670131a0
commit 3ca85cd4a6
6 changed files with 422 additions and 1 deletions

View File

@@ -7080,6 +7080,284 @@ describe('ParseGraphQLServer', () => {
});
});
describe("Config Queries", () => {
beforeEach(async () => {
// Setup initial config data
await Parse.Config.save(
{ publicParam: 'publicValue', privateParam: 'privateValue' },
{ privateParam: true },
{ useMasterKey: true }
);
});
it("should return the config value for a specific parameter", async () => {
const query = gql`
query cloudConfig($paramName: String!) {
cloudConfig(paramName: $paramName) {
value
isMasterKeyOnly
}
}
`;
const result = await apolloClient.query({
query,
variables: { paramName: 'publicParam' },
context: {
headers: {
'X-Parse-Master-Key': 'test',
},
},
});
expect(result.errors).toBeUndefined();
expect(result.data.cloudConfig.value).toEqual('publicValue');
expect(result.data.cloudConfig.isMasterKeyOnly).toEqual(false);
});
it("should return null for non-existent parameter", async () => {
const query = gql`
query cloudConfig($paramName: String!) {
cloudConfig(paramName: $paramName) {
value
isMasterKeyOnly
}
}
`;
const result = await apolloClient.query({
query,
variables: { paramName: 'nonExistentParam' },
context: {
headers: {
'X-Parse-Master-Key': 'test',
},
},
});
expect(result.errors).toBeUndefined();
expect(result.data.cloudConfig.value).toBeNull();
expect(result.data.cloudConfig.isMasterKeyOnly).toBeNull();
});
});
describe("Config Mutations", () => {
it("should update a config value using mutation and retrieve it with query", async () => {
const mutation = gql`
mutation updateCloudConfig($input: UpdateCloudConfigInput!) {
updateCloudConfig(input: $input) {
clientMutationId
cloudConfig {
value
isMasterKeyOnly
}
}
}
`;
const query = gql`
query cloudConfig($paramName: String!) {
cloudConfig(paramName: $paramName) {
value
isMasterKeyOnly
}
}
`;
const mutationResult = await apolloClient.mutate({
mutation,
variables: {
input: {
clientMutationId: 'test-mutation-id',
paramName: 'testParam',
value: 'testValue',
isMasterKeyOnly: false,
},
},
context: {
headers: {
'X-Parse-Master-Key': 'test',
},
},
});
expect(mutationResult.errors).toBeUndefined();
expect(mutationResult.data.updateCloudConfig.cloudConfig.value).toEqual('testValue');
expect(mutationResult.data.updateCloudConfig.cloudConfig.isMasterKeyOnly).toEqual(false);
const queryResult = await apolloClient.query({
query,
variables: { paramName: 'testParam' },
context: {
headers: {
'X-Parse-Master-Key': 'test',
},
},
});
expect(queryResult.errors).toBeUndefined();
expect(queryResult.data.cloudConfig.value).toEqual('testValue');
expect(queryResult.data.cloudConfig.isMasterKeyOnly).toEqual(false);
});
it("should update a config value with isMasterKeyOnly set to true", async () => {
const mutation = gql`
mutation updateCloudConfig($input: UpdateCloudConfigInput!) {
updateCloudConfig(input: $input) {
clientMutationId
cloudConfig {
value
isMasterKeyOnly
}
}
}
`;
const query = gql`
query cloudConfig($paramName: String!) {
cloudConfig(paramName: $paramName) {
value
isMasterKeyOnly
}
}
`;
const mutationResult = await apolloClient.mutate({
mutation,
variables: {
input: {
clientMutationId: 'test-mutation-id-2',
paramName: 'privateTestParam',
value: 'privateValue',
isMasterKeyOnly: true,
},
},
context: {
headers: {
'X-Parse-Master-Key': 'test',
},
},
});
expect(mutationResult.errors).toBeUndefined();
expect(mutationResult.data.updateCloudConfig.cloudConfig.value).toEqual('privateValue');
expect(mutationResult.data.updateCloudConfig.cloudConfig.isMasterKeyOnly).toEqual(true);
const queryResult = await apolloClient.query({
query,
variables: { paramName: 'privateTestParam' },
context: {
headers: {
'X-Parse-Master-Key': 'test',
},
},
});
expect(queryResult.errors).toBeUndefined();
expect(queryResult.data.cloudConfig.value).toEqual('privateValue');
expect(queryResult.data.cloudConfig.isMasterKeyOnly).toEqual(true);
});
it("should update an existing config value", async () => {
await Parse.Config.save(
{ existingParam: 'initialValue' },
{},
{ useMasterKey: true }
);
const mutation = gql`
mutation updateCloudConfig($input: UpdateCloudConfigInput!) {
updateCloudConfig(input: $input) {
clientMutationId
cloudConfig {
value
isMasterKeyOnly
}
}
}
`;
const query = gql`
query cloudConfig($paramName: String!) {
cloudConfig(paramName: $paramName) {
value
isMasterKeyOnly
}
}
`;
const mutationResult = await apolloClient.mutate({
mutation,
variables: {
input: {
clientMutationId: 'test-mutation-id-3',
paramName: 'existingParam',
value: 'updatedValue',
isMasterKeyOnly: false,
},
},
context: {
headers: {
'X-Parse-Master-Key': 'test',
},
},
});
expect(mutationResult.errors).toBeUndefined();
expect(mutationResult.data.updateCloudConfig.cloudConfig.value).toEqual('updatedValue');
const queryResult = await apolloClient.query({
query,
variables: { paramName: 'existingParam' },
context: {
headers: {
'X-Parse-Master-Key': 'test',
},
},
});
expect(queryResult.errors).toBeUndefined();
expect(queryResult.data.cloudConfig.value).toEqual('updatedValue');
});
it("should require master key to update config", async () => {
const mutation = gql`
mutation updateCloudConfig($input: UpdateCloudConfigInput!) {
updateCloudConfig(input: $input) {
clientMutationId
cloudConfig {
value
isMasterKeyOnly
}
}
}
`;
try {
await apolloClient.mutate({
mutation,
variables: {
input: {
clientMutationId: 'test-mutation-id-4',
paramName: 'testParam',
value: 'testValue',
isMasterKeyOnly: false,
},
},
context: {
headers: {
'X-Parse-Application-Id': 'test',
},
},
});
fail('Should have thrown an error');
} catch (error) {
expect(error.graphQLErrors).toBeDefined();
expect(error.graphQLErrors[0].message).toContain('Permission denied');
}
});
})
describe('Users Queries', () => {
it('should return current logged user', async () => {
const userName = 'user1',