Skip to content

Commit

Permalink
connectiontypes: inline types into 'connection.js'
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Mar 19, 2021
1 parent 30f989b commit 4e891ec
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 86 deletions.
2 changes: 1 addition & 1 deletion src/connection/arrayconnection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {
Connection,
ConnectionArguments,
ConnectionCursor,
} from './connectiontypes';
} from './connection';

// TS_SPECIFIC: This type is only exported by TypeScript
export interface ArraySliceMetaInfo {
Expand Down
2 changes: 1 addition & 1 deletion src/connection/arrayconnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
Connection,
ConnectionArguments,
ConnectionCursor,
} from './connectiontypes';
} from './connection';

type ArraySliceMetaInfo = {|
sliceStart: number,
Expand Down
41 changes: 41 additions & 0 deletions src/connection/connection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ export const connectionArgs: GraphQLFieldConfigArgumentMap &
ForwardConnectionArgs &
BackwardConnectionArgs;

/**
* A type alias for cursors in this implementation.
*/
export type ConnectionCursor = string;

/**
* A type describing the arguments a connection field receives in GraphQL.
*/
export interface ConnectionArguments {
before?: ConnectionCursor | null;
after?: ConnectionCursor | null;
first?: number | null;
last?: number | null;
}

export interface ConnectionConfig {
name?: string;
nodeType: GraphQLObjectType;
Expand All @@ -62,3 +77,29 @@ export interface GraphQLConnectionDefinitions {
export function connectionDefinitions(
config: ConnectionConfig,
): GraphQLConnectionDefinitions;

/**
* A type designed to be exposed as a `Connection` over GraphQL.
*/
export interface Connection<T> {
edges: Array<Edge<T>>;
pageInfo: PageInfo;
}

/**
* A type designed to be exposed as a `Edge` over GraphQL.
*/
export interface Edge<T> {
node: T;
cursor: ConnectionCursor;
}

/**
* A type designed to be exposed as `PageInfo` over GraphQL.
*/
export interface PageInfo {
startCursor: ConnectionCursor | null;
endCursor: ConnectionCursor | null;
hasPreviousPage: boolean;
hasNextPage: boolean;
}
42 changes: 42 additions & 0 deletions src/connection/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ export const connectionArgs: GraphQLFieldConfigArgumentMap = {
...backwardConnectionArgs,
};

/**
* A type alias for cursors in this implementation.
*/
export type ConnectionCursor = string;

/**
* A type describing the arguments a connection field receives in GraphQL.
*/
export type ConnectionArguments = {
before?: ConnectionCursor | null,
after?: ConnectionCursor | null,
first?: number | null,
last?: number | null,
...
};

type ConnectionConfig = {|
name?: string,
nodeType: GraphQLObjectType,
Expand Down Expand Up @@ -120,6 +136,22 @@ export function connectionDefinitions(
return { edgeType, connectionType };
}

/**
* A type designed to be exposed as a `Connection` over GraphQL.
*/
export type Connection<T> = {|
edges: Array<Edge<T>>,
pageInfo: PageInfo,
|};

/**
* A type designed to be exposed as a `Edge` over GraphQL.
*/
export type Edge<T> = {|
node: T,
cursor: ConnectionCursor,
|};

/**
* The common page info type used by all connections.
*/
Expand All @@ -145,3 +177,13 @@ const pageInfoType = new GraphQLObjectType({
},
}),
});

/**
* A type designed to be exposed as `PageInfo` over GraphQL.
*/
export type PageInfo = {|
startCursor: ConnectionCursor | null,
endCursor: ConnectionCursor | null,
hasPreviousPage: boolean,
hasNextPage: boolean,
|};
40 changes: 0 additions & 40 deletions src/connection/connectiontypes.d.ts

This file was deleted.

41 changes: 0 additions & 41 deletions src/connection/connectiontypes.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Flow types for creating connection types in the schema
// Types for creating connection types in the schema
export type {
Connection,
ConnectionArguments,
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Flow types for creating connection types in the schema
// Types for creating connection types in the schema
export type {
Connection,
ConnectionArguments,
ConnectionCursor,
Edge,
PageInfo,
} from './connection/connectiontypes';
} from './connection/connection';

// Helpers for creating connection types in the schema
export {
Expand Down

0 comments on commit 4e891ec

Please sign in to comment.