forked from pluralsh/absinthe-socket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreact-relay_v1.x.x.js
1267 lines (1135 loc) · 36.9 KB
/
react-relay_v1.x.x.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
declare module "react-relay" {
declare export type RecordState = "EXISTENT" | "NONEXISTENT" | "UNKNOWN";
declare export type onCompleted = (
response: ?Object,
errors: ?Array<PayloadError>
) => void;
declare export type onError = (error: Error) => void;
declare export type CommitOptions = {
onCompleted: onCompleted,
onError: onError
};
/**
* Ideally this would be a union of Field/Fragment/Mutation/Query/Subscription,
* but that causes lots of Flow errors.
*/
declare export type ConcreteBatchCallVariable = {
jsonPath: string,
kind: "BatchCallVariable",
sourceQueryID: string
};
declare export type ConcreteCall = {
kind: "Call",
metadata: {
type?: ?string
},
name: string,
value: ?ConcreteValue
};
declare export type ConcreteCallValue = {
callValue: mixed,
kind: "CallValue"
};
declare export type ConcreteCallVariable = {
callVariableName: string,
kind: "CallVariable"
};
declare export type ConcreteDirective = {
args: Array<ConcreteDirectiveArgument>,
kind: "Directive",
name: string
};
declare export type ConcreteDirectiveArgument = {
name: string,
value: ?ConcreteDirectiveValue
};
declare export type ConcreteDirectiveValue =
| ConcreteCallValue
| ConcreteCallVariable
| Array<ConcreteCallValue | ConcreteCallVariable>;
declare export type ConcreteFieldMetadata = {
canHaveSubselections?: ?boolean,
inferredPrimaryKey?: ?string,
inferredRootCallName?: ?string,
isAbstract?: boolean,
isConnection?: boolean,
isConnectionWithoutNodeID?: boolean,
isFindable?: boolean,
isGenerated?: boolean,
isPlural?: boolean,
isRequisite?: boolean
};
declare export type ConcreteFragmentMetadata = {
isAbstract?: boolean,
pattern?: boolean,
plural?: boolean
};
declare export type ConcreteMutation = {
calls: Array<ConcreteCall>,
children?: ?Array<?ConcreteSelection>,
directives?: ?Array<ConcreteDirective>,
kind: "Mutation",
metadata: {
inputType?: ?string
},
name: string,
responseType: string
};
declare export type ConcreteOperationMetadata = {
inputType?: ?string
};
declare export type ConcreteQuery = {
calls?: ?Array<ConcreteCall>,
children?: ?Array<?ConcreteSelection>,
directives?: ?Array<ConcreteDirective>,
fieldName: string,
isDeferred?: boolean,
kind: "Query",
metadata: {
identifyingArgName?: ?string,
identifyingArgType?: ?string,
isAbstract?: ?boolean,
isPlural?: ?boolean
},
name: string,
type: string
};
declare export type ConcreteQueryMetadata = {
identifyingArgName: ?string,
identifyingArgType: ?string,
isAbstract: ?boolean,
isDeferred: ?boolean,
isPlural: ?boolean
};
declare export type ConcreteSubscription = {
calls: Array<ConcreteCall>,
children?: ?Array<?ConcreteSelection>,
directives?: ?Array<ConcreteDirective>,
kind: "Subscription",
name: string,
responseType: string,
metadata: {
inputType?: ?string
}
};
declare export type ConcreteValue =
| ConcreteBatchCallVariable
| ConcreteCallValue
| ConcreteCallVariable
| Array<ConcreteCallValue | ConcreteCallVariable>;
/**
* The output of a graphql-tagged fragment definition.
*/
declare export type ConcreteFragmentDefinition = {
kind: "FragmentDefinition",
argumentDefinitions: Array<ConcreteArgumentDefinition>,
node: ConcreteFragment
};
declare export type ConcreteLocalArgumentDefinition = {
kind: "LocalArgument",
name: string,
defaultValue: mixed
};
declare export type ConcreteRootArgumentDefinition = {
kind: "RootArgument",
name: string
};
/**
* The output of a graphql-tagged operation definition.
*/
declare export type ConcreteOperationDefinition = {
kind: "OperationDefinition",
argumentDefinitions: Array<ConcreteLocalArgumentDefinition>,
name: string,
operation: "mutation" | "query" | "subscription",
node: ConcreteFragment | ConcreteMutation | ConcreteSubscription
};
declare export type ConcreteArgument = ConcreteLiteral | ConcreteVariable;
declare export type ConcreteArgumentDefinition =
| ConcreteLocalArgument
| ConcreteRootArgument;
/**
* Represents a single ConcreteRoot along with metadata for processing it at
* runtime. The persisted `id` (or `text`) can be used to fetch the query,
* the `fragment` can be used to read the root data (masking data from child
* fragments), and the `query` can be used to normalize server responses.
*
* NOTE: The use of "batch" in the name is intentional, as this wrapper around
* the ConcreteRoot will provide a place to store multiple concrete nodes that
* are part of the same batch, e.g. in the case of deferred nodes or
* for streaming connections that are represented as distinct concrete roots but
* are still conceptually tied to one source query.
*/
declare export type ConcreteBatch = {
kind: "Batch",
fragment: ConcreteFragment,
id: ?string,
metadata: {[key: string]: mixed},
name: string,
query: ConcreteRoot,
text: ?string
};
declare export type ConcreteCondition = {
kind: "Condition",
passingValue: boolean,
condition: string,
selections: Array<ConcreteSelection>
};
declare export type ConcreteField = ConcreteScalarField | ConcreteLinkedField;
declare export type ConcreteFragment = {
argumentDefinitions: Array<ConcreteArgumentDefinition>,
kind: "Fragment",
metadata: ?{[key: string]: mixed},
name: string,
selections: Array<ConcreteSelection>,
type: string
};
declare export type ConcreteFragmentSpread = {
args: ?Array<ConcreteArgument>,
kind: "FragmentSpread",
name: string
};
declare export type ConcreteHandle =
| ConcreteScalarHandle
| ConcreteLinkedHandle;
declare export type ConcreteRootArgument = {
kind: "RootArgument",
name: string,
type: ?string
};
declare export type ConcreteInlineFragment = {
kind: "InlineFragment",
selections: Array<ConcreteSelection>,
type: string
};
declare export type ConcreteLinkedField = {
alias: ?string,
args: ?Array<ConcreteArgument>,
concreteType: ?string,
kind: "LinkedField",
name: string,
plural: boolean,
selections: Array<ConcreteSelection>,
storageKey: ?string
};
declare export type ConcreteLinkedHandle = {
alias: ?string,
args: ?Array<ConcreteArgument>,
kind: "LinkedHandle",
name: string,
handle: string,
key: string,
filters: ?Array<string>
};
declare export type ConcreteLiteral = {
kind: "Literal",
name: string,
type: ?string,
value: mixed
};
declare export type ConcreteLocalArgument = {
defaultValue: mixed,
kind: "LocalArgument",
name: string,
type: string
};
declare export type ConcreteNode =
| ConcreteCondition
| ConcreteLinkedField
| ConcreteFragment
| ConcreteInlineFragment
| ConcreteRoot;
declare export type ConcreteRoot = {
argumentDefinitions: Array<ConcreteLocalArgument>,
kind: "Root",
name: string,
operation: "mutation" | "query" | "subscription",
selections: Array<ConcreteSelection>
};
declare export type ConcreteScalarField = {
alias: ?string,
args: ?Array<ConcreteArgument>,
kind: "ScalarField",
name: string,
storageKey: ?string
};
declare export type ConcreteScalarHandle = {
alias: ?string,
args: ?Array<ConcreteArgument>,
kind: "ScalarHandle",
name: string,
handle: string,
key: string,
filters: ?Array<string>
};
declare export type ConcreteSelection =
| ConcreteCondition
| ConcreteField
| ConcreteFragmentSpread
| ConcreteHandle
| ConcreteInlineFragment;
declare export type ConcreteVariable = {
kind: "Variable",
name: string,
type: ?string,
variableName: string
};
declare export type ConcreteSelectableNode = ConcreteFragment | ConcreteRoot;
declare export type GeneratedNode = ConcreteBatch | ConcreteFragment;
// The type of a graphql`...` tagged template expression.
declare export type GraphQLTaggedNode =
| (() => ConcreteFragment | ConcreteBatch)
| {
modern: () => ConcreteFragment | ConcreteBatch,
classic: () => ConcreteFragmentDefinition | ConcreteOperationDefinition
};
declare export function graphql(strings: Array<string>): GraphQLTaggedNode;
declare export type GeneratedNodeMap = {[key: string]: GraphQLTaggedNode};
declare export function createFragmentContainer<
TBase: React$ComponentType<*>
>(
Component: TBase,
fragmentSpec: GraphQLTaggedNode | GeneratedNodeMap
): TBase;
declare export function createRefetchContainer<TBase: React$ComponentType<*>>(
Component: TBase,
fragmentSpec: GraphQLTaggedNode | GeneratedNodeMap,
taggedNode: GraphQLTaggedNode
): TBase;
declare export type Variables = {[name: string]: $FlowFixMe};
declare export type DataID = string;
declare type TEnvironment = Environment;
declare type TFragment = ConcreteFragment;
declare type TGraphQLTaggedNode = GraphQLTaggedNode;
declare type TNode = ConcreteSelectableNode;
declare type TOperation = ConcreteBatch;
declare type TPayload = RelayResponsePayload;
declare export type FragmentMap = CFragmentMap<TFragment>;
declare export type OperationSelector = COperationSelector<TNode, TOperation>;
declare export type RelayContext = CRelayContext<TEnvironment>;
declare export type Selector = CSelector<TNode>;
declare export type TSnapshot<TRecord> = CSnapshot<TNode, TRecord>;
declare export type Snapshot = TSnapshot<Record>;
declare export type ProxySnapshot = TSnapshot<RecordProxy>;
declare export type UnstableEnvironmentCore = CUnstableEnvironmentCore<
TEnvironment,
TFragment,
TGraphQLTaggedNode,
TNode,
TOperation
>;
declare export interface IRecordSource<TRecord> {
get(dataID: DataID): ?TRecord;
}
/**
* A read-only interface for accessing cached graph data.
*/
declare export interface RecordSource extends IRecordSource<Record> {
get(dataID: DataID): ?Record;
getRecordIDs(): Array<DataID>;
getStatus(dataID: DataID): RecordState;
has(dataID: DataID): boolean;
load(
dataID: DataID,
callback: (error: ?Error, record: ?Record) => void
): void;
size(): number;
}
/**
* A read/write interface for accessing and updating graph data.
*/
declare export interface MutableRecordSource extends RecordSource {
clear(): void;
delete(dataID: DataID): void;
remove(dataID: DataID): void;
set(dataID: DataID, record: Record): void;
}
/**
* An interface for keeping multiple views of data consistent across an
* application.
*/
declare export interface Store {
/**
* Get a read-only view of the store's internal RecordSource.
*/
getSource(): RecordSource;
/**
* Determine if the selector can be resolved with data in the store (i.e. no
* fields are missing).
*/
check(selector: Selector): boolean;
/**
* Read the results of a selector from in-memory records in the store.
*/
lookup(selector: Selector): Snapshot;
/**
* Notify subscribers (see `subscribe`) of any data that was published
* (`publish()`) since the last time `notify` was called.
*/
notify(): void;
/**
* Publish new information (e.g. from the network) to the store, updating its
* internal record source. Subscribers are not immediately notified - this
* occurs when `notify()` is called.
*/
publish(source: RecordSource): void;
/**
* Attempts to load all the records necessary to fulfill the selector into the
* target record source.
*/
resolve(
target: MutableRecordSource,
selector: Selector,
callback: AsyncLoadCallback
): void;
/**
* Ensure that all the records necessary to fulfill the given selector are
* retained in-memory. The records will not be eligible for garbage collection
* until the returned reference is disposed.
*/
retain(selector: Selector): Disposable;
/**
* Subscribe to changes to the results of a selector. The callback is called
* when `notify()` is called *and* records have been published that affect the
* selector results relative to the last `notify()`.
*/
subscribe(
snapshot: Snapshot,
callback: (snapshot: Snapshot) => void
): Disposable;
}
/**
* An interface for imperatively getting/setting properties of a `Record`. This interface
* is designed to allow the appearance of direct Record manipulation while
* allowing different implementations that may e.g. create a changeset of
* the modifications.
*/
declare export interface RecordProxy {
copyFieldsFrom(source: RecordProxy): void;
getDataID(): DataID;
getLinkedRecord(name: string, args?: ?Variables): ?RecordProxy;
getLinkedRecords(name: string, args?: ?Variables): ?Array<?RecordProxy>;
getOrCreateLinkedRecord(
name: string,
typeName: string,
args?: ?Variables
): RecordProxy;
getType(): string;
getValue(name: string, args?: ?Variables): mixed;
setLinkedRecord(
record: RecordProxy,
name: string,
args?: ?Variables
): RecordProxy;
setLinkedRecords(
records: Array<?RecordProxy>,
name: string,
args?: ?Variables
): RecordProxy;
setValue(value: mixed, name: string, args?: ?Variables): RecordProxy;
}
/**
* An interface for imperatively getting/setting properties of a `RecordSource`. This interface
* is designed to allow the appearance of direct RecordSource manipulation while
* allowing different implementations that may e.g. create a changeset of
* the modifications.
*/
declare export interface RecordSourceProxy
extends IRecordSource<RecordProxy> {
create(dataID: DataID, typeName: string): RecordProxy;
delete(dataID: DataID): void;
get(dataID: DataID): ?RecordProxy;
getRoot(): RecordProxy;
}
/**
* Extends the RecordSourceProxy interface with methods for accessing the root
* fields of a Selector.
*/
declare export interface RecordSourceSelectorProxy
extends IRecordSource<RecordProxy> {
create(dataID: DataID, typeName: string): RecordProxy;
delete(dataID: DataID): void;
get(dataID: DataID): ?RecordProxy;
getRoot(): RecordProxy;
getRootField(fieldName: string): ?RecordProxy;
getPluralRootField(fieldName: string): ?Array<?RecordProxy>;
getResponse(): ?Object;
}
declare export interface IRecordReader<TRecord> {
getDataID(record: TRecord): DataID;
getType(record: TRecord): string;
getValue(record: TRecord, name: string, args?: ?Variables): mixed;
getLinkedRecordID(
record: TRecord,
name: string,
args?: ?Variables
): ?DataID;
getLinkedRecordIDs(
record: TRecord,
name: string,
args?: ?Variables
): ?Array<?DataID>;
}
/**
* Settings for how a query response may be cached.
*
* - `force`: causes a query to be issued unconditionally, irrespective of the
* state of any configured response cache.
* - `poll`: causes a query to live update by polling at the specified interval
in milliseconds. (This value will be passed to setTimeout.)
*/
declare export type CacheConfig = {
force?: ?boolean,
poll?: ?number
};
/**
* Represents any resource that must be explicitly disposed of. The most common
* use-case is as a return value for subscriptions, where calling `dispose()`
* would cancel the subscription.
*/
declare export type Disposable = {
dispose(): void
};
/**
* Arbitrary data e.g. received by a container as props.
*/
declare export type Props = {[key: string]: mixed};
/*
* An individual cached graph object.
*/
declare export type Record = {[key: string]: mixed};
/**
* A collection of records keyed by id.
*/
declare export type RecordMap<T> = {[dataID: DataID]: ?T};
/**
* A selector defines the starting point for a traversal into the graph for the
* purposes of targeting a subgraph.
*/
declare export type CSelector<TNode> = {
dataID: DataID,
node: TNode,
variables: Variables
};
/**
* A representation of a selector and its results at a particular point in time.
*/
declare export type CSnapshot<TNode, TRecord> = CSelector<TNode> & {
data: ?SelectorData,
seenRecords: RecordMap<TRecord>
};
/**
* The results of a selector given a store/RecordSource.
*/
declare export type SelectorData = {[key: string]: mixed};
/**
* The results of reading the results of a FragmentMap given some input
* `Props`.
*/
declare export type FragmentSpecResults = {[key: string]: mixed};
/**
* A utility for resolving and subscribing to the results of a fragment spec
* (key -> fragment mapping) given some "props" that determine the root ID
* and variables to use when reading each fragment. When props are changed via
* `setProps()`, the resolver will update its results and subscriptions
* accordingly. Internally, the resolver:
* - Converts the fragment map & props map into a map of `Selector`s.
* - Removes any resolvers for any props that became null.
* - Creates resolvers for any props that became non-null.
* - Updates resolvers with the latest props.
*/
declare export interface FragmentSpecResolver {
/**
* Stop watching for changes to the results of the fragments.
*/
dispose(): void;
/**
* Get the current results.
*/
resolve(): FragmentSpecResults;
/**
* Update the resolver with new inputs. Call `resolve()` to get the updated
* results.
*/
setProps(props: Props): void;
/**
* Override the variables used to read the results of the fragments. Call
* `resolve()` to get the updated results.
*/
setVariables(variables: Variables): void;
}
declare export type CFragmentMap<TFragment> = {[key: string]: TFragment};
/**
* An operation selector describes a specific instance of a GraphQL operation
* with variables applied.
*
* - `root`: a selector intended for processing server results or retaining
* response data in the store.
* - `fragment`: a selector intended for use in reading or subscribing to
* the results of the the operation.
*/
declare export type COperationSelector<TNode, TOperation> = {
fragment: CSelector<TNode>,
node: TOperation,
root: CSelector<TNode>,
variables: Variables
};
/**
* The public API of Relay core. Represents an encapsulated environment with its
* own in-memory cache.
*/
declare export interface CEnvironment<
TEnvironment,
TFragment,
TGraphQLTaggedNode,
TNode,
TOperation,
TPayload
> {
/**
* Read the results of a selector from in-memory records in the store.
*/
lookup(selector: CSelector<TNode>): CSnapshot<TNode>;
/**
* Subscribe to changes to the results of a selector. The callback is called
* when data has been committed to the store that would cause the results of
* the snapshot's selector to change.
*/
subscribe(
snapshot: CSnapshot<TNode>,
callback: (snapshot: CSnapshot<TNode>) => void
): Disposable;
/**
* Ensure that all the records necessary to fulfill the given selector are
* retained in-memory. The records will not be eligible for garbage collection
* until the returned reference is disposed.
*
* Note: This is a no-op in the classic core.
*/
retain(selector: CSelector<TNode>): Disposable;
/**
* Send a query to the server with request/response semantics: the query will
* either complete successfully (calling `onNext` and `onCompleted`) or fail
* (calling `onError`).
*
* Note: Most applications should use `streamQuery` in order to
* optionally receive updated information over time, should that feature be
* supported by the network/server. A good rule of thumb is to use this method
* if you would otherwise immediately dispose the `streamQuery()`
* after receving the first `onNext` result.
*/
sendQuery(config: {|
cacheConfig?: ?CacheConfig,
onCompleted?: ?() => void,
onError?: ?(error: Error) => void,
onNext?: ?(payload: TPayload) => void,
operation: COperationSelector<TNode, TOperation>
|}): Disposable;
/**
* Send a query to the server with request/subscription semantics: one or more
* responses may be returned (via `onNext`) over time followed by either
* the request completing (`onCompleted`) or an error (`onError`).
*
* Networks/servers that support subscriptions may choose to hold the
* subscription open indefinitely such that `onCompleted` is not called.
*/
streamQuery(config: {|
cacheConfig?: ?CacheConfig,
onCompleted?: ?() => void,
onError?: ?(error: Error) => void,
onNext?: ?(payload: TPayload) => void,
operation: COperationSelector<TNode, TOperation>
|}): Disposable;
unstable_internal: CUnstableEnvironmentCore<
TEnvironment,
TFragment,
TGraphQLTaggedNode,
TNode,
TOperation
>;
}
declare export interface CUnstableEnvironmentCore<
TEnvironment,
TFragment,
TGraphQLTaggedNode,
TNode,
TOperation
> {
/**
* Create an instance of a FragmentSpecResolver.
*
* TODO: The FragmentSpecResolver *can* be implemented via the other methods
* defined here, so this could be moved out of core. It's convenient to have
* separate implementations until the experimental core is in OSS.
*/
createFragmentSpecResolver: (
context: CRelayContext<TEnvironment>,
containerName: string,
fragments: CFragmentMap<TFragment>,
props: Props,
callback: () => void
) => FragmentSpecResolver;
/**
* Creates an instance of an OperationSelector given an operation definition
* (see `getOperation`) and the variables to apply. The input variables are
* filtered to exclude variables that do not matche defined arguments on the
* operation, and default values are populated for null values.
*/
createOperationSelector: (
operation: TOperation,
variables: Variables
) => COperationSelector<TNode, TOperation>;
/**
* Given a graphql`...` tagged template, extract a fragment definition usable
* by this version of Relay core. Throws if the value is not a fragment.
*/
getFragment: (node: TGraphQLTaggedNode) => TFragment;
/**
* Given a graphql`...` tagged template, extract an operation definition
* usable by this version of Relay core. Throws if the value is not an
* operation.
*/
getOperation: (node: TGraphQLTaggedNode) => TOperation;
/**
* Determine if two selectors are equal (represent the same selection). Note
* that this function returns `false` when the two queries/fragments are
* different objects, even if they select the same fields.
*/
areEqualSelectors: (a: CSelector<TNode>, b: CSelector<TNode>) => boolean;
/**
* Given the result `item` from a parent that fetched `fragment`, creates a
* selector that can be used to read the results of that fragment for that item.
*
* Example:
*
* Given two fragments as follows:
*
* ```
* fragment Parent on User {
* id
* ...Child
* }
* fragment Child on User {
* name
* }
* ```
*
* And given some object `parent` that is the results of `Parent` for id "4",
* the results of `Child` can be accessed by first getting a selector and then
* using that selector to `lookup()` the results against the environment:
*
* ```
* const childSelector = getSelector(queryVariables, Child, parent);
* const childData = environment.lookup(childSelector).data;
* ```
*/
getSelector: (
operationVariables: Variables,
fragment: TFragment,
prop: mixed
) => ?CSelector<TNode>;
/**
* Given the result `items` from a parent that fetched `fragment`, creates a
* selector that can be used to read the results of that fragment on those
* items. This is similar to `getSelector` but for "plural" fragments that
* expect an array of results and therefore return an array of selectors.
*/
getSelectorList: (
operationVariables: Variables,
fragment: TFragment,
props: Array<mixed>
) => ?Array<CSelector<TNode>>;
/**
* Given a mapping of keys -> results and a mapping of keys -> fragments,
* extracts the selectors for those fragments from the results.
*
* The canonical use-case for this function are Relay Containers, which
* use this function to convert (props, fragments) into selectors so that they
* can read the results to pass to the inner component.
*/
getSelectorsFromObject: (
operationVariables: Variables,
fragments: CFragmentMap<TFragment>,
props: Props
) => {[key: string]: ?(CSelector<TNode> | Array<CSelector<TNode>>)};
/**
* Given a mapping of keys -> results and a mapping of keys -> fragments,
* extracts a mapping of keys -> id(s) of the results.
*
* Similar to `getSelectorsFromObject()`, this function can be useful in
* determining the "identity" of the props passed to a component.
*/
getDataIDsFromObject: (
fragments: CFragmentMap<TFragment>,
props: Props
) => {[key: string]: ?(DataID | Array<DataID>)};
/**
* Given a mapping of keys -> results and a mapping of keys -> fragments,
* extracts the merged variables that would be in scope for those
* fragments/results.
*
* This can be useful in determing what varaibles were used to fetch the data
* for a Relay container, for example.
*/
getVariablesFromObject: (
operationVariables: Variables,
fragments: CFragmentMap<TFragment>,
props: Props
) => Variables;
}
/**
* The type of the `relay` property set on React context by the React/Relay
* integration layer (e.g. QueryRenderer, FragmentContainer, etc).
*/
declare export type CRelayContext<TEnvironment> = {
environment: TEnvironment,
variables: Variables
};
/**
* The public API of Relay core. Represents an encapsulated environment with its
* own in-memory cache.
*/
declare export interface Environment
extends CEnvironment<
TEnvironment,
TFragment,
TGraphQLTaggedNode,
TNode,
TOperation,
TPayload
> {
/**
* Applies an optimistic mutation to the store without committing it to the
* server. The returned Disposable can be used to revert this change at a
* later time.
*/
applyMutation(config: {|
configs: Array<RelayMutationConfig>,
operation: ConcreteOperationDefinition,
optimisticResponse: Object,
variables: Variables
|}): Disposable;
/**
* Applies an optimistic mutation if provided and commits the mutation to the
* server. The returned Disposable can be used to bypass the `onCompleted`
* and `onError` callbacks when the server response is returned.
*/
sendMutation<ResponseType>(config: {|
configs: Array<RelayMutationConfig>,
onCompleted?: ?(response: ResponseType) => void,
onError?: ?(error: Error) => void,
operation: ConcreteOperationDefinition,
optimisticOperation?: ?ConcreteOperationDefinition,
optimisticResponse?: ?Object,
variables: Variables,
uploadables?: UploadableMap
|}): Disposable;
}
declare export type Observer<T> = {
onCompleted?: ?() => void,
onError?: ?(error: Error) => void,
onNext?: ?(data: T) => void
};
/**
* The results of reading data for a fragment. This is similar to a `Selector`,
* but references the (fragment) node by name rather than by value.
*/
declare export type FragmentPointer = {
__id: DataID,
__fragments: {[fragmentName: string]: Variables}
};
/**
* A callback for resolving a Selector from a source.
*/
declare export type AsyncLoadCallback = (loadingState: LoadingState) => void;
declare export type LoadingState = $Exact<{
status: "aborted" | "complete" | "error" | "missing",
error?: Error
}>;
/**
* A map of records affected by an update operation.
*/
declare export type UpdatedRecords = {[dataID: DataID]: boolean};
/**
* A function that updates a store (via a proxy) given the results of a "handle"
* field payload.
*/
declare export type Handler = {
update: (store: RecordSourceProxy, fieldPayload: HandleFieldPayload) => void
};
/**
* A payload that is used to initialize or update a "handle" field with
* information from the server.
*/
declare export type HandleFieldPayload = $Exact<{
// The arguments that were fetched.
args: Variables,
// The __id of the record containing the source/handle field.
dataID: DataID,
// The (storage) key at which the original server data was written.
fieldKey: string,
// The name of the handle.
handle: string,
// The (storage) key at which the handle's data should be written by the
// handler.
handleKey: string
}>;
/**
* A function that receives a proxy over the store and may trigger side-effects
* (indirectly) by calling `set*` methods on the store or its record proxies.
*/
declare export type StoreUpdater = (store: RecordSourceProxy) => void;
/**
* Similar to StoreUpdater, but accepts a proxy tied to a specific selector in
* order to easily access the root fields of a query/mutation.
*/
declare export type SelectorStoreUpdater = (
store: RecordSourceSelectorProxy
) => void;
declare export type CallValue = ?(
| boolean
| number
| string
| {[key: string]: CallValue}
| Array<CallValue>);
declare export type RangeBehaviorsFunction = (connectionArgs: {