Skip to content

Commit f93bb65

Browse files
Mark 'config' as readonly argument to contructors (#2312)
1 parent 3986def commit f93bb65

File tree

6 files changed

+24
-20
lines changed

6 files changed

+24
-20
lines changed

src/type/definition.d.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ export class GraphQLScalarType {
292292
astNode: Maybe<ScalarTypeDefinitionNode>;
293293
extensionASTNodes: Maybe<ReadonlyArray<ScalarTypeExtensionNode>>;
294294

295-
constructor(config: GraphQLScalarTypeConfig<any, any>);
295+
constructor(config: Readonly<GraphQLScalarTypeConfig<any, any>>);
296296

297297
toConfig(): GraphQLScalarTypeConfig<any, any> & {
298298
serialize: GraphQLScalarSerializer<any>;
@@ -381,7 +381,9 @@ export class GraphQLObjectType<
381381
astNode: Maybe<ObjectTypeDefinitionNode>;
382382
extensionASTNodes: Maybe<ReadonlyArray<ObjectTypeExtensionNode>>;
383383

384-
constructor(config: GraphQLObjectTypeConfig<TSource, TContext, TArgs>);
384+
constructor(
385+
config: Readonly<GraphQLObjectTypeConfig<TSource, TContext, TArgs>>,
386+
);
385387
getFields(): GraphQLFieldMap<any, TContext, TArgs>;
386388
getInterfaces(): GraphQLInterfaceType[];
387389

@@ -560,7 +562,7 @@ export class GraphQLInterfaceType {
560562
astNode?: Maybe<InterfaceTypeDefinitionNode>;
561563
extensionASTNodes: Maybe<ReadonlyArray<InterfaceTypeExtensionNode>>;
562564

563-
constructor(config: GraphQLInterfaceTypeConfig<any, any>);
565+
constructor(config: Readonly<GraphQLInterfaceTypeConfig<any, any>>);
564566
getFields(): GraphQLFieldMap<any, any>;
565567
getInterfaces(): GraphQLInterfaceType[];
566568

@@ -628,7 +630,7 @@ export class GraphQLUnionType {
628630
astNode: Maybe<UnionTypeDefinitionNode>;
629631
extensionASTNodes: Maybe<ReadonlyArray<UnionTypeExtensionNode>>;
630632

631-
constructor(config: GraphQLUnionTypeConfig<any, any>);
633+
constructor(config: Readonly<GraphQLUnionTypeConfig<any, any>>);
632634
getTypes(): GraphQLObjectType[];
633635

634636
toConfig(): GraphQLUnionTypeConfig<any, any> & {
@@ -685,7 +687,7 @@ export class GraphQLEnumType {
685687
astNode: Maybe<EnumTypeDefinitionNode>;
686688
extensionASTNodes: Maybe<ReadonlyArray<EnumTypeExtensionNode>>;
687689

688-
constructor(config: GraphQLEnumTypeConfig);
690+
constructor(config: Readonly<GraphQLEnumTypeConfig>);
689691
getValues(): GraphQLEnumValue[];
690692
getValue(name: string): Maybe<GraphQLEnumValue>;
691693
serialize(value: any): Maybe<string>;
@@ -763,7 +765,7 @@ export class GraphQLInputObjectType {
763765
astNode: Maybe<InputObjectTypeDefinitionNode>;
764766
extensionASTNodes: Maybe<ReadonlyArray<InputObjectTypeExtensionNode>>;
765767

766-
constructor(config: GraphQLInputObjectTypeConfig);
768+
constructor(config: Readonly<GraphQLInputObjectTypeConfig>);
767769
getFields(): GraphQLInputFieldMap;
768770

769771
toConfig(): GraphQLInputObjectTypeConfig & {

src/type/definition.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ export class GraphQLScalarType {
553553
astNode: ?ScalarTypeDefinitionNode;
554554
extensionASTNodes: ?$ReadOnlyArray<ScalarTypeExtensionNode>;
555555

556-
constructor(config: GraphQLScalarTypeConfig<mixed, mixed>): void {
556+
constructor(config: $ReadOnly<GraphQLScalarTypeConfig<mixed, mixed>>): void {
557557
const parseValue = config.parseValue || identityFunc;
558558
this.name = config.name;
559559
this.description = config.description;
@@ -678,7 +678,7 @@ export class GraphQLObjectType {
678678
_fields: Thunk<GraphQLFieldMap<any, any>>;
679679
_interfaces: Thunk<Array<GraphQLInterfaceType>>;
680680
681-
constructor(config: GraphQLObjectTypeConfig<any, any>): void {
681+
constructor(config: $ReadOnly<GraphQLObjectTypeConfig<any, any>>): void {
682682
this.name = config.name;
683683
this.description = config.description;
684684
this.isTypeOf = config.isTypeOf;
@@ -739,9 +739,10 @@ defineToStringTag(GraphQLObjectType);
739739
defineToJSON(GraphQLObjectType);
740740

741741
function defineInterfaces(
742-
config:
742+
config: $ReadOnly<
743743
| GraphQLObjectTypeConfig<mixed, mixed>
744744
| GraphQLInterfaceTypeConfig<mixed, mixed>,
745+
>,
745746
): Array<GraphQLInterfaceType> {
746747
const interfaces = resolveThunk(config.interfaces) || [];
747748
devAssert(
@@ -752,9 +753,10 @@ function defineInterfaces(
752753
}
753754

754755
function defineFieldMap<TSource, TContext>(
755-
config:
756+
config: $ReadOnly<
756757
| GraphQLObjectTypeConfig<TSource, TContext>
757758
| GraphQLInterfaceTypeConfig<TSource, TContext>,
759+
>,
758760
): GraphQLFieldMap<TSource, TContext> {
759761
const fieldMap = resolveThunk(config.fields) || {};
760762
devAssert(
@@ -983,7 +985,7 @@ export class GraphQLInterfaceType {
983985
_fields: Thunk<GraphQLFieldMap<any, any>>;
984986
_interfaces: Thunk<Array<GraphQLInterfaceType>>;
985987

986-
constructor(config: GraphQLInterfaceTypeConfig<any, any>): void {
988+
constructor(config: $ReadOnly<GraphQLInterfaceTypeConfig<any, any>>): void {
987989
this.name = config.name;
988990
this.description = config.description;
989991
this.resolveType = config.resolveType;
@@ -1092,7 +1094,7 @@ export class GraphQLUnionType {
10921094

10931095
_types: Thunk<Array<GraphQLObjectType>>;
10941096

1095-
constructor(config: GraphQLUnionTypeConfig<any, any>): void {
1097+
constructor(config: $ReadOnly<GraphQLUnionTypeConfig<any, any>>): void {
10961098
this.name = config.name;
10971099
this.description = config.description;
10981100
this.resolveType = config.resolveType;
@@ -1143,7 +1145,7 @@ defineToStringTag(GraphQLUnionType);
11431145
defineToJSON(GraphQLUnionType);
11441146

11451147
function defineTypes(
1146-
config: GraphQLUnionTypeConfig<mixed, mixed>,
1148+
config: $ReadOnly<GraphQLUnionTypeConfig<mixed, mixed>>,
11471149
): Array<GraphQLObjectType> {
11481150
const types = resolveThunk(config.types) || [];
11491151
devAssert(
@@ -1200,7 +1202,7 @@ export class GraphQLEnumType /* <T> */ {
12001202
_valueLookup: Map<any /* T */, GraphQLEnumValue>;
12011203
_nameLookup: ObjMap<GraphQLEnumValue>;
12021204

1203-
constructor(config: GraphQLEnumTypeConfig /* <T> */): void {
1205+
constructor(config: $ReadOnly<GraphQLEnumTypeConfig /* <T> */>): void {
12041206
this.name = config.name;
12051207
this.description = config.description;
12061208
this.extensions = config.extensions && toObjMap(config.extensions);
@@ -1374,7 +1376,7 @@ export class GraphQLInputObjectType {
13741376

13751377
_fields: Thunk<GraphQLInputFieldMap>;
13761378

1377-
constructor(config: GraphQLInputObjectTypeConfig): void {
1379+
constructor(config: $ReadOnly<GraphQLInputObjectTypeConfig>): void {
13781380
this.name = config.name;
13791381
this.description = config.description;
13801382
this.extensions = config.extensions && toObjMap(config.extensions);
@@ -1426,7 +1428,7 @@ defineToStringTag(GraphQLInputObjectType);
14261428
defineToJSON(GraphQLInputObjectType);
14271429

14281430
function defineInputFieldMap(
1429-
config: GraphQLInputObjectTypeConfig,
1431+
config: $ReadOnly<GraphQLInputObjectTypeConfig>,
14301432
): GraphQLInputFieldMap {
14311433
const fieldMap = resolveThunk(config.fields) || {};
14321434
devAssert(

src/type/directives.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class GraphQLDirective {
2121
extensions: Maybe<Readonly<Record<string, any>>>;
2222
astNode: Maybe<DirectiveDefinitionNode>;
2323

24-
constructor(config: GraphQLDirectiveConfig);
24+
constructor(config: Readonly<GraphQLDirectiveConfig>);
2525

2626
toConfig(): GraphQLDirectiveConfig & {
2727
args: GraphQLFieldConfigArgumentMap;

src/type/directives.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class GraphQLDirective {
6161
extensions: ?ReadOnlyObjMap<mixed>;
6262
astNode: ?DirectiveDefinitionNode;
6363

64-
constructor(config: GraphQLDirectiveConfig): void {
64+
constructor(config: $ReadOnly<GraphQLDirectiveConfig>): void {
6565
this.name = config.name;
6666
this.description = config.description;
6767
this.locations = config.locations;

src/type/schema.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class GraphQLSchema {
4646
astNode: Maybe<SchemaDefinitionNode>;
4747
extensionASTNodes: Maybe<ReadonlyArray<SchemaExtensionNode>>;
4848

49-
constructor(config: GraphQLSchemaConfig);
49+
constructor(config: Readonly<GraphQLSchemaConfig>);
5050
getQueryType(): Maybe<GraphQLObjectType>;
5151
getMutationType(): Maybe<GraphQLObjectType>;
5252
getSubscriptionType(): Maybe<GraphQLObjectType>;

src/type/schema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export class GraphQLSchema {
135135
// Used as a cache for validateSchema().
136136
__validationErrors: ?$ReadOnlyArray<GraphQLError>;
137137

138-
constructor(config: GraphQLSchemaConfig): void {
138+
constructor(config: $ReadOnly<GraphQLSchemaConfig>): void {
139139
// If this schema was built from a source known to be valid, then it may be
140140
// marked with assumeValid to avoid an additional type system validation.
141141
if (config && config.assumeValid) {

0 commit comments

Comments
 (0)