-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathConnectionInterface.js
89 lines (77 loc) · 1.73 KB
/
ConnectionInterface.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall relay
*/
'use strict';
import type {Record} from '../../store/RelayStoreTypes';
type Call = {name: string, ...};
export type EdgeRecord = Record & {
cursor: mixed,
node: Record,
...
};
export type PageInfo = {
endCursor: ?string,
hasNextPage: boolean,
hasPreviousPage: boolean,
startCursor: ?string,
...
};
type ConnectionConfig = {
CURSOR: string,
EDGES: string,
END_CURSOR: string,
HAS_NEXT_PAGE: string,
HAS_PREV_PAGE: string,
NODE: string,
PAGE_INFO: string,
PAGE_INFO_TYPE: string,
START_CURSOR: string,
};
const CONNECTION_CALLS = {
after: true,
before: true,
find: true,
first: true,
last: true,
surrounds: true,
};
let config: ConnectionConfig = {
CURSOR: 'cursor',
EDGES: 'edges',
END_CURSOR: 'endCursor',
HAS_NEXT_PAGE: 'hasNextPage',
HAS_PREV_PAGE: 'hasPreviousPage',
NODE: 'node',
PAGE_INFO_TYPE: 'PageInfo',
PAGE_INFO: 'pageInfo',
START_CURSOR: 'startCursor',
};
/**
* @internal
*
* Defines logic relevant to the informal "Connection" GraphQL interface.
*/
const ConnectionInterface = {
inject(newConfig: ConnectionConfig) {
config = newConfig;
},
get(): ConnectionConfig {
return config;
},
/**
* Checks whether a call exists strictly to encode which parts of a connection
* to fetch. Fields that only differ by connection call values should have the
* same identity.
*/
isConnectionCall(call: Call): boolean {
return CONNECTION_CALLS.hasOwnProperty(call.name);
},
};
module.exports = ConnectionInterface;