Skip to content

Commit 03e95bd

Browse files
committed
Allow IEnumResolver values to be number type
1 parent 4f489d3 commit 03e95bd

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Added GraphQL Subscriptions support for schema stitching and `makeRemoteExecutableSchema` [PR #563](https://github.com/apollographql/graphql-tools/pull/563)
66
* Make `apollo-link` a direct dependency [PR #561](https://github.com/apollographql/graphql-tools/pull/561)
77
* Update tests to use `graphql-js@0.12` docstring format [PR #559](https://github.com/apollographql/graphql-tools/pull/559)
8+
* IEnumResolver value can be a `number` type
89

910
### v2.15.0
1011

src/Interfaces.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export type ITypeDefinitions = ITypedef | ITypedef[];
4949
export type IResolverObject = {
5050
[key: string]: IFieldResolver<any, any> | IResolverOptions;
5151
};
52-
export type IEnumResolver = { [key: string]: string };
52+
export type IEnumResolver = { [key: string]: string | number };
5353
export interface IResolvers {
5454
[key: string]:
5555
| (() => any)

src/test/testMergeSchemas.ts

+33
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,20 @@ let enumTest = `
6868
RED
6969
}
7070
71+
"""
72+
A type that uses an Enum with a numeric constant.
73+
"""
74+
enum NumericEnum {
75+
TEST
76+
}
77+
7178
schema {
7279
query: Query
7380
}
7481
7582
type Query {
7683
color: Color
84+
numericEnum: NumericEnum
7785
}
7886
`;
7987

@@ -157,12 +165,18 @@ if (process.env.GRAPHQL_VERSION === '^0.11') {
157165
RED
158166
}
159167
168+
# A type that uses an Enum with a numeric constant.
169+
enum NumericEnum {
170+
TEST
171+
}
172+
160173
schema {
161174
query: Query
162175
}
163176
164177
type Query {
165178
color: Color
179+
numericEnum: NumericEnum
166180
}
167181
`;
168182

@@ -232,6 +246,9 @@ testCombinations.forEach(async combination => {
232246
parseValue: value => value,
233247
parseLiteral: () => null,
234248
}),
249+
NumericEnum: {
250+
TEST: 1
251+
},
235252
Color: {
236253
RED: '#EA3232',
237254
},
@@ -287,6 +304,9 @@ testCombinations.forEach(async combination => {
287304
color() {
288305
return '#EA3232';
289306
},
307+
numericEnum() {
308+
return 1;
309+
},
290310
delegateInterfaceTest(parent, args, context, info) {
291311
return info.mergeInfo.delegate(
292312
'query',
@@ -449,10 +469,16 @@ testCombinations.forEach(async combination => {
449469
Color: {
450470
RED: '#EA3232',
451471
},
472+
NumericEnum: {
473+
TEST: 1
474+
},
452475
Query: {
453476
color() {
454477
return '#EA3232';
455478
},
479+
numericEnum() {
480+
return 1;
481+
},
456482
},
457483
},
458484
});
@@ -461,6 +487,7 @@ testCombinations.forEach(async combination => {
461487
`
462488
query {
463489
color
490+
numericEnum
464491
}
465492
`,
466493
);
@@ -470,13 +497,15 @@ testCombinations.forEach(async combination => {
470497
`
471498
query {
472499
color
500+
numericEnum
473501
}
474502
`,
475503
);
476504

477505
expect(enumResult).to.deep.equal({
478506
data: {
479507
color: 'RED',
508+
numericEnum: 'TEST'
480509
},
481510
});
482511
expect(mergedResult).to.deep.equal(enumResult);
@@ -1556,6 +1585,10 @@ bookingById(id: $b1) {
15561585
'A type that uses an Enum.',
15571586
);
15581587

1588+
expect(mergedSchema.getType('NumericEnum').description).to.equal(
1589+
'A type that uses an Enum with a numeric constant.',
1590+
);
1591+
15591592
expect(mergedSchema.getType('LinkType').description).to.equal(
15601593
'A new type linking the Property type.',
15611594
);

0 commit comments

Comments
 (0)