## Fix resolver schema leaking between `/metadata` and `/graphql` endpoints ### Summary - Patch `@nestjs/graphql` to support a `resolverSchemaScope` option that filters resolvers at both schema generation and runtime, preventing cross-endpoint leaking - Introduce `@CoreResolver()` and `@MetadataResolver()` decorators to explicitly scope each resolver to its endpoint - Move most resolvers (auth, billing, workspace, user, etc.) to the metadata schema where the frontend expects them; only workflow and timeline calendar/messaging resolvers remain on `/graphql` - Fix frontend `SSEQuerySubscribeEffect` to use the default (metadata) Apollo client instead of the core client ### Problem NestJS GraphQL's module-based resolver discovery traverses transitive imports, causing resolvers from `/metadata` modules to leak into the `/graphql` schema and vice versa. This made the schemas unpredictable and tightly coupled to module import order. ### Approach - Added `resolverSchemaScope` to `GqlModuleOptions` via a patch on `@nestjs/graphql`, filtering in both `filterResolvers()` (runtime binding) and `getAllCtors()` (schema generation) - Each resolver is explicitly decorated with `@CoreResolver()` or `@MetadataResolver()` - Organized decorator, constant, and type files under `graphql-config/` following project conventions Core GQL Schema: (see: no more fields!) <img width="827" height="894" alt="image" src="https://github.com/user-attachments/assets/668f3f0f-485e-43f0-92be-4345aeccacb6" /> Metadata GQL Schema (see no more getTimelineCalendarEventsFromCompany) <img width="827" height="894" alt="image" src="https://github.com/user-attachments/assets/443913db-e5fe-4161-b0e7-4a971cc80a71" />
92 lines
2.3 KiB
TypeScript
92 lines
2.3 KiB
TypeScript
import request from 'supertest';
|
|
|
|
const SERVER_URL = `http://localhost:${APP_PORT}`;
|
|
|
|
const client = request(SERVER_URL);
|
|
|
|
const ORIGIN = new URL(SERVER_URL);
|
|
|
|
ORIGIN.hostname =
|
|
process.env.IS_MULTIWORKSPACE_ENABLED === 'true'
|
|
? `apple.${ORIGIN.hostname}`
|
|
: ORIGIN.hostname;
|
|
|
|
const auth = {
|
|
email: 'tim@apple.dev',
|
|
password: 'tim@apple.dev',
|
|
};
|
|
|
|
describe('AuthResolve (integration)', () => {
|
|
let loginToken: string;
|
|
|
|
it('should getLoginTokenFromCredentials with email and password', () => {
|
|
const queryData = {
|
|
query: `
|
|
mutation GetLoginTokenFromCredentials {
|
|
getLoginTokenFromCredentials(email: "${auth.email}", password: "${auth.password}", origin: "${ORIGIN.toString()}") {
|
|
loginToken {
|
|
token
|
|
expiresAt
|
|
}
|
|
}
|
|
}
|
|
`,
|
|
};
|
|
|
|
return client
|
|
.post('/metadata')
|
|
.set('Origin', ORIGIN.toString())
|
|
.send(queryData)
|
|
.expect(200)
|
|
.expect((res) => {
|
|
expect(res.body.data).toBeDefined();
|
|
expect(res.body.errors).toBeUndefined();
|
|
})
|
|
.expect((res) => {
|
|
const data = res.body.data.getLoginTokenFromCredentials;
|
|
|
|
expect(data).toBeDefined();
|
|
expect(data.loginToken).toBeDefined();
|
|
|
|
loginToken = data.loginToken.token;
|
|
});
|
|
});
|
|
|
|
it('should getAuthTokensFromLoginToken with login token', () => {
|
|
const queryData = {
|
|
query: `
|
|
mutation GetAuthTokensFromLoginToken {
|
|
getAuthTokensFromLoginToken(loginToken: "${loginToken}", origin: "${ORIGIN.toString()}") {
|
|
tokens {
|
|
accessOrWorkspaceAgnosticToken {
|
|
token
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`,
|
|
};
|
|
|
|
return client
|
|
.post('/metadata')
|
|
.set('Origin', ORIGIN.toString())
|
|
.send(queryData)
|
|
.expect(200)
|
|
.expect((res) => {
|
|
expect(res.body.data).toBeDefined();
|
|
expect(res.body.errors).toBeUndefined();
|
|
})
|
|
.expect((res) => {
|
|
const data = res.body.data.getAuthTokensFromLoginToken;
|
|
|
|
expect(data).toBeDefined();
|
|
expect(data.tokens).toBeDefined();
|
|
|
|
const accessToken = data.tokens.accessOrWorkspaceAgnosticToken;
|
|
|
|
expect(accessToken).toBeDefined();
|
|
expect(accessToken.token).toBeDefined();
|
|
});
|
|
});
|
|
});
|