Skip to content

Commit 3552957

Browse files
authored
feat(api): add usage fields to public api schema (#6795)
1 parent a9ecd42 commit 3552957

28 files changed

+748
-594
lines changed

.changeset/weak-cobras-rhyme.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'hive': major
3+
---
4+
5+
Add fields for querying usage datato the public api schema.
6+
- `Target.schemaCoordinateStats`
7+
- `Target.clientStats`
8+
- `Target.operationsStats`
9+
10+
**BREAKING CHANGE**: This renames and changes the types for existing types within the private GraphQL schema.

integration-tests/testkit/flow.ts

Lines changed: 74 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type {
44
AddAlertInput,
55
AnswerOrganizationTransferRequestInput,
66
AssignMemberRoleInput,
7-
ClientStatsInput,
87
CreateMemberRoleInput,
98
CreateOrganizationAccessTokenInput,
109
CreateOrganizationInput,
@@ -16,7 +15,6 @@ import type {
1615
EnableExternalSchemaCompositionInput,
1716
Experimental__UpdateTargetSchemaCompositionInput,
1817
InviteToOrganizationByEmailInput,
19-
OperationsStatsSelectorInput,
2018
OrganizationSelectorInput,
2119
OrganizationTransferRequestSelector,
2220
RateLimitInput,
@@ -32,6 +30,7 @@ import type {
3230
UpdateTargetConditionalBreakingChangeConfigurationInput,
3331
UpdateTargetSlugInput,
3432
} from './gql/graphql';
33+
import * as GraphQLSchema from './gql/graphql';
3534
import { execute } from './graphql';
3635

3736
export function waitFor(ms: number) {
@@ -1010,73 +1009,105 @@ export function updateBaseSchema(input: UpdateBaseSchemaInput, token: string) {
10101009
});
10111010
}
10121011

1013-
export function readClientStats(selector: ClientStatsInput, token: string) {
1012+
export function readClientStats(
1013+
reference: GraphQLSchema.TargetReferenceInput,
1014+
period: GraphQLSchema.DateRangeInput,
1015+
clientName: string,
1016+
token: string,
1017+
) {
10141018
return execute({
10151019
document: graphql(`
1016-
query IntegrationTests_ClientStat($selector: ClientStatsInput!) {
1017-
clientStats(selector: $selector) {
1018-
totalRequests
1019-
totalVersions
1020-
operations {
1021-
nodes {
1022-
id
1023-
name
1024-
operationHash
1020+
query IntegrationTests_ClientStat(
1021+
$reference: TargetReferenceInput!
1022+
$period: DateRangeInput!
1023+
$clientName: String!
1024+
) {
1025+
target(reference: $reference) {
1026+
clientStats(period: $period, clientName: $clientName) {
1027+
totalRequests
1028+
totalVersions
1029+
operations {
1030+
edges {
1031+
node {
1032+
id
1033+
name
1034+
operationHash
1035+
count
1036+
}
1037+
}
1038+
}
1039+
versions(limit: 25) {
1040+
version
10251041
count
10261042
}
10271043
}
1028-
versions(limit: 25) {
1029-
version
1030-
count
1031-
}
10321044
}
10331045
}
10341046
`),
10351047
token,
10361048
variables: {
1037-
selector,
1049+
reference,
1050+
period,
1051+
clientName,
10381052
},
10391053
});
10401054
}
10411055

1042-
export function readOperationsStats(input: OperationsStatsSelectorInput, token: string) {
1056+
export function readOperationsStats(
1057+
target: GraphQLSchema.TargetReferenceInput,
1058+
period: GraphQLSchema.DateRangeInput,
1059+
filter: GraphQLSchema.OperationStatsFilterInput,
1060+
token: string,
1061+
) {
10431062
return execute({
10441063
document: graphql(`
1045-
query readOperationsStats($input: OperationsStatsSelectorInput!) {
1046-
operationsStats(selector: $input) {
1047-
totalOperations
1048-
operations {
1049-
nodes {
1050-
id
1051-
operationHash
1052-
kind
1053-
name
1054-
count
1055-
percentage
1056-
duration {
1057-
p75
1058-
p90
1059-
p95
1060-
p99
1064+
query readOperationsStats(
1065+
$target: TargetReferenceInput!
1066+
$period: DateRangeInput!
1067+
$filter: OperationStatsFilterInput
1068+
) {
1069+
target(reference: $target) {
1070+
operationsStats(period: $period, filter: $filter) {
1071+
totalOperations
1072+
operations {
1073+
edges {
1074+
node {
1075+
id
1076+
operationHash
1077+
kind
1078+
name
1079+
count
1080+
percentage
1081+
duration {
1082+
p75
1083+
p90
1084+
p95
1085+
p99
1086+
}
1087+
}
10611088
}
10621089
}
1063-
}
1064-
clients {
1065-
nodes {
1066-
name
1067-
versions {
1068-
version
1069-
count
1090+
clients {
1091+
edges {
1092+
node {
1093+
name
1094+
versions {
1095+
version
1096+
count
1097+
}
1098+
count
1099+
}
10701100
}
1071-
count
10721101
}
10731102
}
10741103
}
10751104
}
10761105
`),
10771106
token,
10781107
variables: {
1079-
input,
1108+
target,
1109+
period,
1110+
filter,
10801111
},
10811112
});
10821113
}

integration-tests/testkit/seed.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -748,17 +748,20 @@ export function initSeed() {
748748
const check = async () => {
749749
const statsResult = await readOperationsStats(
750750
{
751-
organizationSlug: organization.slug,
752-
projectSlug: project.slug,
753-
targetSlug: ttarget.slug,
754-
period: {
755-
from,
756-
to,
751+
bySelector: {
752+
organizationSlug: organization.slug,
753+
projectSlug: project.slug,
754+
targetSlug: ttarget.slug,
757755
},
758756
},
757+
{
758+
from,
759+
to,
760+
},
761+
{},
759762
ownerToken,
760763
).then(r => r.expectNoGraphQLErrors());
761-
return statsResult.operationsStats.totalOperations == n;
764+
return statsResult.target?.operationsStats.totalOperations == n;
762765
};
763766

764767
return pollFor(check);
@@ -769,36 +772,31 @@ export function initSeed() {
769772
ttarget: TargetOverwrite = target,
770773
) {
771774
const statsResult = await readOperationsStats(
775+
{ byId: ttarget.id },
772776
{
773-
organizationSlug: organization.slug,
774-
projectSlug: project.slug,
775-
targetSlug: ttarget.slug,
776-
period: {
777-
from,
778-
to,
779-
},
777+
from,
778+
to,
780779
},
780+
{},
781781
ownerToken,
782782
).then(r => r.expectNoGraphQLErrors());
783783

784-
return statsResult.operationsStats;
784+
return statsResult.target?.operationsStats!;
785785
},
786786
async readClientStats(params: { clientName: string; from: string; to: string }) {
787787
const statsResult = await readClientStats(
788788
{
789-
organizationSlug: organization.slug,
790-
projectSlug: project.slug,
791-
targetSlug: target.slug,
792-
client: params.clientName,
793-
period: {
794-
from: params.from,
795-
to: params.to,
796-
},
789+
byId: target.id,
790+
},
791+
{
792+
from: params.from,
793+
to: params.to,
797794
},
795+
params.clientName,
798796
ownerToken,
799797
).then(r => r.expectNoGraphQLErrors());
800798

801-
return statsResult.clientStats;
799+
return statsResult.target?.clientStats!;
802800
},
803801
async updateBaseSchema(newBase: string, ttarget: TargetOverwrite = target) {
804802
const result = await updateBaseSchema(

integration-tests/tests/api/legacy-auth.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ test.concurrent(
4545
const from = formatISO(subHours(Date.now(), 6));
4646
const to = formatISO(Date.now());
4747
const operationsStats = await readOperationsStats(from, to);
48-
expect(operationsStats.operations.nodes).toHaveLength(1);
48+
expect(operationsStats.operations.edges).toHaveLength(1);
4949

50-
const op = operationsStats.operations.nodes[0];
50+
const op = operationsStats.operations.edges[0].node;
5151
expect(op.count).toEqual(1);
5252
await expect(readOperationBody(op.operationHash!)).resolves.toEqual('query ping{ping}');
5353
expect(op.operationHash).toBeDefined();

0 commit comments

Comments
 (0)