-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate X-API-Token to Authorization header (#122)
- Loading branch information
1 parent
8035861
commit 25d6b01
Showing
36 changed files
with
260 additions
and
3,381 deletions.
There are no files selected for viewing
This file contains 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,6 @@ | ||
--- | ||
'@graphql-hive/cli': minor | ||
'@graphql-hive/client': minor | ||
--- | ||
|
||
Migrate to Authorization header (previously X-API-Token) |
This file contains 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 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 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 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 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,122 @@ | ||
import { TargetAccessScope, ProjectType } from '@app/gql/graphql'; | ||
import formatISO from 'date-fns/formatISO'; | ||
import subHours from 'date-fns/subHours'; | ||
import { authenticate } from '../../testkit/auth'; | ||
import { | ||
publishSchema, | ||
createOrganization, | ||
createProject, | ||
createToken, | ||
readOperationsStats, | ||
waitFor, | ||
} from '../../testkit/flow'; | ||
import { collect } from '../../testkit/usage'; | ||
|
||
test('X-API-Token header should work when calling GraphQL API and collecting usage', async () => { | ||
const { access_token: owner_access_token } = await authenticate('main'); | ||
const orgResult = await createOrganization( | ||
{ | ||
name: 'foo', | ||
}, | ||
owner_access_token | ||
); | ||
|
||
const org = orgResult.body.data!.createOrganization.ok!.createdOrganizationPayload.organization; | ||
|
||
const projectResult = await createProject( | ||
{ | ||
organization: org.cleanId, | ||
type: ProjectType.Single, | ||
name: 'foo', | ||
}, | ||
owner_access_token | ||
); | ||
|
||
const project = projectResult.body.data!.createProject.ok!.createdProject; | ||
const target = projectResult.body.data!.createProject.ok!.createdTargets[0]; | ||
|
||
const tokenResult = await createToken( | ||
{ | ||
name: 'test', | ||
organization: org.cleanId, | ||
project: project.cleanId, | ||
target: target.cleanId, | ||
organizationScopes: [], | ||
projectScopes: [], | ||
targetScopes: [TargetAccessScope.RegistryRead, TargetAccessScope.RegistryWrite], | ||
}, | ||
owner_access_token | ||
); | ||
|
||
expect(tokenResult.body.errors).not.toBeDefined(); | ||
|
||
const token = tokenResult.body.data!.createToken.ok!.secret; | ||
|
||
const result = await publishSchema( | ||
{ | ||
author: 'Kamil', | ||
commit: 'abc123', | ||
sdl: `type Query { ping: String }`, | ||
}, | ||
token, | ||
'x-api-token' | ||
); | ||
|
||
expect(result.body.errors).not.toBeDefined(); | ||
expect(result.body.data!.schemaPublish.__typename).toBe('SchemaPublishSuccess'); | ||
|
||
const collectResult = await collect({ | ||
operations: [ | ||
{ | ||
operation: 'query ping { ping }', | ||
operationName: 'ping', | ||
fields: ['Query', 'Query.ping'], | ||
execution: { | ||
ok: true, | ||
duration: 200000000, | ||
errorsTotal: 0, | ||
}, | ||
}, | ||
], | ||
token, | ||
authorizationHeader: 'x-api-token', | ||
}); | ||
|
||
expect(collectResult.status).toEqual(200); | ||
|
||
await waitFor(5_000); | ||
|
||
const from = formatISO(subHours(Date.now(), 6)); | ||
const to = formatISO(Date.now()); | ||
const operationStatsResult = await readOperationsStats( | ||
{ | ||
organization: org.cleanId, | ||
project: project.cleanId, | ||
target: target.cleanId, | ||
period: { | ||
from, | ||
to, | ||
}, | ||
}, | ||
token | ||
); | ||
|
||
expect(operationStatsResult.body.errors).not.toBeDefined(); | ||
|
||
const operationsStats = operationStatsResult.body.data!.operationsStats; | ||
|
||
expect(operationsStats.operations.nodes).toHaveLength(1); | ||
|
||
const op = operationsStats.operations.nodes[0]; | ||
|
||
expect(op.count).toEqual(1); | ||
expect(op.document).toMatch('ping'); | ||
expect(op.operationHash).toBeDefined(); | ||
expect(op.duration.p75).toEqual(200); | ||
expect(op.duration.p90).toEqual(200); | ||
expect(op.duration.p95).toEqual(200); | ||
expect(op.duration.p99).toEqual(200); | ||
expect(op.kind).toEqual('query'); | ||
expect(op.name).toMatch('ping'); | ||
expect(op.percentage).toBeGreaterThan(99); | ||
}); |
This file contains 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 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 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 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 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.