import { describe, beforeEach, afterEach, it, expect } from 'vitest'; import { Express } from 'express'; import { getIntrospectionQuery } from 'graphql'; import request from 'supertest'; import { init } from '../app'; import { Config } from '../app'; import { remoteApplication1 } from '../test/remote-graphql-1'; import { remoteApplication2 } from '../test/remote-graphql-2'; describe('introspection', () => { let remote1: any; let remote2: any; let app: { app: Express, stop: () => void }; afterEach(async () => { app.stop(); remote1.server.close(); remote2.server.close(); }); it('should not be able to get the introspection', async () => { const config: Config = { reloadInterval: 5000, list: [ { name: "Movies!", url: "http://localhost:8008/graphql", prefix: "movies_" }, { name: "Books!", url: "http://localhost:8009/graphql", prefix: "books_" } ], allowedQueriesAndMutations: ['getMovies', 'getBooks'], }; remote1 = await remoteApplication1(); remote2 = await remoteApplication2(); app = await init({ config }); const result = await request(app.app) .post('/graphql') .set('x-test', 'test') .send({ query: getIntrospectionQuery(), }); const { status } = result; expect(status).toEqual(403); }); it('should be able to get the introspection if explicitly saying so in the config', async () => { const config: Config = { reloadInterval: 5000, list: [ { name: "Movies!", url: "http://localhost:8008/graphql", prefix: "movies_" }, { name: "Books!", url: "http://localhost:8009/graphql", prefix: "books_" } ], allowedQueriesAndMutations: ['getMovies', 'getBooks'], shouldExposeIntrospetion: true, }; remote1 = await remoteApplication1(); remote2 = await remoteApplication2(); app = await init({ config }); const result = await request(app.app) .post('/graphql') .set('x-test', 'test') .send({ query: getIntrospectionQuery(), }); const { status } = result; expect(status).toEqual(200); expect(result.body.data.__schema).toBeDefined(); }); });