feat: Add request context middleware for config and dependency injection in hooks (#8480)

This commit is contained in:
Antoine Cormouls
2025-10-14 20:16:31 +02:00
committed by GitHub
parent e704de83e6
commit 64f104e5c5
12 changed files with 219 additions and 29 deletions

View File

@@ -607,6 +607,41 @@ describe('ParseGraphQLServer', () => {
]);
};
describe('Context', () => {
it('should support dependency injection on graphql api', async () => {
const requestContextMiddleware = (req, res, next) => {
req.config.aCustomController = 'aCustomController';
next();
};
let called;
const parseServer = await reconfigureServer({ requestContextMiddleware });
await createGQLFromParseServer(parseServer);
Parse.Cloud.beforeSave('_User', request => {
expect(request.config.aCustomController).toEqual('aCustomController');
called = true;
});
await apolloClient.query({
query: gql`
mutation {
createUser(input: { fields: { username: "test", password: "test" } }) {
user {
objectId
}
}
}
`,
context: {
headers: {
'X-Parse-Master-Key': 'test',
},
}
})
expect(called).toBe(true);
})
})
describe('Introspection', () => {
it('should have public introspection disabled by default without master key', async () => {