import { describe, beforeEach, afterEach, it, expect } from 'vitest'; import { Express } from 'express'; import path from 'path'; 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('stich', () => { let remote1: any; let remote2: any; let app: { app: Express, stop: () => void }; beforeEach(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 }); }); afterEach(async () => { app.stop(); remote1.server.close(); remote2.server.close(); }); it('should enable access multiple remote services schemas', async () => { const result = await request(app.app) .post('/graphql') .set('x-test', 'test') .set('foo', 'bar') .send({ query: ` query { getMovies { movies { title } } getBooks { books { title } } } `, }); const { body, status } = result; expect(remote1.getHeaders()['x-test']).toBe('test'); expect(remote1.getHeaders()['foo']).toBe('bar'); expect(status).toEqual(200); expect(body.data.getMovies.movies).toMatchObject([ {title: 'The Shawshank Redemption'}, {title: 'The Godfather'}, {title: 'The Godfather: Part II'}, {title: 'The Dark Knight'}, ]); expect(body.data.getBooks.books).toMatchObject([ {title: 'The Awakening'}, {title: 'City of Glass'}, {title: 'The Great Gatsby'}, ]); }); });