Skip to content

Commit f4047b7

Browse files
committed
Replace = with as
1 parent c36386c commit f4047b7

File tree

8 files changed

+41
-32
lines changed

8 files changed

+41
-32
lines changed

src/language/__tests__/schema-kitchen-sink.graphql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ extend union Feed @onUnion
6565

6666
scalar CustomScalar
6767

68-
scalar StringEncodedCustomScalar = String
69-
7068
scalar AnnotatedScalar @onScalar
7169

70+
scalar StringEncodedCustomScalar as String
71+
7272
extend scalar CustomScalar @onScalar
7373

7474
enum Site {

src/language/__tests__/schema-printer-test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ describe('Printer', () => {
111111
112112
scalar AnnotatedScalar @onScalar
113113
114-
scalar StringEncodedCustomScalar = String
115-
116-
scalar AnnotatedScalar @onScalar
114+
scalar StringEncodedCustomScalar as String
117115
118116
extend scalar CustomScalar @onScalar
119117

src/language/parser.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -893,14 +893,17 @@ function parseOperationTypeDefinition(
893893
* ScalarTypeDefinition :
894894
* - Description? scalar Name ScalarOfType? Directives[Const]?
895895
*
896-
* ScalarOfType : = NamedType
896+
* ScalarOfType : as NamedType
897897
*/
898898
function parseScalarTypeDefinition(lexer: Lexer<*>): ScalarTypeDefinitionNode {
899899
const start = lexer.token;
900900
const description = parseDescription(lexer);
901901
expectKeyword(lexer, 'scalar');
902902
const name = parseName(lexer);
903-
const type = skip(lexer, TokenKind.EQUALS) ? parseNamedType(lexer) : null;
903+
let type;
904+
if (skipKeyword(lexer, 'as')) {
905+
type = parseNamedType(lexer);
906+
}
904907
const directives = parseDirectives(lexer, true);
905908
return {
906909
kind: SCALAR_TYPE_DEFINITION,
@@ -1508,10 +1511,24 @@ function expect(lexer: Lexer<*>, kind: string): Token {
15081511
}
15091512

15101513
/**
1511-
* If the next token is a keyword with the given value, return that token after
1514+
* If the next token is a keyword with the given value, return true after
15121515
* advancing the lexer. Otherwise, do not change the parser state and return
15131516
* false.
15141517
*/
1518+
function skipKeyword(lexer: Lexer<*>, value: string): boolean {
1519+
const token = lexer.token;
1520+
const match = token.kind === TokenKind.NAME && token.value === value;
1521+
if (match) {
1522+
lexer.advance();
1523+
}
1524+
return match;
1525+
}
1526+
1527+
/**
1528+
* If the next token is a keyword with the given value, return that token after
1529+
* advancing the lexer. Otherwise, do not change the parser state and throw
1530+
* an error.
1531+
*/
15151532
function expectKeyword(lexer: Lexer<*>, value: string): Token {
15161533
const token = lexer.token;
15171534
if (token.kind === TokenKind.NAME && token.value === value) {

src/language/printer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const printDocASTReducer = {
112112

113113
ScalarTypeDefinition: ({ description, name, directives }) =>
114114
join(
115-
[description, join(['scalar', name, wrap(' = ', type), join(directives, ' ')], ' ')],
115+
[description, join(['scalar', name, wrap(' as ', type), join(directives, ' ')], ' ')],
116116
'\n',
117117
),
118118

src/type/__tests__/introspection-test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,9 @@ describe('Introspection', () => {
13071307
'An enum describing what kind of type a given `__Type` is.',
13081308
enumValues: [
13091309
{
1310-
description: 'Indicates this type is a scalar. `ofType` is a valid field.',
1310+
description:
1311+
'Indicates this type is a scalar. ' +
1312+
'`ofType` may represent how this scalar is serialized.',
13111313
name: 'SCALAR'
13121314
},
13131315
{

src/type/introspection.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ export const __Type = new GraphQLObjectType({
207207
'The fundamental unit of any GraphQL Schema is the type. There are ' +
208208
'many kinds of types in GraphQL as represented by the `__TypeKind` enum.' +
209209
'\n\nDepending on the kind of a type, certain fields describe ' +
210-
'information about that type. Scalar types provide no information ' +
211-
'beyond a name and description, while Enum types provide their values. ' +
210+
'information about that type. Scalar types provide a name, description' +
211+
'and how they serialize, while Enum types provide their possible values. ' +
212212
'Object and Interface types provide the fields they describe. Abstract ' +
213213
'types, Union and Interface, provide the Object types possible ' +
214214
'at runtime. List and NonNull types compose other types.',
@@ -381,7 +381,9 @@ export const __TypeKind = new GraphQLEnumType({
381381
values: {
382382
SCALAR: {
383383
value: TypeKind.SCALAR,
384-
description: 'Indicates this type is a scalar. `ofType` is a valid field.',
384+
description:
385+
'Indicates this type is a scalar. ' +
386+
'`ofType` may represent how this scalar is serialized.',
385387
},
386388
OBJECT: {
387389
value: TypeKind.OBJECT,

src/utilities/__tests__/schemaPrinter-test.js

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -529,25 +529,15 @@ describe('Type System Printer', () => {
529529
query: Root
530530
}
531531
532-
<<<<<<< HEAD
532+
scalar Even as Int
533+
533534
scalar Odd
534535
535536
type Root {
537+
even: Even
536538
odd: Odd
537539
}
538540
`);
539-
=======
540-
scalar Even = Int
541-
542-
scalar Odd
543-
544-
type Root {
545-
even: Even
546-
odd: Odd
547-
}
548-
`
549-
);
550-
>>>>>>> RFC: Define custom scalars in terms of built-in scalars.
551541
});
552542

553543
it('Enum', () => {
@@ -1023,10 +1013,10 @@ type Root {
10231013
# types in GraphQL as represented by the \`__TypeKind\` enum.
10241014
#
10251015
# Depending on the kind of a type, certain fields describe information about that
1026-
# type. Scalar types provide no information beyond a name and description, while
1027-
# Enum types provide their values. Object and Interface types provide the fields
1028-
# they describe. Abstract types, Union and Interface, provide the Object types
1029-
# possible at runtime. List and NonNull types compose other types.
1016+
# type. Scalar types provide a name, descriptionand how they serialize, while Enum
1017+
# types provide their possible values. Object and Interface types provide the
1018+
# fields they describe. Abstract types, Union and Interface, provide the Object
1019+
# types possible at runtime. List and NonNull types compose other types.
10301020
type __Type {
10311021
kind: __TypeKind!
10321022
name: String
@@ -1041,7 +1031,7 @@ type Root {
10411031
10421032
# An enum describing what kind of type a given \`__Type\` is.
10431033
enum __TypeKind {
1044-
# Indicates this type is a scalar. \`ofType\` is a valid field.
1034+
# Indicates this type is a scalar. \`ofType\` may represent how this scalar is serialized.
10451035
SCALAR
10461036
10471037
# Indicates this type is an object. \`fields\` and \`interfaces\` are valid fields.

src/utilities/schemaPrinter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export function printType(type: GraphQLNamedType, options?: Options): string {
170170
}
171171

172172
function printScalar(type: GraphQLScalarType, options): string {
173-
const ofType = type.ofType ? ` = ${type.ofType.name}` : '';
173+
const ofType = type.ofType ? ` as ${type.ofType.name}` : '';
174174
return printDescription(options, type) + `scalar ${type.name}${ofType}`;
175175
}
176176

0 commit comments

Comments
 (0)