Skip to content

Commit 7fdfdf8

Browse files
authored
feat(api): refactor Query.target + expose via public API (#6656)
1 parent c40ea2c commit 7fdfdf8

31 files changed

+131
-103
lines changed

integration-tests/testkit/collections.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { graphql } from './gql';
22

33
export const FindCollectionQuery = graphql(`
44
query Collection($selector: TargetSelectorInput!, $id: ID!) {
5-
target(selector: $selector) {
5+
target(reference: { bySelector: $selector }) {
66
id
77
documentCollection(id: $id) {
88
id

integration-tests/testkit/flow.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ export function readTargetInfo(
631631
return execute({
632632
document: graphql(`
633633
query readTargetInfo($selector: TargetSelectorInput!) {
634-
target(selector: $selector) {
634+
target(reference: { bySelector: $selector }) {
635635
id
636636
slug
637637
}
@@ -1085,7 +1085,7 @@ export function readOperationBody(
10851085
return execute({
10861086
document: graphql(`
10871087
query readOperationBody($selector: TargetSelectorInput!, $hash: String!) {
1088-
target(selector: $selector) {
1088+
target(reference: { bySelector: $selector }) {
10891089
id
10901090
operation(hash: $hash) {
10911091
body
@@ -1195,7 +1195,7 @@ export function fetchVersions(selector: TargetSelectorInput, first: number, toke
11951195
return execute({
11961196
document: graphql(`
11971197
query schemaVersions($first: Int!, $selector: TargetSelectorInput!) {
1198-
target(selector: $selector) {
1198+
target(reference: { bySelector: $selector }) {
11991199
schemaVersions(first: $first) {
12001200
edges {
12011201
node {
@@ -1261,10 +1261,12 @@ export function compareToPreviousVersion(
12611261
$version: ID!
12621262
) {
12631263
target(
1264-
selector: {
1265-
organizationSlug: $organizationSlug
1266-
projectSlug: $projectSlug
1267-
targetSlug: $targetSlug
1264+
reference: {
1265+
bySelector: {
1266+
organizationSlug: $organizationSlug
1267+
projectSlug: $projectSlug
1268+
targetSlug: $targetSlug
1269+
}
12681270
}
12691271
) {
12701272
id

integration-tests/tests/api/app-deployments.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const GetAppDeployment = graphql(`
3535
$appDeploymentName: String!
3636
$appDeploymentVersion: String!
3737
) {
38-
target(selector: $targetSelector) {
38+
target(reference: { bySelector: $targetSelector }) {
3939
appDeployment(appName: $appDeploymentName, appVersion: $appDeploymentVersion) {
4040
id
4141
lastUsed
@@ -112,7 +112,7 @@ const GetPaginatedPersistedDocuments = graphql(`
112112
$first: Int
113113
$cursor: String
114114
) {
115-
target(selector: $targetSelector) {
115+
target(reference: { bySelector: $targetSelector }) {
116116
appDeployment(appName: $appDeploymentName, appVersion: $appDeploymentVersion) {
117117
id
118118
documents(first: $first, after: $cursor) {

integration-tests/tests/api/artifacts-cdn.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ runArtifactsCDNTests('API Mirror', { service: 'server', port: 8082, path: '/arti
433433
describe('CDN token', () => {
434434
const TargetCDNAccessTokensQuery = graphql(`
435435
query TargetCDNAccessTokens($selector: TargetSelectorInput!, $after: String, $first: Int = 2) {
436-
target(selector: $selector) {
436+
target(reference: { bySelector: $selector }) {
437437
cdnAccessTokens(first: $first, after: $after) {
438438
pageInfo {
439439
hasNextPage

integration-tests/tests/api/schema/check.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ test.concurrent('should match indentation of previous description', async ({ exp
120120

121121
const SchemaCheckQuery = graphql(/* GraphQL */ `
122122
query SchemaCheckOnTargetQuery($selector: TargetSelectorInput!, $id: ID!) {
123-
target(selector: $selector) {
123+
target(reference: { bySelector: $selector }) {
124124
schemaCheck(id: $id) {
125125
__typename
126126
id

integration-tests/tests/api/schema/contracts-check.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ const ApproveFailedSchemaCheckMutation = graphql(/* GraphQL */ `
300300

301301
const SchemaCheckQuery = graphql(/* GraphQL */ `
302302
query SchemaCheckContractsQuery($selector: TargetSelectorInput!, $id: ID!) {
303-
target(selector: $selector) {
303+
target(reference: { bySelector: $selector }) {
304304
schemaCheck(id: $id) {
305305
__typename
306306
id

integration-tests/tests/api/schema/publish.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,10 +2588,12 @@ const SchemaCompareToPreviousVersionQuery = graphql(`
25882588
$version: ID!
25892589
) {
25902590
target(
2591-
selector: {
2592-
organizationSlug: $organizationSlug
2593-
projectSlug: $projectSlug
2594-
targetSlug: $targetSlug
2591+
reference: {
2592+
bySelector: {
2593+
organizationSlug: $organizationSlug
2594+
projectSlug: $projectSlug
2595+
targetSlug: $targetSlug
2596+
}
25952597
}
25962598
) {
25972599
id

integration-tests/tests/api/target/usage.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2095,7 +2095,7 @@ test.concurrent(
20952095

20962096
const SubscriptionSchemaCheckQuery = graphql(/* GraphQL */ `
20972097
query SubscriptionSchemaCheck($selector: TargetSelectorInput!, $id: ID!) {
2098-
target(selector: $selector) {
2098+
target(reference: { bySelector: $selector }) {
20992099
schemaCheck(id: $id) {
21002100
__typename
21012101
id

packages/services/api/src/modules/shared/providers/id-translator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class IdTranslator {
107107
targetId: string;
108108
};
109109

110-
if (args.reference?.bySelector) {
110+
if (args.reference?.bySelector != null) {
111111
try {
112112
const [organizationId, projectId, targetId] = await Promise.all([
113113
this.translateOrganizationId(args.reference.bySelector),
@@ -131,7 +131,7 @@ export class IdTranslator {
131131
this.logger.debug('Failed to resolve input slug to ids (slug=%o)', args.reference);
132132
return null;
133133
}
134-
} else if (args.reference?.byId) {
134+
} else if (args.reference?.byId != null) {
135135
if (!isUUID(args.reference.byId)) {
136136
this.logger.debug('Invalid uuid provided. (targetId=%s)', args.reference.byId);
137137
return null;

packages/services/api/src/modules/target/module.graphql.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { gql } from 'graphql-modules';
22

33
export default gql`
44
extend type Query {
5-
target(selector: TargetSelectorInput!): Target
5+
target(reference: TargetReferenceInput! @tag(name: "public")): Target @tag(name: "public")
66
targets(selector: ProjectSelectorInput!): TargetConnection!
77
}
88
@@ -120,9 +120,9 @@ export default gql`
120120
}
121121
122122
input TargetSelectorInput {
123-
organizationSlug: String!
124-
projectSlug: String!
125-
targetSlug: String!
123+
organizationSlug: String! @tag(name: "public")
124+
projectSlug: String! @tag(name: "public")
125+
targetSlug: String! @tag(name: "public")
126126
}
127127
128128
"""
@@ -132,11 +132,11 @@ export default gql`
132132
"""
133133
Reference to a target using it's ID (see "Target.id" field).
134134
"""
135-
byId: ID
135+
byId: ID @tag(name: "public")
136136
"""
137137
Reference to a target using it's slug parts (see "Organization.slug", "Project.slug", "Target.slug").
138138
"""
139-
bySelector: TargetSelectorInput
139+
bySelector: TargetSelectorInput @tag(name: "public")
140140
}
141141
142142
input UpdateTargetValidationSettingsInput {
@@ -195,8 +195,8 @@ export default gql`
195195
}
196196
197197
type Target {
198-
id: ID!
199-
slug: String!
198+
id: ID! @tag(name: "public")
199+
slug: String! @tag(name: "public")
200200
cleanId: ID! @deprecated(reason: "Use the 'slug' field instead.")
201201
name: String! @deprecated(reason: "Use the 'slug' field instead.")
202202
project: Project!

0 commit comments

Comments
 (0)