UNPKG

3.55 kBTypeScriptView Raw
1/// <reference types="react" />
2import { GraphQLSchema, GraphQLNamedType, GraphQLFieldResolver } from 'graphql';
3import { SanityWebhookBody } from './sanity';
4interface GatsbyEventEmitter {
5 on: (event: String, fn: Function) => null;
6 off: (event: String, fn: Function) => null;
7}
8interface GatsbyStoreState {
9 program: {
10 directory: string;
11 };
12}
13interface GatsbyStore {
14 getState: () => GatsbyStoreState;
15}
16export interface GatsbyNode {
17 id: string;
18 _id: string;
19 parent?: string | null;
20 children?: string[];
21 internal?: {
22 mediaType?: string;
23 type: string;
24 contentDigest: string;
25 };
26 [key: string]: any;
27}
28export interface GatsbyReporter {
29 info: (msg: string) => null;
30 warn: (msg: string) => null;
31 error: (msg: string) => null;
32 panic: (msg: string) => null;
33 panicOnBuild: (msg: string) => null;
34}
35export interface GatsbyParentChildLink {
36 parent: GatsbyNode;
37 child: GatsbyNode;
38}
39export interface GatsbyDeleteOptions {
40 node: GatsbyNode;
41}
42export declare type GatsbyNodeModel = {
43 getNodeById: (args: {
44 id: string;
45 }) => GatsbyNode;
46};
47export declare type GatsbyGraphQLContext = {
48 nodeModel: GatsbyNodeModel;
49};
50export interface MinimalGatsbyContext {
51 createNodeId: GatsbyNodeIdCreator;
52 getNode: (id: string) => GatsbyNode | undefined;
53}
54export declare type GatsbyTypesCreator = (types: string) => null;
55export declare type GatsbyResolverMap = {
56 [typeName: string]: {
57 [fieldName: string]: {
58 type?: string;
59 resolve: GraphQLFieldResolver<{
60 [key: string]: any;
61 }, GatsbyGraphQLContext>;
62 };
63 };
64};
65export declare type GatsbyResolversCreator = (resolvers: GatsbyResolverMap) => null;
66export declare type GatsbyNodeCreator = (node: GatsbyNode) => null;
67export declare type GatsbyNodeDeletor = (options: GatsbyDeleteOptions) => null;
68export declare type GatsbyNodeIdCreator = (id: string, namespace?: string) => string;
69export declare type GatsbyContentDigester = (content: string) => string;
70export declare type GatsbyParentChildLinker = (link: GatsbyParentChildLink) => null;
71export interface GatsbyCache {
72 name: string;
73 cache: {
74 del: (key: string) => Promise<any>;
75 get: (key: string) => Promise<any>;
76 set: (key: string, value: any) => Promise<any>;
77 mset: (key1: string, val1: any, key2: string, val2: any, key3?: string, val3?: any) => Promise<any>;
78 };
79}
80export interface GatsbyOnNodeTypeContext {
81 type: GraphQLNamedType;
82}
83export interface GatsbyContext {
84 emitter: GatsbyEventEmitter;
85 cache: GatsbyCache;
86 actions: GatsbyActions;
87 createNodeId: GatsbyNodeIdCreator;
88 createContentDigest: GatsbyContentDigester;
89 store: GatsbyStore;
90 getNode: (id: string) => GatsbyNode | undefined;
91 getNodes: () => GatsbyNode[];
92 reporter: GatsbyReporter;
93 webhookBody?: SanityWebhookBody;
94}
95export interface GatsbySsrContext {
96 setHeadComponents: (components: React.ReactElement[]) => undefined;
97}
98export interface GatsbyActions {
99 createTypes: GatsbyTypesCreator;
100 createResolvers: GatsbyResolversCreator;
101 createNode: GatsbyNodeCreator;
102 deleteNode: GatsbyNodeDeletor;
103 createParentChildLink: GatsbyParentChildLinker;
104 touchNode: (options: {
105 nodeId: string;
106 }) => null;
107 addThirdPartySchema: (schema: {
108 schema: GraphQLSchema | string;
109 }) => null;
110}
111export interface ReduxSetSchemaAction {
112 payload: GraphQLSchema;
113}
114export {};