Skip to content

Commit 7117b46

Browse files
committed
change base directive name to key
when computed fields are used, the key is supplemented with additional selection sets. but base is too non-descriptive....
1 parent 01d4011 commit 7117b46

8 files changed

+43
-41
lines changed

packages/stitch/tests/typeMergingWithDirectives.test.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('merging using type merging', () => {
4646
me: User
4747
_users(keys: [_Key!]!): [User] @merge
4848
}
49-
type User @base(selectionSet: "{ id }") {
49+
type User @key(selectionSet: "{ id }") {
5050
id: ID!
5151
name: String
5252
username: String
@@ -73,7 +73,7 @@ describe('merging using type merging', () => {
7373
// 1. the key for that type will be sent to the resolvers first argument.
7474
// 2. an array of keys will sent if the resolver returns a list.
7575
//
76-
// In this example, the key is constructed by using @base and @computed selection sets.
76+
// In this example, the key is constructed by using @key and @computed selection sets.
7777
// The @computed directive for a given field instructs the gateway to only add the required
7878
// additional selections when the tagged field is included within a query. In addition,
7979
// the @computed directive will defer resolution of these fields even when queries originate
@@ -99,7 +99,7 @@ describe('merging using type merging', () => {
9999
price: Int
100100
weight: Int
101101
}
102-
type Product @base(selectionSet: "{ upc }") {
102+
type Product @key(selectionSet: "{ upc }") {
103103
upc: String!
104104
inStock: Boolean
105105
shippingEstimate: Int @computed(selectionSet: "{ price weight }")
@@ -172,9 +172,10 @@ describe('merging using type merging', () => {
172172
type Query {
173173
topProducts(first: Int = 2): [Product]
174174
_productsByUpc(upcs: [String!]!): [Product] @merge(keyField: "upc")
175-
# EQUIVALENT TO: _productsByUpc(upcs: [String!]!): [Product] @merge(argsExpr: "upcs: [[$key.upc]]")
175+
# EQUIVALENT TO:
176+
# _productsByUpc(upcs: [String!]!): [Product] @merge(argsExpr: "upcs: [[$key.upc]]")
176177
}
177-
type Product @base(selectionSet: "{ upc }") {
178+
type Product @key(selectionSet: "{ upc }") {
178179
upc: String!
179180
name: String
180181
price: Int
@@ -246,7 +247,7 @@ describe('merging using type merging', () => {
246247
input UserKey {
247248
id: ID!
248249
}
249-
type User @base(selectionSet: "{ id }") {
250+
type User @key(selectionSet: "{ id }") {
250251
id: ID!
251252
username: String
252253
numberOfReviews: Int
@@ -258,15 +259,16 @@ describe('merging using type merging', () => {
258259
input ProductInput {
259260
keys: [ProductKey!]!
260261
}
261-
type Product @base(selectionSet: "{ upc }") {
262+
type Product @key(selectionSet: "{ upc }") {
262263
upc: String!
263264
reviews: [Review]
264265
}
265266
type Query {
266267
_reviews(id: ID!): Review
267268
_users(keys: [UserKey!]!): [User] @merge
268269
_products(input: ProductInput): [Product]! @merge(keyField: "input.keys")
269-
# EQUIVALENT TO: _products(input: ProductInput): [Product]! @merge(argsExpr: "input: { keys: [[$key]] }")
270+
# EQUIVALENT TO:
271+
# _products(input: ProductInput): [Product]! @merge(argsExpr: "input: { keys: [[$key]] }")
270272
}
271273
`,
272274
resolvers: {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const defaultStitchingDirectiveOptions = {
2-
baseDirectiveName: 'base',
2+
keyDirectiveName: 'key',
33
computedDirectiveName: 'computed',
44
mergeDirectiveName: 'merge',
55
};

packages/stitching-directives/src/stitchingDirectives.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { stitchingDirectivesTransformer } from './stitchingDirectivesTransformer
1111
export function stitchingDirectives(
1212
options: StitchingDirectivesOptions = {}
1313
): {
14-
baseDirectiveTypeDefs: string;
14+
keyDirectiveTypeDefs: string;
1515
computedDirectiveTypeDefs: string;
1616
mergeDirectiveTypeDefs: string;
1717
stitchingDirectivesTypeDefs: string;
@@ -23,18 +23,18 @@ export function stitchingDirectives(
2323
...options,
2424
};
2525

26-
const { baseDirectiveName, computedDirectiveName, mergeDirectiveName } = finalOptions;
26+
const { keyDirectiveName, computedDirectiveName, mergeDirectiveName } = finalOptions;
2727

28-
const baseDirectiveTypeDefs = `directive @${baseDirectiveName}(selectionSet: String!) on OBJECT`;
28+
const keyDirectiveTypeDefs = `directive @${keyDirectiveName}(selectionSet: String!) on OBJECT`;
2929
const computedDirectiveTypeDefs = `directive @${computedDirectiveName}(selectionSet: String!) on FIELD_DEFINITION`;
3030
const mergeDirectiveTypeDefs = `directive @${mergeDirectiveName}(argsExpr: String, keyArg: String, keyField: String, key: [String!], additionalArgs: String) on FIELD_DEFINITION`;
3131

3232
return {
33-
baseDirectiveTypeDefs,
33+
keyDirectiveTypeDefs,
3434
computedDirectiveTypeDefs,
3535
mergeDirectiveTypeDefs,
3636
stitchingDirectivesTypeDefs: `
37-
${baseDirectiveTypeDefs}
37+
${keyDirectiveTypeDefs}
3838
${computedDirectiveTypeDefs}
3939
${mergeDirectiveTypeDefs}
4040
`,

packages/stitching-directives/src/stitchingDirectivesTransformer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { stitchingDirectivesValidator } from './stitchingDirectivesValidator';
3131
export function stitchingDirectivesTransformer(
3232
options: StitchingDirectivesOptions = {}
3333
): (subschemaConfig: SubschemaConfig) => SubschemaConfig {
34-
const { baseDirectiveName, computedDirectiveName, mergeDirectiveName } = {
34+
const { keyDirectiveName, computedDirectiveName, mergeDirectiveName } = {
3535
...defaultStitchingDirectiveOptions,
3636
...options,
3737
};
@@ -52,8 +52,8 @@ export function stitchingDirectivesTransformer(
5252
[MapperKind.OBJECT_TYPE]: type => {
5353
const directives = getDirectives(schema, type);
5454

55-
if (directives[baseDirectiveName]) {
56-
const directiveArgumentMap = directives[baseDirectiveName];
55+
if (directives[keyDirectiveName]) {
56+
const directiveArgumentMap = directives[keyDirectiveName];
5757
const selectionSet = parseSelectionSet(directiveArgumentMap.selectionSet);
5858
selectionSetsByType[type.name] = selectionSet;
5959
}

packages/stitching-directives/src/stitchingDirectivesValidator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const dottedNameRegEx = /^[_A-Za-z][_0-9A-Za-z]*(.[_A-Za-z][_0-9A-Za-z]*)*$/;
2222
export function stitchingDirectivesValidator(
2323
options: StitchingDirectivesOptions = {}
2424
): (schema: GraphQLSchema) => GraphQLSchema {
25-
const { baseDirectiveName, computedDirectiveName, mergeDirectiveName } = {
25+
const { keyDirectiveName, computedDirectiveName, mergeDirectiveName } = {
2626
...defaultStitchingDirectiveOptions,
2727
...options,
2828
};
@@ -34,8 +34,8 @@ export function stitchingDirectivesValidator(
3434
[MapperKind.OBJECT_TYPE]: type => {
3535
const directives = getDirectives(schema, type);
3636

37-
if (directives[baseDirectiveName]) {
38-
const directiveArgumentMap = directives[baseDirectiveName];
37+
if (directives[keyDirectiveName]) {
38+
const directiveArgumentMap = directives[keyDirectiveName];
3939
parseSelectionSet(directiveArgumentMap.selectionSet);
4040
}
4141

packages/stitching-directives/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface Expansion {
2222
export type VariablePaths = Record<string, Array<string | number>>;
2323

2424
export interface StitchingDirectivesOptions {
25-
baseDirectiveName?: string;
25+
keyDirectiveName?: string;
2626
computedDirectiveName?: string;
2727
mergeDirectiveName?: string;
2828
}

packages/stitching-directives/tests/stitchingDirectivesTransformer.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { stitchingDirectives } from '../src';
88
describe('type merging directives', () => {
99
const { stitchingDirectivesTypeDefs, stitchingDirectivesTransformer } = stitchingDirectives();
1010

11-
test('adds base selection sets', () => {
11+
test('adds type selection sets', () => {
1212
const typeDefs = `
1313
${stitchingDirectivesTypeDefs}
1414
scalar _Key
@@ -17,7 +17,7 @@ describe('type merging directives', () => {
1717
_user(key: _Key): User @merge
1818
}
1919
20-
type User @base(selectionSet: "{ id }") {
20+
type User @key(selectionSet: "{ id }") {
2121
id: ID
2222
name: String
2323
}
@@ -71,7 +71,7 @@ describe('type merging directives', () => {
7171
_user(key: _Key): User @merge
7272
}
7373
74-
type User @base(selectionSet: "{ id }") {
74+
type User @key(selectionSet: "{ id }") {
7575
id: ID
7676
name: String
7777
}
@@ -110,7 +110,7 @@ describe('type merging directives', () => {
110110
_user(key: _Key): User @merge(argsExpr: "key: $key")
111111
}
112112
113-
type User @base(selectionSet: "{ id }") {
113+
type User @key(selectionSet: "{ id }") {
114114
id: ID
115115
name: String
116116
}
@@ -149,7 +149,7 @@ describe('type merging directives', () => {
149149
_user(key: _Key): User @merge(argsExpr: "key: { id: $key.id }")
150150
}
151151
152-
type User @base(selectionSet: "{ id }") {
152+
type User @key(selectionSet: "{ id }") {
153153
id: ID
154154
name: String
155155
}
@@ -188,7 +188,7 @@ describe('type merging directives', () => {
188188
_user(key: _Key): User @merge(keyArg: "key")
189189
}
190190
191-
type User @base(selectionSet: "{ id }") {
191+
type User @key(selectionSet: "{ id }") {
192192
id: ID
193193
name: String
194194
}
@@ -231,7 +231,7 @@ describe('type merging directives', () => {
231231
_user(input: UserInput, scope: String): User @merge(keyArg: "input.key", additionalArgs: """ scope: "full" """)
232232
}
233233
234-
type User @base(selectionSet: "{ id }") {
234+
type User @key(selectionSet: "{ id }") {
235235
id: ID
236236
name: String
237237
}
@@ -273,7 +273,7 @@ describe('type merging directives', () => {
273273
_user(key: _Key, scope: String): User @merge(keyArg: "key", additionalArgs: """ scope: "full" """)
274274
}
275275
276-
type User @base(selectionSet: "{ id }") {
276+
type User @key(selectionSet: "{ id }") {
277277
id: ID
278278
name: String
279279
}
@@ -311,7 +311,7 @@ describe('type merging directives', () => {
311311
_user(id: ID): User @merge(keyField: "id")
312312
}
313313
314-
type User @base(selectionSet: "{ id }") {
314+
type User @key(selectionSet: "{ id }") {
315315
id: ID
316316
name: String
317317
}
@@ -348,7 +348,7 @@ describe('type merging directives', () => {
348348
_user(key: _Key): User @merge(key: ["id", "outer.inner.firstName:name.firstName"])
349349
}
350350
351-
type User @base(selectionSet: "{ id name { firstName } }") {
351+
type User @key(selectionSet: "{ id name { firstName } }") {
352352
id: ID
353353
email: String
354354
}
@@ -394,7 +394,7 @@ describe('type merging directives', () => {
394394
_user(key: _Key): [User] @merge
395395
}
396396
397-
type User @base(selectionSet: "{ id }") {
397+
type User @key(selectionSet: "{ id }") {
398398
id: ID
399399
name: String
400400
}
@@ -438,7 +438,7 @@ describe('type merging directives', () => {
438438
_user(key: _Key): [User] @merge(argsExpr: "key: [[$key]]")
439439
}
440440
441-
type User @base(selectionSet: "{ id }") {
441+
type User @key(selectionSet: "{ id }") {
442442
id: ID
443443
name: String
444444
}
@@ -482,7 +482,7 @@ describe('type merging directives', () => {
482482
_user(key: _Key): [User] @merge(argsExpr: "key: [[{ id: $key.id }]]")
483483
}
484484
485-
type User @base(selectionSet: "{ id }") {
485+
type User @key(selectionSet: "{ id }") {
486486
id: ID
487487
name: String
488488
}

packages/stitching-directives/tests/stitchingDirectivesValidator.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ describe('type merging directives', () => {
1414
expect(() => makeExecutableSchema({ typeDefs, schemaTransforms: [stitchingDirectivesValidator] })).not.toThrow();
1515
});
1616

17-
test('throws an error if base selectionSet invalid', () => {
17+
test('throws an error if type selectionSet invalid', () => {
1818
const typeDefs = `
1919
${stitchingDirectivesTypeDefs}
2020
type Query {
2121
_user: User
2222
}
2323
24-
type User @base(selectionSet: "** invalid **") {
24+
type User @key(selectionSet: "** invalid **") {
2525
id: ID
2626
name: String
2727
}
@@ -31,14 +31,14 @@ describe('type merging directives', () => {
3131
expect(() => makeExecutableSchema({ typeDefs, schemaTransforms: [stitchingDirectivesValidator] })).toThrow();
3232
});
3333

34-
test('does not throws an error if base selectionSet valid', () => {
34+
test('does not throws an error if type selectionSet valid', () => {
3535
const typeDefs = `
3636
${stitchingDirectivesTypeDefs}
3737
type Query {
3838
_user: User
3939
}
4040
41-
type User @base(selectionSet: "{ id }") {
41+
type User @key(selectionSet: "{ id }") {
4242
id: ID
4343
name: String
4444
}
@@ -91,7 +91,7 @@ describe('type merging directives', () => {
9191
_user(key: _Key): User @merge(argsExpr: "key: $$key")
9292
}
9393
94-
type User @base(selectionSet: "{ id }") {
94+
type User @key(selectionSet: "{ id }") {
9595
id: ID
9696
name: String
9797
}
@@ -110,7 +110,7 @@ describe('type merging directives', () => {
110110
_user(key: _Key): User @merge(argsExpr: "key: $key")
111111
}
112112
113-
type User @base(selectionSet: "{ id }") {
113+
type User @key(selectionSet: "{ id }") {
114114
id: ID
115115
name: String
116116
}
@@ -129,7 +129,7 @@ describe('type merging directives', () => {
129129
_user(key: _Key): User @merge
130130
}
131131
132-
type User @base(selectionSet: "{ id }") {
132+
type User @key(selectionSet: "{ id }") {
133133
id: ID
134134
name: String
135135
}

0 commit comments

Comments
 (0)