Skip to content

Commit 10fab5b

Browse files
saihajIvanGoncharov
authored andcommitted
Switch all files to TS syntax
1 parent adcfe48 commit 10fab5b

File tree

12 files changed

+104
-105
lines changed

12 files changed

+104
-105
lines changed

.eslintrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ overrides:
509509
'@typescript-eslint/consistent-indexed-object-style': off # TODO enable after TS conversion
510510
'@typescript-eslint/consistent-type-assertions':
511511
[error, { assertionStyle: as, objectLiteralTypeAssertions: never }]
512-
'@typescript-eslint/consistent-type-definitions': off # TODO consider
512+
'@typescript-eslint/consistent-type-definitions': error
513513
'@typescript-eslint/consistent-type-imports': off # TODO enable after TS conversion
514514
'@typescript-eslint/explicit-function-return-type': off # TODO consider
515515
'@typescript-eslint/explicit-member-accessibility': off # TODO consider

src/__testUtils__/dedent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export function dedentString(string: string): string {
2727
* str === "{\n test\n}";
2828
*/
2929
export function dedent(
30-
strings: $ReadOnlyArray<string>,
31-
...values: $ReadOnlyArray<string>
30+
strings: ReadonlyArray<string>,
31+
...values: ReadonlyArray<string>
3232
): string {
3333
let str = strings[0];
3434

src/__tests__/starWarsData.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
* JSON objects in a more complex demo.
77
*/
88

9-
type Ship = {
10-
id: string,
11-
name: string,
12-
};
9+
interface Ship {
10+
id: string;
11+
name: string;
12+
}
1313

1414
const allShips: Array<Ship> = [
1515
{ id: '1', name: 'X-Wing' },
@@ -25,11 +25,11 @@ const allShips: Array<Ship> = [
2525
{ id: '8', name: 'Executor' },
2626
];
2727

28-
type Faction = {
29-
id: string,
30-
name: string,
31-
ships: Array<string>,
32-
};
28+
interface Faction {
29+
id: string;
30+
name: string;
31+
ships: Array<string>;
32+
}
3333

3434
const rebels: Faction = {
3535
id: '1',
@@ -59,11 +59,11 @@ export function createShip(shipName: string, factionId: string): Ship {
5959
return newShip;
6060
}
6161

62-
export function getShip(id: string): Ship | void {
62+
export function getShip(id: string): Ship | undefined {
6363
return allShips.find((ship) => ship.id === id);
6464
}
6565

66-
export function getFaction(id: string): Faction | void {
66+
export function getFaction(id: string): Faction | undefined {
6767
return allFactions.find((faction) => faction.id === id);
6868
}
6969

src/connection/__tests__/connection-test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const userType = new GraphQLObjectType({
5555

5656
const { connectionType: friendConnection } = connectionDefinitions({
5757
name: 'Friend',
58+
// @ts-expect-error
5859
nodeType: new GraphQLNonNull(userType),
5960
resolveNode: (edge) => allUsers[edge.node],
6061
edgeFields: () => ({
@@ -72,6 +73,7 @@ const { connectionType: friendConnection } = connectionDefinitions({
7273
});
7374

7475
const { connectionType: userConnection } = connectionDefinitions({
76+
// @ts-expect-error
7577
nodeType: new GraphQLNonNull(userType),
7678
resolveNode: (edge) => allUsers[edge.node],
7779
});

src/connection/arrayConnection.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ import type {
66
ConnectionCursor,
77
} from './connection';
88

9-
type ArraySliceMetaInfo = {
10-
sliceStart: number,
11-
arrayLength: number,
12-
};
9+
interface ArraySliceMetaInfo {
10+
sliceStart: number;
11+
arrayLength: number;
12+
}
1313

1414
/**
1515
* A simple function that accepts an array and connection arguments, and returns
1616
* a connection object for use in GraphQL. It uses array offsets as pagination,
1717
* so pagination will only work if the array is static.
1818
*/
1919
export function connectionFromArray<T>(
20-
data: $ReadOnlyArray<T>,
20+
data: ReadonlyArray<T>,
2121
args: ConnectionArguments,
2222
): Connection<T> {
2323
return connectionFromArraySlice(data, args, {
@@ -31,7 +31,7 @@ export function connectionFromArray<T>(
3131
* promised connection.
3232
*/
3333
export function connectionFromPromisedArray<T>(
34-
dataPromise: Promise<$ReadOnlyArray<T>>,
34+
dataPromise: Promise<ReadonlyArray<T>>,
3535
args: ConnectionArguments,
3636
): Promise<Connection<T>> {
3737
return dataPromise.then((data) => connectionFromArray(data, args));
@@ -47,7 +47,7 @@ export function connectionFromPromisedArray<T>(
4747
* total result large enough to cover the range specified in `args`.
4848
*/
4949
export function connectionFromArraySlice<T>(
50-
arraySlice: $ReadOnlyArray<T>,
50+
arraySlice: ReadonlyArray<T>,
5151
args: ConnectionArguments,
5252
meta: ArraySliceMetaInfo,
5353
): Connection<T> {
@@ -115,7 +115,7 @@ export function connectionFromArraySlice<T>(
115115
* and returns a promised connection.
116116
*/
117117
export function connectionFromPromisedArraySlice<T>(
118-
dataPromise: Promise<$ReadOnlyArray<T>>,
118+
dataPromise: Promise<ReadonlyArray<T>>,
119119
args: ConnectionArguments,
120120
arrayInfo: ArraySliceMetaInfo,
121121
): Promise<Connection<T>> {
@@ -144,7 +144,7 @@ export function cursorToOffset(cursor: ConnectionCursor): number {
144144
* Return the cursor associated with an object in an array.
145145
*/
146146
export function cursorForObjectInConnection<T>(
147-
data: $ReadOnlyArray<T>,
147+
data: ReadonlyArray<T>,
148148
object: T,
149149
): ConnectionCursor | null {
150150
const offset = data.indexOf(object);
@@ -160,7 +160,7 @@ export function cursorForObjectInConnection<T>(
160160
* otherwise it will be the default.
161161
*/
162162
export function getOffsetWithDefault(
163-
cursor: ConnectionCursor | null | void,
163+
cursor: ConnectionCursor | null | undefined,
164164
defaultOffset: number,
165165
): number {
166166
if (typeof cursor !== 'string') {

src/connection/connection.ts

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -67,31 +67,30 @@ export type ConnectionCursor = string;
6767
/**
6868
* A type describing the arguments a connection field receives in GraphQL.
6969
*/
70-
export type ConnectionArguments = {
71-
before?: ConnectionCursor | null,
72-
after?: ConnectionCursor | null,
73-
first?: number | null,
74-
last?: number | null,
75-
...
76-
};
70+
export interface ConnectionArguments {
71+
before?: ConnectionCursor | null;
72+
after?: ConnectionCursor | null;
73+
first?: number | null;
74+
last?: number | null;
75+
}
7776

78-
export type ConnectionConfig = {
79-
name?: string,
80-
nodeType: GraphQLNamedOutputType | GraphQLNonNull<GraphQLNamedOutputType>,
81-
resolveNode?: GraphQLFieldResolver<any, any>,
82-
resolveCursor?: GraphQLFieldResolver<any, any>,
83-
edgeFields?: Thunk<GraphQLFieldConfigMap<any, any>>,
84-
connectionFields?: Thunk<GraphQLFieldConfigMap<any, any>>,
85-
};
77+
export interface ConnectionConfig {
78+
name?: string;
79+
nodeType: GraphQLNamedOutputType | GraphQLNonNull<GraphQLNamedOutputType>;
80+
resolveNode?: GraphQLFieldResolver<any, any>;
81+
resolveCursor?: GraphQLFieldResolver<any, any>;
82+
edgeFields?: Thunk<GraphQLFieldConfigMap<any, any>>;
83+
connectionFields?: Thunk<GraphQLFieldConfigMap<any, any>>;
84+
}
8685

87-
export type GraphQLConnectionDefinitions = {
88-
edgeType: GraphQLObjectType,
89-
connectionType: GraphQLObjectType,
90-
};
86+
export interface GraphQLConnectionDefinitions {
87+
edgeType: GraphQLObjectType;
88+
connectionType: GraphQLObjectType;
89+
}
9190

9291
function resolveMaybeThunk<T>(thingOrThunk: Thunk<T>): T {
9392
return typeof thingOrThunk === 'function'
94-
? // $FlowFixMe[incompatible-use] - if it's a function, we assume a thunk without arguments
93+
? // @ts-expect-error - if it's a function, we assume a thunk without arguments
9594
thingOrThunk()
9695
: thingOrThunk;
9796
}
@@ -145,18 +144,18 @@ export function connectionDefinitions(
145144
/**
146145
* A type designed to be exposed as a `Connection` over GraphQL.
147146
*/
148-
export type Connection<T> = {
149-
edges: Array<Edge<T>>,
150-
pageInfo: PageInfo,
151-
};
147+
export interface Connection<T> {
148+
edges: Array<Edge<T>>;
149+
pageInfo: PageInfo;
150+
}
152151

153152
/**
154153
* A type designed to be exposed as a `Edge` over GraphQL.
155154
*/
156-
export type Edge<T> = {
157-
node: T,
158-
cursor: ConnectionCursor,
159-
};
155+
export interface Edge<T> {
156+
node: T;
157+
cursor: ConnectionCursor;
158+
}
160159

161160
/**
162161
* The common page info type used by all connections.
@@ -187,9 +186,9 @@ const pageInfoType = new GraphQLObjectType({
187186
/**
188187
* A type designed to be exposed as `PageInfo` over GraphQL.
189188
*/
190-
export type PageInfo = {
191-
startCursor: ConnectionCursor | null,
192-
endCursor: ConnectionCursor | null,
193-
hasPreviousPage: boolean,
194-
hasNextPage: boolean,
195-
};
189+
export interface PageInfo {
190+
startCursor: ConnectionCursor | null;
191+
endCursor: ConnectionCursor | null;
192+
hasPreviousPage: boolean;
193+
hasNextPage: boolean;
194+
}

src/mutation/__tests__/mutation-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function dummyResolve() {
2020
}
2121

2222
function wrapInSchema(mutationFields: {
23-
[field: string]: GraphQLFieldConfig<any, any>,
23+
[field: string]: GraphQLFieldConfig<any, any>;
2424
}): GraphQLSchema {
2525
const queryType = new GraphQLObjectType({
2626
name: 'Query',

src/mutation/mutation.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import type {
1313
Thunk,
1414
} from 'graphql';
1515

16-
type MutationFn = (object: any, ctx: any, info: GraphQLResolveInfo) => mixed;
16+
type MutationFn = (object: any, ctx: any, info: GraphQLResolveInfo) => unknown;
1717

1818
function resolveMaybeThunk<T>(thingOrThunk: Thunk<T>): T {
1919
return typeof thingOrThunk === 'function'
20-
? // $FlowFixMe[incompatible-use] - if it's a function, we assume a thunk without arguments
20+
? // @ts-expect-error - if it's a function, we assume a thunk without arguments
2121
thingOrThunk()
2222
: thingOrThunk;
2323
}
@@ -36,23 +36,23 @@ function resolveMaybeThunk<T>(thingOrThunk: Thunk<T>): T {
3636
* input field, and it should return an Object with a key for each
3737
* output field. It may return synchronously, or return a Promise.
3838
*/
39-
type MutationConfig = {
40-
name: string,
41-
description?: string,
42-
deprecationReason?: string,
43-
extensions?: { [name: string]: mixed },
44-
inputFields: Thunk<GraphQLInputFieldConfigMap>,
45-
outputFields: Thunk<GraphQLFieldConfigMap<any, any>>,
46-
mutateAndGetPayload: MutationFn,
47-
};
39+
interface MutationConfig {
40+
name: string;
41+
description?: string;
42+
deprecationReason?: string;
43+
extensions?: { [name: string]: unknown };
44+
inputFields: Thunk<GraphQLInputFieldConfigMap>;
45+
outputFields: Thunk<GraphQLFieldConfigMap<any, any>>;
46+
mutateAndGetPayload: MutationFn;
47+
}
4848

4949
/**
5050
* Returns a GraphQLFieldConfig for the mutation described by the
5151
* provided MutationConfig.
5252
*/
5353
export function mutationWithClientMutationId(
5454
config: MutationConfig,
55-
): GraphQLFieldConfig<mixed, mixed> {
55+
): GraphQLFieldConfig<unknown, unknown> {
5656
const { name, inputFields, outputFields, mutateAndGetPayload } = config;
5757
const augmentedInputFields = () => ({
5858
...resolveMaybeThunk(inputFields),
@@ -93,9 +93,9 @@ export function mutationWithClientMutationId(
9393
}
9494
return injectClientMutationId(payload);
9595

96-
function injectClientMutationId(data: mixed) {
96+
function injectClientMutationId(data: unknown) {
9797
if (typeof data === 'object' && data !== null) {
98-
// $FlowFixMe[cannot-write] It's bad idea to mutate data but we need to pass clientMutationId somehow. Maybe in future we figure out better solution satisfying all our test cases.
98+
// @ts-expect-error FIXME It's bad idea to mutate data but we need to pass clientMutationId somehow. Maybe in future we figure out better solution satisfying all our test cases.
9999
data.clientMutationId = clientMutationId;
100100
}
101101

@@ -107,10 +107,6 @@ export function mutationWithClientMutationId(
107107

108108
// FIXME: Temporary until graphql-js resolves this issue
109109
// See, https://github.com/graphql/graphql-js/pull/3243#issuecomment-919510590
110-
declare function isPromiseLike(value: mixed): boolean %checks(value instanceof
111-
Promise);
112-
113-
// eslint-disable-next-line no-redeclare
114-
function isPromiseLike(value) {
110+
function isPromiseLike(value: any): value is Promise<unknown> {
115111
return typeof value?.then === 'function';
116112
}

src/node/__tests__/plural-test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ const queryType = new GraphQLObjectType({
3333
description: 'Map from a username to the user',
3434
inputType: GraphQLString,
3535
outputType: userType,
36-
resolveSingleInput: (
37-
username: string,
38-
context: { lang: string, ... },
39-
) => ({
36+
resolveSingleInput: (username: string, context: { lang: string }) => ({
4037
username,
4138
url: `www.facebook.com/${username}?lang=${context.lang}`,
4239
}),

0 commit comments

Comments
 (0)