Skip to content

Commit

Permalink
Sync TypeScript types with Flow types (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielrearden authored Jul 11, 2020
1 parent 3bd6838 commit eb2d9e9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 36 deletions.
15 changes: 8 additions & 7 deletions src/connection/arrayconnection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
ConnectionCursor,
} from './connectiontypes';

// TS_SPECIFIC: This type is only exported by TypeScript
export interface ArraySliceMetaInfo {
sliceStart: number;
arrayLength: number;
Expand All @@ -15,7 +16,7 @@ export interface ArraySliceMetaInfo {
* so pagination will only work if the array is static.
*/
export function connectionFromArray<T>(
data: T[],
data: ReadonlyArray<T>,
args: ConnectionArguments,
): Connection<T>;

Expand All @@ -24,7 +25,7 @@ export function connectionFromArray<T>(
* promised connection.
*/
export function connectionFromPromisedArray<T>(
dataPromise: Promise<T[]>,
dataPromise: Promise<ReadonlyArray<T>>,
args: ConnectionArguments,
): Promise<Connection<T>>;

Expand All @@ -38,7 +39,7 @@ export function connectionFromPromisedArray<T>(
* total result large enough to cover the range specified in `args`.
*/
export function connectionFromArraySlice<T>(
arraySlice: T[],
arraySlice: ReadonlyArray<T>,
args: ConnectionArguments,
meta: ArraySliceMetaInfo,
): Connection<T>;
Expand All @@ -48,7 +49,7 @@ export function connectionFromArraySlice<T>(
* and returns a promised connection.
*/
export function connectionFromPromisedArraySlice<T>(
dataPromise: Promise<T[]>,
dataPromise: Promise<ReadonlyArray<T>>,
args: ConnectionArguments,
arrayInfo: ArraySliceMetaInfo,
): Promise<Connection<T>>;
Expand All @@ -67,9 +68,9 @@ export function cursorToOffset(cursor: ConnectionCursor): number;
* Return the cursor associated with an object in an array.
*/
export function cursorForObjectInConnection<T>(
data: T[],
data: ReadonlyArray<T>,
object: T,
): ConnectionCursor;
): ConnectionCursor | null | undefined;

/**
* Given an optional cursor and a default offset, returns the offset
Expand All @@ -78,5 +79,5 @@ export function cursorForObjectInConnection<T>(
*/
export function getOffsetWithDefault(
cursor?: ConnectionCursor | null,
defaultOffset?: number | null,
defaultOffset: number,
): number;
23 changes: 3 additions & 20 deletions src/connection/connection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import type {
Thunk,
} from 'graphql';

/**
* Returns a GraphQLFieldConfigArgumentMap appropriate to include on a field
* whose return type is a connection type with forward pagination.
*/
// TS_SPECIFIC: This type is only exported by TypeScript. Flow uses the spread operator instead.
export interface ForwardConnectionArgs {
after: { type: GraphQLScalarType };
first: { type: GraphQLScalarType };
Expand All @@ -23,10 +20,7 @@ export interface ForwardConnectionArgs {
export const forwardConnectionArgs: GraphQLFieldConfigArgumentMap &
ForwardConnectionArgs;

/**
* Returns a GraphQLFieldConfigArgumentMap appropriate to include on a field
* whose return type is a connection type with backward pagination.
*/
// TS_SPECIFIC: This type is only exported by TypeScript. Flow uses the spread operator instead.
export interface BackwardConnectionArgs {
before: { type: GraphQLScalarType };
last: { type: GraphQLScalarType };
Expand All @@ -47,20 +41,9 @@ export const connectionArgs: GraphQLFieldConfigArgumentMap &
ForwardConnectionArgs &
BackwardConnectionArgs;

export type ConnectionConfigNodeTypeNullable =
| GraphQLScalarType
| GraphQLObjectType
| GraphQLInterfaceType
| GraphQLUnionType
| GraphQLEnumType;

export type ConnectionConfigNodeType =
| ConnectionConfigNodeTypeNullable
| GraphQLNonNull<ConnectionConfigNodeTypeNullable>;

export interface ConnectionConfig {
name?: string | null;
nodeType: ConnectionConfigNodeType;
nodeType: GraphQLObjectType;
resolveNode?: GraphQLFieldResolver<any, any> | null;
resolveCursor?: GraphQLFieldResolver<any, any> | null;
edgeFields?: Thunk<GraphQLFieldConfigMap<any, any>> | null;
Expand Down
6 changes: 4 additions & 2 deletions src/mutation/mutation.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import type {
Thunk,
} from 'graphql';

export type mutationFn = (
// TS_SPECIFIC: This type is only exported by TypeScript
export type MutationFn = (
object: any,
ctx: any,
info: GraphQLResolveInfo,
) => Promise<any> | any;

// TS_SPECIFIC: This type is only exported by TypeScript
/**
* A description of a mutation consumable by mutationWithClientMutationId
* to create a GraphQLFieldConfig for that mutation.
Expand All @@ -31,7 +33,7 @@ export interface MutationConfig {
description?: string;
inputFields: Thunk<GraphQLInputFieldConfigMap>;
outputFields: Thunk<GraphQLFieldConfigMap<any, any>>;
mutateAndGetPayload: mutationFn;
mutateAndGetPayload: MutationFn;
deprecationReason?: string;
}

Expand Down
14 changes: 8 additions & 6 deletions src/node/node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import type {
GraphQLTypeResolver,
} from 'graphql';

export interface GraphQLNodeDefinitions {
// TS_SPECIFIC: This type is only exported by TypeScript
export interface GraphQLNodeDefinitions<TContext> {
nodeInterface: GraphQLInterfaceType;
nodeField: GraphQLFieldConfig<any, any>;
nodesField: GraphQLFieldConfig<any, any>;
nodeField: GraphQLFieldConfig<any, TContext>;
nodesField: GraphQLFieldConfig<any, TContext>;
}

/**
Expand All @@ -22,9 +23,10 @@ export interface GraphQLNodeDefinitions {
*/
export function nodeDefinitions<TContext>(
idFetcher: (id: string, context: TContext, info: GraphQLResolveInfo) => any,
typeResolver?: GraphQLTypeResolver<any, TContext>,
): GraphQLNodeDefinitions;
typeResolver?: GraphQLTypeResolver<any, TContext> | null,
): GraphQLNodeDefinitions<TContext>;

// TS_SPECIFIC: This type is only exported by TypeScript
export interface ResolvedGlobalId {
type: string;
id: string;
Expand All @@ -49,6 +51,6 @@ export function fromGlobalId(globalId: string): ResolvedGlobalId;
* property on the object.
*/
export function globalIdField(
typeName?: string,
typeName?: string | null,
idFetcher?: (object: any, context: any, info: GraphQLResolveInfo) => string,
): GraphQLFieldConfig<any, any>;
7 changes: 6 additions & 1 deletion src/node/plural.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ import type {
GraphQLResolveInfo,
} from 'graphql';

// TS_SPECIFIC: This type is only exported by TypeScript
export interface PluralIdentifyingRootFieldConfig {
argName: string;
inputType: GraphQLInputType;
outputType: GraphQLOutputType;
resolveSingleInput(input: any, context: any, info: GraphQLResolveInfo): any;
resolveSingleInput: (
input: any,
context: any,
info: GraphQLResolveInfo,
) => any;
description?: string;
}

Expand Down

0 comments on commit eb2d9e9

Please sign in to comment.