// Type definitions for graphql-relay 0.4 // Project: https://github.com/graphql/graphql-relay-js // Definitions by: Arvitaly , nitintutlani , Grelinfo // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.6 import { GraphQLBoolean, GraphQLInt, GraphQLNonNull, GraphQLList, GraphQLObjectType, GraphQLString, GraphQLFieldConfig, GraphQLInputFieldConfigMap, GraphQLFieldConfigMap, GraphQLFieldConfigArgumentMap, GraphQLResolveInfo, GraphQLInterfaceType, GraphQLInputType, GraphQLOutputType, GraphQLFieldResolver, GraphQLTypeResolver, GraphQLUnionType, GraphQLEnumType, GraphQLScalarType, Thunk } from "graphql"; // connection/connection.js /** * Returns a GraphQLFieldConfigArgumentMap appropriate to include on a field * whose return type is a connection type with forward pagination. */ export interface ForwardConnectionArgs { after: { type: GraphQLScalarType }; first: { type: GraphQLScalarType }; } export const forwardConnectionArgs: GraphQLFieldConfigArgumentMap & ForwardConnectionArgs; /** * Returns a GraphQLFieldConfigArgumentMap appropriate to include on a field * whose return type is a connection type with backward pagination. */ export interface BackwardConnectionArgs { before: { type: GraphQLScalarType }; last: { type: GraphQLScalarType }; } export const backwardConnectionArgs: GraphQLFieldConfigArgumentMap & BackwardConnectionArgs; /** * Returns a GraphQLFieldConfigArgumentMap appropriate to include on a field * whose return type is a connection type with bidirectional pagination. */ export const connectionArgs: GraphQLFieldConfigArgumentMap & ForwardConnectionArgs & BackwardConnectionArgs; export type ConnectionConfigNodeTypeNullable = | GraphQLScalarType | GraphQLObjectType | GraphQLInterfaceType | GraphQLUnionType | GraphQLEnumType; export type ConnectionConfigNodeType = | ConnectionConfigNodeTypeNullable | GraphQLNonNull; export interface ConnectionConfig { name?: string | null; nodeType: ConnectionConfigNodeType; resolveNode?: GraphQLFieldResolver | null; resolveCursor?: GraphQLFieldResolver | null; edgeFields?: Thunk> | null; connectionFields?: Thunk> | null; } export interface GraphQLConnectionDefinitions { edgeType: GraphQLObjectType; connectionType: GraphQLObjectType; } /** * Returns a GraphQLObjectType for a connection with the given name, * and whose nodes are of the specified type. */ export function connectionDefinitions( config: ConnectionConfig ): GraphQLConnectionDefinitions; // connection/connectiontypes.js /** * 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 | null; hasNextPage?: boolean | null; } /** * 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; } // connection/arrayconnection.js export interface ArraySliceMetaInfo { sliceStart: number; arrayLength: number; } /** * A simple function that accepts an array and connection arguments, and returns * a connection object for use in GraphQL. It uses array offsets as pagination, * so pagination will only work if the array is static. */ export function connectionFromArray( data: T[], args: ConnectionArguments ): Connection; /** * A version of `connectionFromArray` that takes a promised array, and returns a * promised connection. */ export function connectionFromPromisedArray( dataPromise: Promise, args: ConnectionArguments ): Promise>; /** * Given a slice (subset) of an array, returns a connection object for use in * GraphQL. * * This function is similar to `connectionFromArray`, but is intended for use * cases where you know the cardinality of the connection, consider it too large * to materialize the entire array, and instead wish pass in a slice of the * total result large enough to cover the range specified in `args`. */ export function connectionFromArraySlice( arraySlice: T[], args: ConnectionArguments, meta: ArraySliceMetaInfo ): Connection; /** * A version of `connectionFromArraySlice` that takes a promised array slice, * and returns a promised connection. */ export function connectionFromPromisedArraySlice( dataPromise: Promise, args: ConnectionArguments, arrayInfo: ArraySliceMetaInfo ): Promise>; /** * Creates the cursor string from an offset. */ export function offsetToCursor(offset: number): ConnectionCursor; /** * Rederives the offset from the cursor string. */ export function cursorToOffset(cursor: ConnectionCursor): number; /** * Return the cursor associated with an object in an array. */ export function cursorForObjectInConnection( data: T[], object: T ): ConnectionCursor; /** * Given an optional cursor and a default offset, returns the offset * to use; if the cursor contains a valid offset, that will be used, * otherwise it will be the default. */ export function getOffsetWithDefault( cursor?: ConnectionCursor | null, defaultOffset?: number | null ): number; // mutation/mutation.js export type mutationFn = ( object: any, ctx: any, info: GraphQLResolveInfo ) => Promise | any; /** * A description of a mutation consumable by mutationWithClientMutationId * to create a GraphQLFieldConfig for that mutation. * * The inputFields and outputFields should not include `clientMutationId`, * as this will be provided automatically. * * An input object will be created containing the input fields, and an * object will be created containing the output fields. * * mutateAndGetPayload will receieve an Object with a key for each * input field, and it should return an Object with a key for each * output field. It may return synchronously, or return a Promise. */ export interface MutationConfig { name: string; description?: string; inputFields: Thunk; outputFields: Thunk>; mutateAndGetPayload: mutationFn; deprecationReason?: string; } /** * Returns a GraphQLFieldConfig for the mutation described by the * provided MutationConfig. */ export function mutationWithClientMutationId( config: MutationConfig ): GraphQLFieldConfig; // node/node.js export interface GraphQLNodeDefinitions { nodeInterface: GraphQLInterfaceType; nodeField: GraphQLFieldConfig; nodesField: GraphQLFieldConfig; } export type typeResolverFn = ((any: any) => GraphQLObjectType) | ((any: any) => Promise); /** * Given a function to map from an ID to an underlying object, and a function * to map from an underlying object to the concrete GraphQLObjectType it * corresponds to, constructs a `Node` interface that objects can implement, * and a field config for a `node` root field. * * If the typeResolver is omitted, object resolution on the interface will be * handled with the `isTypeOf` method on object types, as with any GraphQL * interface without a provided `resolveType` method. */ export function nodeDefinitions( idFetcher: ((id: string, context: TContext, info: GraphQLResolveInfo) => any), typeResolver?: GraphQLTypeResolver ): GraphQLNodeDefinitions; export interface ResolvedGlobalId { type: string; id: string; } /** * Takes a type name and an ID specific to that type name, and returns a * "global ID" that is unique among all types. */ export function toGlobalId(type: string, id: string): string; /** * Takes the "global ID" created by toGlobalID, and returns the type name and ID * used to create it. */ export function fromGlobalId(globalId: string): ResolvedGlobalId; /** * Creates the configuration for an id field on a node, using `toGlobalId` to * construct the ID from the provided typename. The type-specific ID is fetched * by calling idFetcher on the object, or if not provided, by accessing the `id` * property on the object. */ export function globalIdField( typeName?: string, idFetcher?: (object: any, context: any, info: GraphQLResolveInfo) => string ): GraphQLFieldConfig; // node/plural.js export interface PluralIdentifyingRootFieldConfig { argName: string; inputType: GraphQLInputType; outputType: GraphQLOutputType; resolveSingleInput(input: any, context: any, info: GraphQLResolveInfo): any; description?: string; } export function pluralIdentifyingRootField( config: PluralIdentifyingRootFieldConfig ): GraphQLFieldConfig;