Skip to content

Commit c9b713f

Browse files
committed
Replace = with as
1 parent 9771485 commit c9b713f

File tree

8 files changed

+37
-32
lines changed

8 files changed

+37
-32
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ union AnnotatedUnionTwo @onUnion = | A | B
4141

4242
scalar CustomScalar
4343

44-
scalar StringEncodedCustomScalar = String
44+
scalar StringEncodedCustomScalar as String
4545

4646
scalar AnnotatedScalar @onScalar
4747

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ union AnnotatedUnionTwo @onUnion = A | B
8787
8888
scalar CustomScalar
8989
90-
scalar StringEncodedCustomScalar = String
90+
scalar StringEncodedCustomScalar as String
9191
9292
scalar AnnotatedScalar @onScalar
9393

src/language/parser.js

+18-4
Original file line numberDiff line numberDiff line change
@@ -784,14 +784,14 @@ function parseOperationTypeDefinition(
784784
}
785785

786786
/**
787-
* ScalarTypeDefinition : scalar Name ScalarOfType? Directives?
788-
* ScalarOfType : = NamedType
787+
* ScalarTypeDefinition : scalar Name SerializeAsType? Directives?
788+
* SerializeAsType : as NamedType
789789
*/
790790
function parseScalarTypeDefinition(lexer: Lexer<*>): ScalarTypeDefinitionNode {
791791
const start = lexer.token;
792792
expectKeyword(lexer, 'scalar');
793793
const name = parseName(lexer);
794-
const type = skip(lexer, TokenKind.EQUALS) ? parseNamedType(lexer) : null;
794+
const type = skipKeyword(lexer, 'as') ? parseNamedType(lexer) : null;
795795
const directives = parseDirectives(lexer);
796796
return {
797797
kind: SCALAR_TYPE_DEFINITION,
@@ -1133,10 +1133,24 @@ function expect(lexer: Lexer<*>, kind: string): Token {
11331133
}
11341134

11351135
/**
1136-
* If the next token is a keyword with the given value, return that token after
1136+
* If the next token is a keyword with the given value, return true after
11371137
* advancing the lexer. Otherwise, do not change the parser state and return
11381138
* false.
11391139
*/
1140+
function skipKeyword(lexer: Lexer<*>, value: string): boolean {
1141+
const token = lexer.token;
1142+
const match = token.kind === TokenKind.NAME && token.value === value;
1143+
if (match) {
1144+
lexer.advance();
1145+
}
1146+
return match;
1147+
}
1148+
1149+
/**
1150+
* If the next token is a keyword with the given value, return that token after
1151+
* advancing the lexer. Otherwise, do not change the parser state and throw
1152+
* an error.
1153+
*/
11401154
function expectKeyword(lexer: Lexer<*>, value: string): Token {
11411155
const token = lexer.token;
11421156
if (token.kind === TokenKind.NAME && token.value === value) {

src/language/printer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const printDocASTReducer = {
106106
operation + ': ' + type,
107107

108108
ScalarTypeDefinition: ({ name, type, directives }) =>
109-
join([ 'scalar', name, wrap('= ', type), join(directives, ' ') ], ' '),
109+
join([ 'scalar', name, wrap('as ', type), join(directives, ' ') ], ' '),
110110

111111
ObjectTypeDefinition: ({ name, interfaces, directives, fields }) =>
112112
join([

src/type/__tests__/introspection-test.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1313,8 +1313,9 @@ describe('Introspection', () => {
13131313
'An enum describing what kind of type a given `__Type` is.',
13141314
enumValues: [
13151315
{
1316-
description: 'Indicates this type is a scalar. ' +
1317-
'`ofType` is a valid field.',
1316+
description:
1317+
'Indicates this type is a scalar. ' +
1318+
'`ofType` may represent how this scalar is serialized.',
13181319
name: 'SCALAR'
13191320
},
13201321
{

src/type/introspection.js

+3-3
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.',
@@ -382,7 +382,7 @@ export const __TypeKind = new GraphQLEnumType({
382382
SCALAR: {
383383
value: TypeKind.SCALAR,
384384
description: 'Indicates this type is a scalar. ' +
385-
'`ofType` is a valid field.'
385+
'`ofType` may represent how this scalar is serialized.'
386386
},
387387
OBJECT: {
388388
value: TypeKind.OBJECT,

src/utilities/__tests__/schemaPrinter-test.js

+8-18
Original file line numberDiff line numberDiff line change
@@ -554,25 +554,15 @@ describe('Type System Printer', () => {
554554
query: Root
555555
}
556556
557-
<<<<<<< HEAD
557+
scalar Even as Int
558+
558559
scalar Odd
559560
560561
type Root {
562+
even: Even
561563
odd: Odd
562564
}
563565
`);
564-
=======
565-
scalar Even = Int
566-
567-
scalar Odd
568-
569-
type Root {
570-
even: Even
571-
odd: Odd
572-
}
573-
`
574-
);
575-
>>>>>>> RFC: Define custom scalars in terms of built-in scalars.
576566
});
577567

578568
it('Enum', () => {
@@ -775,10 +765,10 @@ type Root {
775765
# types in GraphQL as represented by the \`__TypeKind\` enum.
776766
#
777767
# Depending on the kind of a type, certain fields describe information about that
778-
# type. Scalar types provide no information beyond a name and description, while
779-
# Enum types provide their values. Object and Interface types provide the fields
780-
# they describe. Abstract types, Union and Interface, provide the Object types
781-
# possible at runtime. List and NonNull types compose other types.
768+
# type. Scalar types provide a name, descriptionand how they serialize, while Enum
769+
# types provide their possible values. Object and Interface types provide the
770+
# fields they describe. Abstract types, Union and Interface, provide the Object
771+
# types possible at runtime. List and NonNull types compose other types.
782772
type __Type {
783773
description: String
784774
enumValues(includeDeprecated: Boolean = false): [__EnumValue!]
@@ -793,7 +783,7 @@ type Root {
793783
794784
# An enum describing what kind of type a given \`__Type\` is.
795785
enum __TypeKind {
796-
# Indicates this type is a scalar. \`ofType\` is a valid field.
786+
# Indicates this type is a scalar. \`ofType\` may represent how this scalar is serialized.
797787
SCALAR
798788
799789
# Indicates this type is an object. \`fields\` and \`interfaces\` are valid fields.

src/utilities/schemaPrinter.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ export function printType(type: GraphQLType): string {
153153
}
154154

155155
function printScalar(type: GraphQLScalarType): string {
156-
const ofType = type.ofType ? ` = ${type.ofType.name}` : '';
156+
const serializeAsType = type.ofType ? ` as ${type.ofType.name}` : '';
157157
return printDescription(type) +
158-
`scalar ${type.name}${ofType}`;
158+
`scalar ${type.name}${serializeAsType}`;
159159
}
160160

161161
function printObject(type: GraphQLObjectType): string {

0 commit comments

Comments
 (0)