Skip to content

Commit

Permalink
Update types against GraphQL 0.8.2 and @types/graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
intellix committed Nov 18, 2016
1 parent ba0849b commit a1e60a8
Show file tree
Hide file tree
Showing 31 changed files with 245 additions and 246 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"whatwg-fetch": "^2.0.0"
},
"devDependencies": {
"@types/graphql": "^0.8.0",
"@types/chai": "^3.4.32",
"@types/chai-as-promised": "0.0.28",
"@types/mocha": "^2.2.31",
Expand All @@ -87,7 +88,6 @@
"sinon": "^1.17.4",
"source-map-support": "^0.4.0",
"tslint": "3.15.1",
"typed-graphql": "1.0.2",
"typescript": "2.0.10",
"uglify-js": "^2.6.2"
},
Expand Down
2 changes: 1 addition & 1 deletion src/ApolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
// though we don't use it. https://github.com/Microsoft/TypeScript/issues/5711
// We need to disable the linter here because TSLint rightfully complains that this is unused.
/* tslint:disable */
SelectionSet,
SelectionSetNode,
/* tslint:enable */

} from 'graphql';
Expand Down
24 changes: 12 additions & 12 deletions src/actions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
Document,
GraphQLResult,
DocumentNode,
ExecutionResult,
} from 'graphql';

import {
Expand All @@ -13,9 +13,9 @@ import {

export type QueryResultAction = {
type: 'APOLLO_QUERY_RESULT';
result: GraphQLResult;
result: ExecutionResult;
queryId: string;
document: Document;
document: DocumentNode;
operationName: string;
requestId: number;
extraReducers?: ApolloReducer[];
Expand All @@ -39,7 +39,7 @@ export function isQueryErrorAction(action: ApolloAction): action is QueryErrorAc
export interface QueryInitAction {
type: 'APOLLO_QUERY_INIT';
queryString: string;
document: Document;
document: DocumentNode;
variables: Object;
forceFetch: boolean;
returnPartialData: boolean;
Expand All @@ -56,7 +56,7 @@ export function isQueryInitAction(action: ApolloAction): action is QueryInitActi

export interface QueryResultClientAction {
type: 'APOLLO_QUERY_RESULT_CLIENT';
result: GraphQLResult;
result: ExecutionResult;
complete: boolean;
queryId: string;
}
Expand All @@ -77,7 +77,7 @@ export function isQueryStopAction(action: ApolloAction): action is QueryStopActi
export interface MutationInitAction {
type: 'APOLLO_MUTATION_INIT';
mutationString: string;
mutation: Document;
mutation: DocumentNode;
variables: Object;
operationName: string;
mutationId: string;
Expand All @@ -93,8 +93,8 @@ export function isMutationInitAction(action: ApolloAction): action is MutationIn
// TODO REFACOTR: simplify all these actions by providing a generic options field to all actions.
export interface MutationResultAction {
type: 'APOLLO_MUTATION_RESULT';
result: GraphQLResult;
document: Document;
result: ExecutionResult;
document: DocumentNode;
operationName: string;
// XXX maybe provide variables as well?
mutationId: string;
Expand All @@ -119,7 +119,7 @@ export function isMutationErrorAction(action: ApolloAction): action is MutationE
export interface UpdateQueryResultAction {
type: 'APOLLO_UPDATE_QUERY_RESULT';
variables: any;
document: Document;
document: DocumentNode;
newResult: Object;
}

Expand All @@ -138,10 +138,10 @@ export function isStoreResetAction(action: ApolloAction): action is StoreResetAc

export type SubscriptionResultAction = {
type: 'APOLLO_SUBSCRIPTION_RESULT';
result: GraphQLResult;
result: ExecutionResult;
subscriptionId: number;
variables: Object;
document: Document;
document: DocumentNode;
operationName: string;
extraReducers?: ApolloReducer[];
}
Expand Down
22 changes: 11 additions & 11 deletions src/core/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ import {
} from '../data/resultReducers';

import {
GraphQLResult,
Document,
ExecutionResult,
DocumentNode,
// TODO REFACTOR: do we still need this??
// We need to import this here to allow TypeScript to include it in the definition file even
// though we don't use it. https://github.com/Microsoft/TypeScript/issues/5711
// We need to disable the linter here because TSLint rightfully complains that this is unused.
/* tslint:disable */
SelectionSet,
SelectionSetNode,
/* tslint:enable */
} from 'graphql';

Expand Down Expand Up @@ -95,7 +95,7 @@ import { ObservableQuery } from './ObservableQuery';
export type QueryListener = (queryStoreValue: QueryStoreValue) => void;

export interface SubscriptionOptions {
document: Document;
document: DocumentNode;
variables?: { [key: string]: any };
};

Expand All @@ -104,7 +104,7 @@ export type ApolloQueryResult = {
loading: boolean;
networkStatus: NetworkStatus;

// This type is different from the GraphQLResult type because it doesn't include errors.
// This type is different from the ExecutionResult type because it doesn't include errors.
// Those are thrown via the standard promise/observer catch mechanism.
}

Expand Down Expand Up @@ -146,7 +146,7 @@ export class QueryManager {
// this should be combined with ObservableQuery, but that needs to be expanded to support
// mutations and subscriptions as well.
private queryListeners: { [queryId: string]: QueryListener[] };
private queryDocuments: { [queryId: string]: Document };
private queryDocuments: { [queryId: string]: DocumentNode };

private idCounter = 0;

Expand Down Expand Up @@ -238,7 +238,7 @@ export class QueryManager {
updateQueries,
refetchQueries = [],
}: {
mutation: Document,
mutation: DocumentNode,
variables?: Object,
resultBehaviors?: MutationBehavior[],
optimisticResponse?: Object,
Expand Down Expand Up @@ -860,7 +860,7 @@ export class QueryManager {
// Takes a set of WatchQueryOptions and transforms the query document
// accordingly. Specifically, it applies the queryTransformer (if there is one defined)
private transformQueryDocument(options: WatchQueryOptions): {
queryDoc: Document,
queryDoc: DocumentNode,
} {
let queryDoc = options.query;

Expand Down Expand Up @@ -900,9 +900,9 @@ export class QueryManager {
}: {
requestId: number,
queryId: string,
document: Document,
document: DocumentNode,
options: WatchQueryOptions,
}): Promise<GraphQLResult> {
}): Promise<ExecutionResult> {
const {
variables,
noFetch,
Expand All @@ -918,7 +918,7 @@ export class QueryManager {
this.addFetchQueryPromise(requestId, retPromise, resolve, reject);

this.networkInterface.query(request)
.then((result: GraphQLResult) => {
.then((result: ExecutionResult) => {

const extraReducers = this.getExtraReducers();

Expand Down
24 changes: 12 additions & 12 deletions src/core/watchQueryOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
Document,
FragmentDefinition,
DocumentNode,
FragmentDefinitionNode,
} from 'graphql';

import {
Expand Down Expand Up @@ -64,7 +64,7 @@ export interface WatchQueryOptions extends ModifiableWatchQueryOptions {
* server.
*/
// TODO REFACTOR: rename this to document. Didn't do it yet because it's in a lot of tests.
query: Document;
query: DocumentNode;
}

// This interface is deprecated because we no longer pass around fragments separately in the core.
Expand All @@ -73,23 +73,23 @@ export interface DeprecatedWatchQueryOptions extends ModifiableWatchQueryOptions
* A GraphQL document that consists of a single query to be sent down to the
* server.
*/
query: Document;
query: DocumentNode;

/**
* A list of fragments that are returned by {@link createFragment} which can be
* referenced from the query document.
*/
fragments?: FragmentDefinition[];
fragments?: FragmentDefinitionNode[];
}

export interface FetchMoreQueryOptions {
query?: Document;
query?: DocumentNode;
variables?: { [key: string]: any };
fragments?: FragmentDefinition[];
fragments?: FragmentDefinitionNode[];
}

export type SubscribeToMoreOptions = {
document: Document;
document: DocumentNode;
variables?: { [key: string]: any };
updateQuery: (previousQueryResult: Object, options: {
subscriptionData: { data: any },
Expand All @@ -99,16 +99,16 @@ export type SubscribeToMoreOptions = {
}

export interface DeprecatedSubscriptionOptions {
query: Document;
query: DocumentNode;
variables?: { [key: string]: any };
fragments?: FragmentDefinition[];
fragments?: FragmentDefinitionNode[];
};

export interface MutationOptions {
mutation: Document;
mutation: DocumentNode;
variables?: Object;
resultBehaviors?: MutationBehavior[];
fragments?: FragmentDefinition[];
fragments?: FragmentDefinitionNode[];
optimisticResponse?: Object;
updateQueries?: MutationQueryReducersMap;
refetchQueries?: string[];
Expand Down
10 changes: 5 additions & 5 deletions src/data/mutationResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
} from './storeUtils';

import {
Document,
GraphQLResult,
DocumentNode,
ExecutionResult,
} from 'graphql';

import mapValues = require('lodash.mapvalues');
Expand Down Expand Up @@ -67,7 +67,7 @@ export type MutationArrayDeleteBehavior = {
export type MutationQueryResultBehavior = {
type: 'QUERY_RESULT';
variables: any;
document: Document;
document: DocumentNode;
newResult: Object;
};

Expand All @@ -79,9 +79,9 @@ export type ArrayInsertWhere =
// The `behavior` field is specific to each reducer
export type MutationBehaviorReducerArgs = {
behavior: MutationBehavior;
result: GraphQLResult;
result: ExecutionResult;
variables: any;
document: Document;
document: DocumentNode;
config: ApolloReducerConfig;
}

Expand Down
6 changes: 3 additions & 3 deletions src/data/readFromStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
Document,
DocumentNode,
} from 'graphql';

import graphqlAnywhere, {
Expand Down Expand Up @@ -33,7 +33,7 @@ export type DiffResult = {

export type ReadQueryOptions = {
store: NormalizedCache,
query: Document,
query: DocumentNode,
variables?: Object,
returnPartialData?: boolean,
config?: ApolloReducerConfig,
Expand Down Expand Up @@ -181,7 +181,7 @@ Perhaps you want to use the \`returnPartialData\` option?`);
/**
* Given a store and a query, return as much of the result as possible and
* identify if any data was missing from the store.
* @param {Document} query A parsed GraphQL query document
* @param {DocumentNode} query A parsed GraphQL query document
* @param {Store} store The Apollo Client store object
* @param {boolean} [returnPartialData] Whether to throw an error if any fields are missing
* @return {result: Object, isMissing: [boolean]}
Expand Down
4 changes: 2 additions & 2 deletions src/data/replaceQueryResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '../store';

import {
Document,
DocumentNode,
} from 'graphql';

import assign = require('lodash.assign');
Expand All @@ -22,7 +22,7 @@ export function replaceQueryResults(state: NormalizedCache, {
newResult,
}: {
variables: any;
document: Document;
document: DocumentNode;
newResult: Object;
}, config: ApolloReducerConfig) {
const clonedState = assign({}, state) as NormalizedCache;
Expand Down
4 changes: 2 additions & 2 deletions src/data/resultReducers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
Document,
DocumentNode,
} from 'graphql';

import {
Expand Down Expand Up @@ -34,7 +34,7 @@ import {
*/
export function createStoreReducer(
resultReducer: OperationResultReducer,
document: Document,
document: DocumentNode,
variables: Object,
config: ApolloReducerConfig,
// TODO: maybe turn the arguments into a single object argument
Expand Down
Loading

0 comments on commit a1e60a8

Please sign in to comment.