diff --git a/src/connection/arrayconnection.d.ts b/src/connection/arrayconnection.d.ts index e5d5dc2..d4211b0 100644 --- a/src/connection/arrayconnection.d.ts +++ b/src/connection/arrayconnection.d.ts @@ -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 { diff --git a/src/connection/arrayconnection.js b/src/connection/arrayconnection.js index 6d7e771..597a955 100644 --- a/src/connection/arrayconnection.js +++ b/src/connection/arrayconnection.js @@ -4,7 +4,7 @@ import type { Connection, ConnectionArguments, ConnectionCursor, -} from './connectiontypes'; +} from './connection'; type ArraySliceMetaInfo = {| sliceStart: number, diff --git a/src/connection/connection.d.ts b/src/connection/connection.d.ts index 091a7ba..8a57e3a 100644 --- a/src/connection/connection.d.ts +++ b/src/connection/connection.d.ts @@ -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; @@ -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 { + edges: Array>; + pageInfo: PageInfo; +} + +/** + * A type designed to be exposed as a `Edge` over GraphQL. + */ +export interface Edge { + 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; +} diff --git a/src/connection/connection.js b/src/connection/connection.js index d10c567..fba683f 100644 --- a/src/connection/connection.js +++ b/src/connection/connection.js @@ -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, @@ -120,6 +136,22 @@ export function connectionDefinitions( return { edgeType, connectionType }; } +/** + * A type designed to be exposed as a `Connection` over GraphQL. + */ +export type Connection = {| + edges: Array>, + pageInfo: PageInfo, +|}; + +/** + * A type designed to be exposed as a `Edge` over GraphQL. + */ +export type Edge = {| + node: T, + cursor: ConnectionCursor, +|}; + /** * The common page info type used by all connections. */ @@ -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, +|}; diff --git a/src/connection/connectiontypes.d.ts b/src/connection/connectiontypes.d.ts deleted file mode 100644 index 926067d..0000000 --- a/src/connection/connectiontypes.d.ts +++ /dev/null @@ -1,40 +0,0 @@ -/** - * An flow type alias for cursors in this implementation. - */ -export type ConnectionCursor = string; - -/** - * A flow type designed to be exposed as `PageInfo` over GraphQL. - */ -export interface PageInfo { - startCursor: ConnectionCursor | null; - endCursor: ConnectionCursor | null; - hasPreviousPage: boolean; - hasNextPage: boolean; -} - -/** - * A flow type designed to be exposed as a `Connection` over GraphQL. - */ -export interface Connection { - edges: Array>; - pageInfo: PageInfo; -} - -/** - * A flow type designed to be exposed as a `Edge` over GraphQL. - */ -export interface Edge { - node: T; - cursor: ConnectionCursor; -} - -/** - * A flow 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; -} diff --git a/src/connection/connectiontypes.js b/src/connection/connectiontypes.js deleted file mode 100644 index 32b1986..0000000 --- a/src/connection/connectiontypes.js +++ /dev/null @@ -1,41 +0,0 @@ -/** - * An flow type alias for cursors in this implementation. - */ -export type ConnectionCursor = string; - -/** - * A flow type designed to be exposed as `PageInfo` over GraphQL. - */ -export type PageInfo = {| - startCursor: ConnectionCursor | null, - endCursor: ConnectionCursor | null, - hasPreviousPage: boolean, - hasNextPage: boolean, -|}; - -/** - * A flow type designed to be exposed as a `Connection` over GraphQL. - */ -export type Connection = {| - edges: Array>, - pageInfo: PageInfo, -|}; - -/** - * A flow type designed to be exposed as a `Edge` over GraphQL. - */ -export type Edge = {| - node: T, - cursor: ConnectionCursor, -|}; - -/** - * A flow 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, - ... -}; diff --git a/src/index.d.ts b/src/index.d.ts index db3e875..0f57db5 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -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, diff --git a/src/index.js b/src/index.js index db3e875..aae5b1c 100644 --- a/src/index.js +++ b/src/index.js @@ -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 {