-
Notifications
You must be signed in to change notification settings - Fork 124
Apollo Router Integration Tests #7394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c6ebbc2
Apollo Router integration
ardatan 96604af
install protoc
ardatan 92767b8
Go
ardatan 58ca8b2
Write config file
ardatan e99f1de
Oops
ardatan b862824
Increase timeout for Apollo Router integration tests
ardatan 899c021
Reduce integration tests timeout and update command
ardatan 6a0d8fb
Update tests-integration.yaml
ardatan 160a3d9
Lets go
ardatan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
integration-tests/tests/apollo-router/apollo-router.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| import { existsSync, rmSync, writeFileSync } from 'node:fs'; | ||
| import { createServer } from 'node:http'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { join } from 'node:path'; | ||
| import { ProjectType } from 'testkit/gql/graphql'; | ||
| import { initSeed } from 'testkit/seed'; | ||
| import { getServiceHost } from 'testkit/utils'; | ||
| import { execa } from '@esm2cjs/execa'; | ||
|
|
||
| describe('Apollo Router Integration', () => { | ||
| const getBaseEndpoint = () => | ||
| getServiceHost('server', 8082).then(v => `http://${v}/artifacts/v1/`); | ||
| const getAvailablePort = () => | ||
| new Promise<number>(resolve => { | ||
| const server = createServer(); | ||
| server.listen(0, () => { | ||
| const address = server.address(); | ||
| if (address && typeof address === 'object') { | ||
| const port = address.port; | ||
| server.close(() => resolve(port)); | ||
| } | ||
| }); | ||
| }); | ||
| it('fetches the supergraph and sends usage reports', async () => { | ||
| const routerConfigPath = join(tmpdir(), `apollo-router-config-${Date.now()}.yaml`); | ||
| const endpointBaseUrl = await getBaseEndpoint(); | ||
| const { createOrg } = await initSeed().createOwner(); | ||
| const { createProject } = await createOrg(); | ||
| const { createTargetAccessToken, createCdnAccess, target, waitForOperationsCollected } = | ||
| await createProject(ProjectType.Federation); | ||
| const writeToken = await createTargetAccessToken({}); | ||
|
|
||
| // Publish Schema | ||
| const publishSchemaResult = await writeToken | ||
| .publishSchema({ | ||
| author: 'Arda', | ||
| commit: 'abc123', | ||
| sdl: /* GraphQL */ ` | ||
| type Query { | ||
| me: User | ||
| } | ||
| type User { | ||
| id: ID! | ||
| name: String! | ||
| } | ||
| `, | ||
| service: 'users', | ||
| url: 'https://federation-demo.theguild.workers.dev/users', | ||
| }) | ||
| .then(r => r.expectNoGraphQLErrors()); | ||
|
|
||
| expect(publishSchemaResult.schemaPublish.__typename).toBe('SchemaPublishSuccess'); | ||
| const cdnAccessResult = await createCdnAccess(); | ||
|
|
||
| const usageAddress = await getServiceHost('usage', 8081); | ||
|
|
||
| const routerBinPath = join(__dirname, '../../../target/debug/router'); | ||
| if (!existsSync(routerBinPath)) { | ||
| throw new Error( | ||
| `Apollo Router binary not found at path: ${routerBinPath}, make sure to build it first with 'cargo build'`, | ||
| ); | ||
| } | ||
| const routerPort = await getAvailablePort(); | ||
| const routerConfigContent = ` | ||
| supergraph: | ||
| listen: 0.0.0.0:${routerPort} | ||
| plugins: | ||
| hive.usage: {} | ||
| `.trim(); | ||
| writeFileSync(routerConfigPath, routerConfigContent, 'utf-8'); | ||
| const routerProc = execa(routerBinPath, ['--dev', '--config', routerConfigPath], { | ||
| all: true, | ||
| env: { | ||
| HIVE_CDN_ENDPOINT: endpointBaseUrl + target.id, | ||
| HIVE_CDN_KEY: cdnAccessResult.secretAccessToken, | ||
| HIVE_ENDPOINT: `http://${usageAddress}`, | ||
| HIVE_TOKEN: writeToken.secret, | ||
| HIVE_TARGET_ID: target.id, | ||
| }, | ||
| }); | ||
| await new Promise((resolve, reject) => { | ||
| routerProc.catch(err => { | ||
| if (!err.isCanceled) { | ||
| reject(err); | ||
| } | ||
| }); | ||
| const routerProcOut = routerProc.all; | ||
| if (!routerProcOut) { | ||
| return reject(new Error('No stdout from Apollo Router process')); | ||
| } | ||
| let log = ''; | ||
| routerProcOut.on('data', data => { | ||
| log += data.toString(); | ||
| if (log.includes('GraphQL endpoint exposed at')) { | ||
| resolve(true); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| try { | ||
| const url = `http://localhost:${routerPort}/`; | ||
| const response = await fetch(url, { | ||
| method: 'POST', | ||
| headers: { | ||
| accept: 'application/json', | ||
| 'content-type': 'application/json', | ||
| }, | ||
| body: JSON.stringify({ | ||
| query: ` | ||
| query TestQuery { | ||
| me { | ||
| id | ||
| name | ||
| } | ||
| } | ||
| `, | ||
| }), | ||
| }); | ||
|
|
||
| expect(response.status).toBe(200); | ||
| const result = await response.json(); | ||
| expect(result).toEqual({ | ||
| data: { | ||
| me: { | ||
| id: '1', | ||
| name: 'Ada Lovelace', | ||
| }, | ||
| }, | ||
| }); | ||
| await waitForOperationsCollected(1); | ||
| } finally { | ||
| routerProc.cancel(); | ||
| rmSync(routerConfigPath); | ||
| } | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.