@@ -52,6 +52,10 @@ export interface NetworkInterface {
5252 [ others : string ] : any ;
5353 query ( request : Request ) : Promise < GraphQLResult > ;
5454}
55+ export interface SubscriptionNetworkInterface extends NetworkInterface {
56+ subscribe ( request : Request , handler : ( error , result ) => void ) : number ;
57+ unsubscribe ( id : Number ) : void ;
58+ }
5559export interface BatchedNetworkInterface extends NetworkInterface {
5660 batchQuery ( requests : Request [ ] ) : Promise < GraphQLResult [ ] > ;
5761}
@@ -389,6 +393,14 @@ import { Observer, Subscription } from '~apollo-client/util/Observable';
389393import { WatchQueryOptions } from '~apollo-client/watchQueryOptions' ;
390394import { ObservableQuery } from '~apollo-client/ObservableQuery' ;
391395export type QueryListener = ( queryStoreValue : QueryStoreValue ) => void ;
396+ export interface SubscriptionOptions {
397+ query : Document ;
398+ variables ?: {
399+ [ key : string ] : any ;
400+ } ;
401+ fragments ?: FragmentDefinition [ ] ;
402+ handler : ( error : Object , result : Object ) => void ;
403+ }
392404export class QueryManager {
393405 pollingTimers : {
394406 [ queryId : string ] : NodeJS . Timer | any ;
@@ -441,6 +453,7 @@ export class QueryManager {
441453 removeObservableQuery ( queryId : string ) : void ;
442454 resetStore ( ) : void ;
443455 startQuery ( queryId : string , options : WatchQueryOptions , listener : QueryListener ) : string ;
456+ startSubscription ( options : SubscriptionOptions ) : number ;
444457 stopQuery ( queryId : string ) : void ;
445458 getQueryWithPreviousResult ( queryId : string , isOptimistic ?: boolean ) : {
446459 previousResult : Object ;
@@ -451,7 +464,10 @@ export class QueryManager {
451464 queryFragments : FragmentDefinition [ ] ;
452465 } ;
453466 private collectResultBehaviorsFromUpdateQueries ( updateQueries , mutationResult , isOptimistic ?) ;
454- private fetchQueryOverInterface ( queryId , options , network ) ;
467+ private transformQueryDocument ( options ) ;
468+ private handleDiffQuery ( { queryDef, rootId, variables, fragmentMap, noFetch} ) ;
469+ private fetchRequest ( { requestId, queryId, query, querySS, options, fragmentMap, networkInterface} ) ;
470+ private fetchQueryOverInterface ( queryId , options , networkInterface ) ;
455471 private refetchQueryByName ( queryName ) ;
456472 private isDifferentResult ( queryId , result ) ;
457473 private broadcastQueries ( ) ;
@@ -465,7 +481,7 @@ export * from '~apollo-client/QueryManager';
465481// Generated by typings
466482// Source: node_modules/apollo-client/ObservableQuery.d.ts
467483declare module '~apollo-client/ObservableQuery' {
468- import { WatchQueryOptions , FetchMoreQueryOptions } from '~apollo-client/watchQueryOptions' ;
484+ import { WatchQueryOptions , FetchMoreQueryOptions , GraphQLSubscriptionOptions } from '~apollo-client/watchQueryOptions' ;
469485import { Observable } from '~apollo-client/util/Observable' ;
470486import { QueryScheduler } from '~apollo-client/scheduler' ;
471487import { ApolloQueryResult } from '~apollo-client/index' ;
@@ -475,9 +491,14 @@ export interface FetchMoreOptions {
475491 queryVariables : Object ;
476492 } ) => Object ;
477493}
494+ export interface UpdateQueryOptions {
495+ queryVariables : Object ;
496+ }
478497export class ObservableQuery extends Observable < ApolloQueryResult > {
479498 refetch : ( variables ?: any ) => Promise < ApolloQueryResult > ;
480499 fetchMore : ( options : FetchMoreQueryOptions & FetchMoreOptions ) => Promise < any > ;
500+ startGraphQLSubscription : ( options : GraphQLSubscriptionOptions ) => number ;
501+ updateQuery : ( mapFn : ( previousQueryResult : any , options : UpdateQueryOptions ) => any ) => void ;
481502 stopPolling : ( ) => void ;
482503 startPolling : ( p : number ) => void ;
483504 options : WatchQueryOptions ;
@@ -517,6 +538,17 @@ export interface FetchMoreQueryOptions {
517538 [ key : string ] : any ;
518539 } ;
519540}
541+ export interface GraphQLSubscriptionOptions {
542+ subscription : Document ;
543+ variables ?: {
544+ [ key : string ] : any ;
545+ } ;
546+ fragments ?: FragmentDefinition [ ] ;
547+ updateQuery : ( previousQueryResult : Object , options : {
548+ subscriptionResult : Object ;
549+ queryVariables : Object ;
550+ } ) => Object ;
551+ }
520552}
521553declare module 'apollo-client/watchQueryOptions' {
522554export * from '~apollo-client/watchQueryOptions' ;
@@ -722,7 +754,7 @@ export * from '~apollo-client/data/mutationResults';
722754// Source: node_modules/apollo-client/index.d.ts
723755declare module '~apollo-client/index' {
724756import { NetworkInterface , createNetworkInterface , addQueryMerging } from '~apollo-client/networkInterface' ;
725- import { Document , FragmentDefinition , SelectionSet } from 'graphql' ;
757+ import { Document , FragmentDefinition } from 'graphql' ;
726758import { print } from 'graphql-tag/printer' ;
727759import { createApolloStore , ApolloStore , createApolloReducer , ApolloReducerConfig } from '~apollo-client/store' ;
728760import { QueryManager } from '~apollo-client/QueryManager' ;
@@ -732,7 +764,7 @@ import { readQueryFromStore, readFragmentFromStore } from '~apollo-client/data/r
732764import { writeQueryToStore , writeFragmentToStore } from '~apollo-client/data/writeToStore' ;
733765import { IdGetter } from '~apollo-client/data/extensions' ;
734766import { QueryTransformer , addTypenameToSelectionSet } from '~apollo-client/queries/queryTransform' ;
735- import { MutationBehaviorReducerMap } from '~apollo-client/data/mutationResults' ;
767+ import { MutationBehavior , MutationBehaviorReducerMap , MutationQueryReducersMap } from '~apollo-client/data/mutationResults' ;
736768export { createNetworkInterface , addQueryMerging , createApolloStore , createApolloReducer , readQueryFromStore , readFragmentFromStore , addTypenameToSelectionSet as addTypename , writeQueryToStore , writeFragmentToStore , print as printAST } ;
737769export type ApolloQueryResult = {
738770 data : any ;
@@ -770,51 +802,21 @@ export default class ApolloClient {
770802 mutationBehaviorReducers ?: MutationBehaviorReducerMap ;
771803 batchInterval ?: number ;
772804 } ) ;
773- watchQuery : ( options : WatchQueryOptions ) => ObservableQuery ;
774- query : ( options : WatchQueryOptions ) => Promise < {
775- data : any ;
776- loading : boolean ;
777- } > ;
778- mutate : ( options : {
805+ watchQuery ( options : WatchQueryOptions ) : ObservableQuery ;
806+ query ( options : WatchQueryOptions ) : Promise < ApolloQueryResult > ;
807+ mutate ( options : {
779808 mutation : Document ;
780809 variables ?: Object ;
781- resultBehaviors ?: ( {
782- type : "ARRAY_INSERT" ;
783- resultPath : ( string | number ) [ ] ;
784- storePath : ( string | number ) [ ] ;
785- where : "PREPEND" | "APPEND" ;
786- } | {
787- type : "ARRAY_DELETE" ;
788- storePath : ( string | number ) [ ] ;
789- dataId : string ;
790- } | {
791- type : "DELETE" ;
792- dataId : string ;
793- } | {
794- type : "QUERY_RESULT" ;
795- queryVariables : any ;
796- querySelectionSet : SelectionSet ;
797- queryFragments : FragmentDefinition [ ] ;
798- newResult : Object ;
799- } ) [ ] ;
810+ resultBehaviors ?: MutationBehavior [ ] ;
800811 fragments ?: FragmentDefinition [ ] ;
801812 optimisticResponse ?: Object ;
802- updateQueries ?: {
803- [ queryName : string ] : ( previousResult : Object , options : {
804- mutationResult : Object ;
805- queryName : Object ;
806- queryVariables : Object ;
807- } ) => Object ;
808- } ;
813+ updateQueries ?: MutationQueryReducersMap ;
809814 refetchQueries ?: string [ ] ;
810- } ) => Promise < {
811- data : any ;
812- loading : boolean ;
813- } > ;
815+ } ) : Promise < ApolloQueryResult > ;
814816 reducer ( ) : Function ;
815817 middleware : ( ) => ( store : ApolloStore ) => ( next : any ) => ( action : any ) => any ;
816818 initStore ( ) : void ;
817- private setStore ;
819+ private setStore ( store ) ;
818820}
819821}
820822declare module 'apollo-client/index' {
0 commit comments