UNPKG

2.02 kBTypeScriptView Raw
1import { GraphQLInterfaceType } from 'graphql';
2import type {
3 GraphQLFieldConfig,
4 GraphQLResolveInfo,
5 GraphQLTypeResolver,
6} from 'graphql';
7interface GraphQLNodeDefinitions<TContext> {
8 nodeInterface: GraphQLInterfaceType;
9 nodeField: GraphQLFieldConfig<unknown, TContext>;
10 nodesField: GraphQLFieldConfig<unknown, TContext>;
11}
12/**
13 * Given a function to map from an ID to an underlying object, and a function
14 * to map from an underlying object to the concrete GraphQLObjectType it
15 * corresponds to, constructs a `Node` interface that objects can implement,
16 * and a field config for a `node` root field.
17 *
18 * If the typeResolver is omitted, object resolution on the interface will be
19 * handled with the `isTypeOf` method on object types, as with any GraphQL
20 * interface without a provided `resolveType` method.
21 */
22export declare function nodeDefinitions<TContext>(
23 fetchById: (
24 id: string,
25 context: TContext,
26 info: GraphQLResolveInfo,
27 ) => unknown,
28 typeResolver?: GraphQLTypeResolver<any, TContext>,
29): GraphQLNodeDefinitions<TContext>;
30interface ResolvedGlobalId {
31 type: string;
32 id: string;
33}
34/**
35 * Takes a type name and an ID specific to that type name, and returns a
36 * "global ID" that is unique among all types.
37 */
38export declare function toGlobalId(type: string, id: string | number): string;
39/**
40 * Takes the "global ID" created by toGlobalID, and returns the type name and ID
41 * used to create it.
42 */
43export declare function fromGlobalId(globalId: string): ResolvedGlobalId;
44/**
45 * Creates the configuration for an id field on a node, using `toGlobalId` to
46 * construct the ID from the provided typename. The type-specific ID is fetched
47 * by calling idFetcher on the object, or if not provided, by accessing the `id`
48 * property on the object.
49 */
50export declare function globalIdField<TContext>(
51 typeName?: string,
52 idFetcher?: (
53 obj: any,
54 context: TContext,
55 info: GraphQLResolveInfo,
56 ) => string | number,
57): GraphQLFieldConfig<any, TContext>;
58export {};