Skip to content

Commit 370c4d6

Browse files
committed
Future proof - entries not capabilities
1 parent cb8c1c1 commit 370c4d6

6 files changed

Lines changed: 35 additions & 32 deletions

File tree

src/language/__tests__/service-test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ describe('Service Definition Parsing and Printing', () => {
1919
expect(serviceDef.kind).to.equal(Kind.SERVICE_DEFINITION);
2020

2121
if (serviceDef.kind === Kind.SERVICE_DEFINITION) {
22-
expect(serviceDef.capabilities).to.have.length(1);
23-
expect(serviceDef.capabilities?.[0].identifier.value).to.equal(
22+
expect(serviceDef.entries).to.have.length(1);
23+
expect(serviceDef.entries?.[0].identifier.value).to.equal(
2424
'example.capability',
2525
);
26-
expect(serviceDef.capabilities?.[0].value).to.equal(undefined);
26+
expect(serviceDef.entries?.[0].value).to.equal(undefined);
2727
}
2828
});
2929

@@ -36,10 +36,10 @@ describe('Service Definition Parsing and Printing', () => {
3636

3737
const serviceDef = doc.definitions[0];
3838
if (serviceDef.kind === Kind.SERVICE_DEFINITION) {
39-
expect(serviceDef.capabilities?.[0].identifier.value).to.equal(
39+
expect(serviceDef.entries?.[0].identifier.value).to.equal(
4040
'example.capability',
4141
);
42-
expect(serviceDef.capabilities?.[0].value?.value).to.equal(
42+
expect(serviceDef.entries?.[0].value?.value).to.equal(
4343
'Example value',
4444
);
4545
}
@@ -69,7 +69,7 @@ describe('Service Definition Parsing and Printing', () => {
6969

7070
const serviceDef = doc.definitions[0];
7171
if (serviceDef.kind === Kind.SERVICE_DEFINITION) {
72-
expect(serviceDef.capabilities?.[0].description?.value).to.equal(
72+
expect(serviceDef.entries?.[0].description?.value).to.equal(
7373
'Example capability description',
7474
);
7575
}
@@ -86,19 +86,19 @@ describe('Service Definition Parsing and Printing', () => {
8686

8787
const serviceDef = doc.definitions[0];
8888
if (serviceDef.kind === Kind.SERVICE_DEFINITION) {
89-
expect(serviceDef.capabilities).to.have.length(3);
90-
expect(serviceDef.capabilities?.[0].identifier.value).to.equal(
89+
expect(serviceDef.entries).to.have.length(3);
90+
expect(serviceDef.entries?.[0].identifier.value).to.equal(
9191
'example.capability',
9292
);
93-
expect(serviceDef.capabilities?.[0].value).to.equal(undefined);
94-
expect(serviceDef.capabilities?.[1].identifier.value).to.equal(
93+
expect(serviceDef.entries?.[0].value).to.equal(undefined);
94+
expect(serviceDef.entries?.[1].identifier.value).to.equal(
9595
'graphql.someFutureCapability',
9696
);
97-
expect(serviceDef.capabilities?.[1].value).to.equal(undefined);
98-
expect(serviceDef.capabilities?.[2].identifier.value).to.equal(
97+
expect(serviceDef.entries?.[1].value).to.equal(undefined);
98+
expect(serviceDef.entries?.[2].identifier.value).to.equal(
9999
'org.example.customFeature',
100100
);
101-
expect(serviceDef.capabilities?.[2].value?.value).to.equal('v2');
101+
expect(serviceDef.entries?.[2].value?.value).to.equal('v2');
102102
}
103103
});
104104

@@ -142,8 +142,8 @@ describe('Service Definition Parsing and Printing', () => {
142142
expect(serviceExt.kind).to.equal(Kind.SERVICE_EXTENSION);
143143

144144
if (serviceExt.kind === Kind.SERVICE_EXTENSION) {
145-
expect(serviceExt.capabilities).to.have.length(1);
146-
expect(serviceExt.capabilities?.[0].identifier.value).to.equal(
145+
expect(serviceExt.entries).to.have.length(1);
146+
expect(serviceExt.entries?.[0].identifier.value).to.equal(
147147
'graphql.additionalFeature',
148148
);
149149
}

src/language/ast.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ export const QueryDocumentKeys: {
341341
'locations',
342342
],
343343

344-
ServiceDefinition: ['description', 'directives', 'capabilities'],
344+
ServiceDefinition: ['description', 'directives', 'entries'],
345345
ServiceCapability: ['description', 'identifier', 'value'],
346346

347347
SchemaExtension: ['directives', 'operationTypes'],
@@ -355,7 +355,7 @@ export const QueryDocumentKeys: {
355355
EnumTypeExtension: ['name', 'directives', 'values'],
356356
InputObjectTypeExtension: ['name', 'directives', 'fields'],
357357

358-
ServiceExtension: ['directives', 'capabilities'],
358+
ServiceExtension: ['directives', 'entries'],
359359

360360
TypeCoordinate: ['name'],
361361
MemberCoordinate: ['name', 'memberName'],
@@ -1018,9 +1018,11 @@ export interface ServiceDefinitionNode {
10181018
readonly loc?: Location;
10191019
readonly description?: StringValueNode;
10201020
readonly directives?: ReadonlyArray<ConstDirectiveNode>;
1021-
readonly capabilities?: ReadonlyArray<ServiceCapabilityNode>;
1021+
readonly entries?: ReadonlyArray<ServiceEntryNode>;
10221022
}
10231023

1024+
export type ServiceEntryNode = ServiceCapabilityNode;
1025+
10241026
export interface ServiceCapabilityNode {
10251027
readonly kind: Kind.SERVICE_CAPABILITY;
10261028
readonly loc?: Location;
@@ -1158,7 +1160,7 @@ export interface ServiceExtensionNode {
11581160
readonly kind: Kind.SERVICE_EXTENSION;
11591161
readonly loc?: Location;
11601162
readonly directives?: ReadonlyArray<ConstDirectiveNode>;
1161-
readonly capabilities?: ReadonlyArray<ServiceCapabilityNode>;
1163+
readonly entries?: ReadonlyArray<ServiceEntryNode>;
11621164
}
11631165

11641166
// Schema Coordinates

src/language/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export type {
9595
InputObjectTypeDefinitionNode,
9696
DirectiveDefinitionNode,
9797
ServiceDefinitionNode,
98+
ServiceEntryNode,
9899
ServiceCapabilityNode,
99100
TypeSystemExtensionNode,
100101
SchemaExtensionNode,

src/language/parser.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,7 @@ export class Parser {
17071707
const description = this.parseDescription();
17081708
this.expectKeyword('service');
17091709
const directives = this.parseConstDirectives();
1710-
const capabilities = this.optionalMany(
1710+
const entries = this.optionalMany(
17111711
TokenKind.BRACE_L,
17121712
this.parseServiceCapability,
17131713
TokenKind.BRACE_R,
@@ -1716,7 +1716,7 @@ export class Parser {
17161716
kind: Kind.SERVICE_DEFINITION,
17171717
description,
17181718
directives,
1719-
capabilities,
1719+
entries,
17201720
});
17211721
}
17221722

@@ -1783,18 +1783,18 @@ export class Parser {
17831783
this.expectKeyword('extend');
17841784
this.expectKeyword('service');
17851785
const directives = this.parseConstDirectives();
1786-
const capabilities = this.optionalMany(
1786+
const entries = this.optionalMany(
17871787
TokenKind.BRACE_L,
17881788
this.parseServiceCapability,
17891789
TokenKind.BRACE_R,
17901790
);
1791-
if (directives.length === 0 && capabilities.length === 0) {
1791+
if (directives.length === 0 && entries.length === 0) {
17921792
throw this.unexpected();
17931793
}
17941794
return this.node<ServiceExtensionNode>(start, {
17951795
kind: Kind.SERVICE_EXTENSION,
17961796
directives,
1797-
capabilities,
1797+
entries,
17981798
});
17991799
}
18001800

src/language/printer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ const printDocASTReducer: ASTReducer<string> = {
269269
},
270270

271271
ServiceDefinition: {
272-
leave: ({ description, directives, capabilities }) =>
272+
leave: ({ description, directives, entries }) =>
273273
wrap('', description, '\n') +
274-
join(['service', join(directives, ' '), block(capabilities)], ' '),
274+
join(['service', join(directives, ' '), block(entries)], ' '),
275275
},
276276

277277
ServiceCapability: {
@@ -364,8 +364,8 @@ const printDocASTReducer: ASTReducer<string> = {
364364
},
365365

366366
ServiceExtension: {
367-
leave: ({ directives, capabilities }) =>
368-
join(['extend service', join(directives, ' '), block(capabilities)], ' '),
367+
leave: ({ directives, entries }) =>
368+
join(['extend service', join(directives, ' '), block(entries)], ' '),
369369
},
370370

371371
// Schema Coordinates

src/utilities/extendSchema.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ export function extendSchemaImpl(
337337
}
338338

339339
// Add capabilities from new service definition
340-
if (astNode?.capabilities) {
341-
for (const cap of astNode.capabilities) {
340+
if (astNode?.entries) {
341+
for (const cap of astNode.entries) {
342342
allCapabilities.push({
343343
identifier: cap.identifier.value,
344344
description: cap.description?.value,
@@ -350,8 +350,8 @@ export function extendSchemaImpl(
350350

351351
// Add capabilities from extensions
352352
for (const ext of extensionNodes) {
353-
if (ext.capabilities) {
354-
for (const cap of ext.capabilities) {
353+
if (ext.entries) {
354+
for (const cap of ext.entries) {
355355
allCapabilities.push({
356356
identifier: cap.identifier.value,
357357
description: cap.description?.value,

0 commit comments

Comments
 (0)