Skip to content

Commit 4e891ec

Browse files
committed
connectiontypes: inline types into 'connection.js'
1 parent 30f989b commit 4e891ec

File tree

8 files changed

+88
-86
lines changed

8 files changed

+88
-86
lines changed

src/connection/arrayconnection.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type {
22
Connection,
33
ConnectionArguments,
44
ConnectionCursor,
5-
} from './connectiontypes';
5+
} from './connection';
66

77
// TS_SPECIFIC: This type is only exported by TypeScript
88
export interface ArraySliceMetaInfo {

src/connection/arrayconnection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {
44
Connection,
55
ConnectionArguments,
66
ConnectionCursor,
7-
} from './connectiontypes';
7+
} from './connection';
88

99
type ArraySliceMetaInfo = {|
1010
sliceStart: number,

src/connection/connection.d.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@ export const connectionArgs: GraphQLFieldConfigArgumentMap &
4141
ForwardConnectionArgs &
4242
BackwardConnectionArgs;
4343

44+
/**
45+
* A type alias for cursors in this implementation.
46+
*/
47+
export type ConnectionCursor = string;
48+
49+
/**
50+
* A type describing the arguments a connection field receives in GraphQL.
51+
*/
52+
export interface ConnectionArguments {
53+
before?: ConnectionCursor | null;
54+
after?: ConnectionCursor | null;
55+
first?: number | null;
56+
last?: number | null;
57+
}
58+
4459
export interface ConnectionConfig {
4560
name?: string;
4661
nodeType: GraphQLObjectType;
@@ -62,3 +77,29 @@ export interface GraphQLConnectionDefinitions {
6277
export function connectionDefinitions(
6378
config: ConnectionConfig,
6479
): GraphQLConnectionDefinitions;
80+
81+
/**
82+
* A type designed to be exposed as a `Connection` over GraphQL.
83+
*/
84+
export interface Connection<T> {
85+
edges: Array<Edge<T>>;
86+
pageInfo: PageInfo;
87+
}
88+
89+
/**
90+
* A type designed to be exposed as a `Edge` over GraphQL.
91+
*/
92+
export interface Edge<T> {
93+
node: T;
94+
cursor: ConnectionCursor;
95+
}
96+
97+
/**
98+
* A type designed to be exposed as `PageInfo` over GraphQL.
99+
*/
100+
export interface PageInfo {
101+
startCursor: ConnectionCursor | null;
102+
endCursor: ConnectionCursor | null;
103+
hasPreviousPage: boolean;
104+
hasNextPage: boolean;
105+
}

src/connection/connection.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ export const connectionArgs: GraphQLFieldConfigArgumentMap = {
4949
...backwardConnectionArgs,
5050
};
5151

52+
/**
53+
* A type alias for cursors in this implementation.
54+
*/
55+
export type ConnectionCursor = string;
56+
57+
/**
58+
* A type describing the arguments a connection field receives in GraphQL.
59+
*/
60+
export type ConnectionArguments = {
61+
before?: ConnectionCursor | null,
62+
after?: ConnectionCursor | null,
63+
first?: number | null,
64+
last?: number | null,
65+
...
66+
};
67+
5268
type ConnectionConfig = {|
5369
name?: string,
5470
nodeType: GraphQLObjectType,
@@ -120,6 +136,22 @@ export function connectionDefinitions(
120136
return { edgeType, connectionType };
121137
}
122138

139+
/**
140+
* A type designed to be exposed as a `Connection` over GraphQL.
141+
*/
142+
export type Connection<T> = {|
143+
edges: Array<Edge<T>>,
144+
pageInfo: PageInfo,
145+
|};
146+
147+
/**
148+
* A type designed to be exposed as a `Edge` over GraphQL.
149+
*/
150+
export type Edge<T> = {|
151+
node: T,
152+
cursor: ConnectionCursor,
153+
|};
154+
123155
/**
124156
* The common page info type used by all connections.
125157
*/
@@ -145,3 +177,13 @@ const pageInfoType = new GraphQLObjectType({
145177
},
146178
}),
147179
});
180+
181+
/**
182+
* A type designed to be exposed as `PageInfo` over GraphQL.
183+
*/
184+
export type PageInfo = {|
185+
startCursor: ConnectionCursor | null,
186+
endCursor: ConnectionCursor | null,
187+
hasPreviousPage: boolean,
188+
hasNextPage: boolean,
189+
|};

src/connection/connectiontypes.d.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/connection/connectiontypes.js

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Flow types for creating connection types in the schema
1+
// Types for creating connection types in the schema
22
export type {
33
Connection,
44
ConnectionArguments,

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// Flow types for creating connection types in the schema
1+
// Types for creating connection types in the schema
22
export type {
33
Connection,
44
ConnectionArguments,
55
ConnectionCursor,
66
Edge,
77
PageInfo,
8-
} from './connection/connectiontypes';
8+
} from './connection/connection';
99

1010
// Helpers for creating connection types in the schema
1111
export {

0 commit comments

Comments
 (0)