Skip to content

Commit 7782190

Browse files
type definitions: Use consistent order for public fields (#2090)
1 parent 0105d92 commit 7782190

File tree

3 files changed

+38
-31
lines changed

3 files changed

+38
-31
lines changed

src/type/definition.js

+31-26
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,9 @@ export class GraphQLScalarType {
558558
this.parseValue = parseValue;
559559
this.parseLiteral =
560560
config.parseLiteral || (node => parseValue(valueFromASTUntyped(node)));
561-
562561
this.astNode = config.astNode;
563562
this.extensionASTNodes = undefineIfEmpty(config.extensionASTNodes);
563+
564564
devAssert(typeof config.name === 'string', 'Must provide name.');
565565
devAssert(
566566
config.serialize == null || typeof config.serialize === 'function',
@@ -663,19 +663,20 @@ export type GraphQLScalarTypeConfig<TInternal, TExternal> = {|
663663
export class GraphQLObjectType {
664664
name: string;
665665
description: ?string;
666+
isTypeOf: ?GraphQLIsTypeOfFn<*, *>;
666667
astNode: ?ObjectTypeDefinitionNode;
667668
extensionASTNodes: ?$ReadOnlyArray<ObjectTypeExtensionNode>;
668-
isTypeOf: ?GraphQLIsTypeOfFn<*, *>;
669669

670670
_fields: Thunk<GraphQLFieldMap<*, *>>;
671671
_interfaces: Thunk<Array<GraphQLInterfaceType>>;
672672

673673
constructor(config: GraphQLObjectTypeConfig<*, *>): void {
674674
this.name = config.name;
675675
this.description = config.description;
676+
this.isTypeOf = config.isTypeOf;
676677
this.astNode = config.astNode;
677678
this.extensionASTNodes = undefineIfEmpty(config.extensionASTNodes);
678-
this.isTypeOf = config.isTypeOf;
679+
679680
this._fields = defineFieldMap.bind(undefined, config);
680681
this._interfaces = defineInterfaces.bind(undefined, config);
681682
devAssert(typeof config.name === 'string', 'Must provide name.');
@@ -709,9 +710,9 @@ export class GraphQLObjectType {
709710
return {
710711
name: this.name,
711712
description: this.description,
712-
isTypeOf: this.isTypeOf,
713713
interfaces: this.getInterfaces(),
714714
fields: fieldsToFieldsConfig(this.getFields()),
715+
isTypeOf: this.isTypeOf,
715716
astNode: this.astNode,
716717
extensionASTNodes: this.extensionASTNodes || [],
717718
};
@@ -797,12 +798,12 @@ function isPlainObj(obj) {
797798

798799
function fieldsToFieldsConfig(fields) {
799800
return mapValue(fields, field => ({
801+
description: field.description,
800802
type: field.type,
801803
args: argsToArgsConfig(field.args),
802804
resolve: field.resolve,
803805
subscribe: field.subscribe,
804806
deprecationReason: field.deprecationReason,
805-
description: field.description,
806807
astNode: field.astNode,
807808
}));
808809
}
@@ -814,20 +815,20 @@ export function argsToArgsConfig(
814815
args,
815816
arg => arg.name,
816817
arg => ({
818+
description: arg.description,
817819
type: arg.type,
818820
defaultValue: arg.defaultValue,
819-
description: arg.description,
820821
astNode: arg.astNode,
821822
}),
822823
);
823824
}
824825

825826
export type GraphQLObjectTypeConfig<TSource, TContext> = {|
826827
name: string,
828+
description?: ?string,
827829
interfaces?: Thunk<?Array<GraphQLInterfaceType>>,
828830
fields: Thunk<GraphQLFieldConfigMap<TSource, TContext>>,
829831
isTypeOf?: ?GraphQLIsTypeOfFn<TSource, TContext>,
830-
description?: ?string,
831832
astNode?: ?ObjectTypeDefinitionNode,
832833
extensionASTNodes?: ?$ReadOnlyArray<ObjectTypeExtensionNode>,
833834
|};
@@ -874,21 +875,21 @@ export type GraphQLFieldConfig<
874875
TContext,
875876
TArgs = { [argument: string]: any, ... },
876877
> = {|
878+
description?: ?string,
877879
type: GraphQLOutputType,
878880
args?: GraphQLFieldConfigArgumentMap,
879881
resolve?: GraphQLFieldResolver<TSource, TContext, TArgs>,
880882
subscribe?: GraphQLFieldResolver<TSource, TContext, TArgs>,
881883
deprecationReason?: ?string,
882-
description?: ?string,
883884
astNode?: ?FieldDefinitionNode,
884885
|};
885886

886887
export type GraphQLFieldConfigArgumentMap = ObjMap<GraphQLArgumentConfig>;
887888

888889
export type GraphQLArgumentConfig = {|
890+
description?: ?string,
889891
type: GraphQLInputType,
890892
defaultValue?: mixed,
891-
description?: ?string,
892893
astNode?: ?InputValueDefinitionNode,
893894
|};
894895

@@ -914,9 +915,9 @@ export type GraphQLField<
914915

915916
export type GraphQLArgument = {|
916917
name: string,
918+
description?: ?string,
917919
type: GraphQLInputType,
918920
defaultValue?: mixed,
919-
description?: ?string,
920921
astNode?: ?InputValueDefinitionNode,
921922
|};
922923

@@ -949,18 +950,19 @@ export type GraphQLFieldMap<TSource, TContext> = ObjMap<
949950
export class GraphQLInterfaceType {
950951
name: string;
951952
description: ?string;
953+
resolveType: ?GraphQLTypeResolver<*, *>;
952954
astNode: ?InterfaceTypeDefinitionNode;
953955
extensionASTNodes: ?$ReadOnlyArray<InterfaceTypeExtensionNode>;
954-
resolveType: ?GraphQLTypeResolver<*, *>;
955956

956957
_fields: Thunk<GraphQLFieldMap<*, *>>;
957958

958959
constructor(config: GraphQLInterfaceTypeConfig<*, *>): void {
959960
this.name = config.name;
960961
this.description = config.description;
962+
this.resolveType = config.resolveType;
961963
this.astNode = config.astNode;
962964
this.extensionASTNodes = undefineIfEmpty(config.extensionASTNodes);
963-
this.resolveType = config.resolveType;
965+
964966
this._fields = defineFieldMap.bind(undefined, config);
965967
devAssert(typeof config.name === 'string', 'Must provide name.');
966968
devAssert(
@@ -985,8 +987,8 @@ export class GraphQLInterfaceType {
985987
return {
986988
name: this.name,
987989
description: this.description,
988-
resolveType: this.resolveType,
989990
fields: fieldsToFieldsConfig(this.getFields()),
991+
resolveType: this.resolveType,
990992
astNode: this.astNode,
991993
extensionASTNodes: this.extensionASTNodes || [],
992994
};
@@ -1003,14 +1005,14 @@ defineToJSON(GraphQLInterfaceType);
10031005

10041006
export type GraphQLInterfaceTypeConfig<TSource, TContext> = {|
10051007
name: string,
1008+
description?: ?string,
10061009
fields: Thunk<GraphQLFieldConfigMap<TSource, TContext>>,
10071010
/**
10081011
* Optionally provide a custom type resolver function. If one is not provided,
10091012
* the default implementation will call `isTypeOf` on each implementing
10101013
* Object type.
10111014
*/
10121015
resolveType?: ?GraphQLTypeResolver<TSource, TContext>,
1013-
description?: ?string,
10141016
astNode?: ?InterfaceTypeDefinitionNode,
10151017
extensionASTNodes?: ?$ReadOnlyArray<InterfaceTypeExtensionNode>,
10161018
|};
@@ -1041,18 +1043,19 @@ export type GraphQLInterfaceTypeConfig<TSource, TContext> = {|
10411043
export class GraphQLUnionType {
10421044
name: string;
10431045
description: ?string;
1046+
resolveType: ?GraphQLTypeResolver<*, *>;
10441047
astNode: ?UnionTypeDefinitionNode;
10451048
extensionASTNodes: ?$ReadOnlyArray<UnionTypeExtensionNode>;
1046-
resolveType: ?GraphQLTypeResolver<*, *>;
10471049

10481050
_types: Thunk<Array<GraphQLObjectType>>;
10491051

10501052
constructor(config: GraphQLUnionTypeConfig<*, *>): void {
10511053
this.name = config.name;
10521054
this.description = config.description;
1055+
this.resolveType = config.resolveType;
10531056
this.astNode = config.astNode;
10541057
this.extensionASTNodes = undefineIfEmpty(config.extensionASTNodes);
1055-
this.resolveType = config.resolveType;
1058+
10561059
this._types = defineTypes.bind(undefined, config);
10571060
devAssert(typeof config.name === 'string', 'Must provide name.');
10581061
devAssert(
@@ -1077,8 +1080,8 @@ export class GraphQLUnionType {
10771080
return {
10781081
name: this.name,
10791082
description: this.description,
1080-
resolveType: this.resolveType,
10811083
types: this.getTypes(),
1084+
resolveType: this.resolveType,
10821085
astNode: this.astNode,
10831086
extensionASTNodes: this.extensionASTNodes || [],
10841087
};
@@ -1106,14 +1109,14 @@ function defineTypes(
11061109

11071110
export type GraphQLUnionTypeConfig<TSource, TContext> = {|
11081111
name: string,
1112+
description?: ?string,
11091113
types: Thunk<Array<GraphQLObjectType>>,
11101114
/**
11111115
* Optionally provide a custom type resolver function. If one is not provided,
11121116
* the default implementation will call `isTypeOf` on each implementing
11131117
* Object type.
11141118
*/
11151119
resolveType?: ?GraphQLTypeResolver<TSource, TContext>,
1116-
description?: ?string,
11171120
astNode?: ?UnionTypeDefinitionNode,
11181121
extensionASTNodes?: ?$ReadOnlyArray<UnionTypeExtensionNode>,
11191122
|};
@@ -1154,6 +1157,7 @@ export class GraphQLEnumType /* <T> */ {
11541157
this.description = config.description;
11551158
this.astNode = config.astNode;
11561159
this.extensionASTNodes = undefineIfEmpty(config.extensionASTNodes);
1160+
11571161
this._values = defineEnumValues(this.name, config.values);
11581162
this._valueLookup = new Map(
11591163
this._values.map(enumValue => [enumValue.value, enumValue]),
@@ -1251,38 +1255,38 @@ function defineEnumValues(
12511255
return {
12521256
name: valueName,
12531257
description: value.description,
1258+
value: 'value' in value ? value.value : valueName,
12541259
isDeprecated: Boolean(value.deprecationReason),
12551260
deprecationReason: value.deprecationReason,
12561261
astNode: value.astNode,
1257-
value: 'value' in value ? value.value : valueName,
12581262
};
12591263
});
12601264
}
12611265

12621266
export type GraphQLEnumTypeConfig /* <T> */ = {|
12631267
name: string,
1264-
values: GraphQLEnumValueConfigMap /* <T> */,
12651268
description?: ?string,
1269+
values: GraphQLEnumValueConfigMap /* <T> */,
12661270
astNode?: ?EnumTypeDefinitionNode,
12671271
extensionASTNodes?: ?$ReadOnlyArray<EnumTypeExtensionNode>,
12681272
|};
12691273

12701274
export type GraphQLEnumValueConfigMap /* <T> */ = ObjMap<GraphQLEnumValueConfig /* <T> */>;
12711275

12721276
export type GraphQLEnumValueConfig /* <T> */ = {|
1277+
description?: ?string,
12731278
value?: any /* T */,
12741279
deprecationReason?: ?string,
1275-
description?: ?string,
12761280
astNode?: ?EnumValueDefinitionNode,
12771281
|};
12781282

12791283
export type GraphQLEnumValue /* <T> */ = {|
12801284
name: string,
12811285
description: ?string,
1286+
value: any /* T */,
12821287
isDeprecated?: boolean,
12831288
deprecationReason: ?string,
12841289
astNode?: ?EnumValueDefinitionNode,
1285-
value: any /* T */,
12861290
|};
12871291

12881292
/**
@@ -1318,6 +1322,7 @@ export class GraphQLInputObjectType {
13181322
this.description = config.description;
13191323
this.astNode = config.astNode;
13201324
this.extensionASTNodes = undefineIfEmpty(config.extensionASTNodes);
1325+
13211326
this._fields = defineInputFieldMap.bind(undefined, config);
13221327
devAssert(typeof config.name === 'string', 'Must provide name.');
13231328
}
@@ -1375,36 +1380,36 @@ function defineInputFieldMap(
13751380

13761381
return {
13771382
name: fieldName,
1383+
description: fieldConfig.description,
13781384
type: fieldConfig.type,
13791385
defaultValue: fieldConfig.defaultValue,
1380-
description: fieldConfig.description,
13811386
astNode: fieldConfig.astNode,
13821387
};
13831388
});
13841389
}
13851390

13861391
export type GraphQLInputObjectTypeConfig = {|
13871392
name: string,
1388-
fields: Thunk<GraphQLInputFieldConfigMap>,
13891393
description?: ?string,
1394+
fields: Thunk<GraphQLInputFieldConfigMap>,
13901395
astNode?: ?InputObjectTypeDefinitionNode,
13911396
extensionASTNodes?: ?$ReadOnlyArray<InputObjectTypeExtensionNode>,
13921397
|};
13931398

13941399
export type GraphQLInputFieldConfig = {|
1400+
description?: ?string,
13951401
type: GraphQLInputType,
13961402
defaultValue?: mixed,
1397-
description?: ?string,
13981403
astNode?: ?InputValueDefinitionNode,
13991404
|};
14001405

14011406
export type GraphQLInputFieldConfigMap = ObjMap<GraphQLInputFieldConfig>;
14021407

14031408
export type GraphQLInputField = {|
14041409
name: string,
1410+
description?: ?string,
14051411
type: GraphQLInputType,
14061412
defaultValue?: mixed,
1407-
description?: ?string,
14081413
astNode?: ?InputValueDefinitionNode,
14091414
|};
14101415

src/type/directives.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ export class GraphQLDirective {
5858
constructor(config: GraphQLDirectiveConfig): void {
5959
this.name = config.name;
6060
this.description = config.description;
61-
6261
this.locations = config.locations;
6362
this.isRepeatable = config.isRepeatable != null && config.isRepeatable;
6463
this.astNode = config.astNode;
64+
6565
devAssert(config.name, 'Directive must be named.');
6666
devAssert(
6767
Array.isArray(config.locations),

src/type/schema.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export function assertSchema(schema: mixed): GraphQLSchema {
117117
export class GraphQLSchema {
118118
astNode: ?SchemaDefinitionNode;
119119
extensionASTNodes: ?$ReadOnlyArray<SchemaExtensionNode>;
120+
120121
_queryType: ?GraphQLObjectType;
121122
_mutationType: ?GraphQLObjectType;
122123
_subscriptionType: ?GraphQLObjectType;
@@ -156,14 +157,15 @@ export class GraphQLSchema {
156157
);
157158
}
158159

160+
this.astNode = config.astNode;
161+
this.extensionASTNodes = config.extensionASTNodes;
162+
159163
this.__allowedLegacyNames = config.allowedLegacyNames || [];
160164
this._queryType = config.query;
161165
this._mutationType = config.mutation;
162166
this._subscriptionType = config.subscription;
163167
// Provide specified directives (e.g. @include and @skip) by default.
164168
this._directives = config.directives || specifiedDirectives;
165-
this.astNode = config.astNode;
166-
this.extensionASTNodes = config.extensionASTNodes;
167169

168170
// Build type map now to detect any errors within this schema.
169171
const initialTypes: Array<?GraphQLNamedType> = [
@@ -266,11 +268,11 @@ export class GraphQLSchema {
266268
allowedLegacyNames: $ReadOnlyArray<string>,
267269
|} {
268270
return {
269-
types: objectValues(this.getTypeMap()),
270-
directives: this.getDirectives().slice(),
271271
query: this.getQueryType(),
272272
mutation: this.getMutationType(),
273273
subscription: this.getSubscriptionType(),
274+
types: objectValues(this.getTypeMap()),
275+
directives: this.getDirectives().slice(),
274276
astNode: this.astNode,
275277
extensionASTNodes: this.extensionASTNodes || [],
276278
assumeValid: this.__validationErrors !== undefined,

0 commit comments

Comments
 (0)