Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(521) >> find . -name '*.ts' | xargs ~/random/prettier/bin/prettier.js --parser typescript --debug-check
./benchmark/index.ts
./benchmark/util.ts
ast(input) !== ast(prettier(input))
Index:
===================================================================
---
+++
@@ -1599,27 +1599,26 @@
"operator": "||",
"left": {
- "type": "MemberExpression",
- "object": {
- "type": "TSAsExpression",
- "expression": {
- "type": "Identifier",
- "name": "description"
- },
+ "type": "TSAsExpression",
+ "expression": {
+ "type": "Identifier",
+ "name": "description"
+ },
+ "typeAnnotation": {
+ "type": "TypeAnnotation",
"typeAnnotation": {
- "type": "TypeAnnotation",
- "typeAnnotation": {
- "type": "TSTypeReference",
- "typeName": {
- "type": "Identifier",
+ "type": "TSTypeReference",
+ "typeName": {
+ "type": "JSXMemberExpression",
+ "object": {
+ "type": "JSXIdentifier",
"name": "DescriptionObject"
+ },
+ "property": {
+ "type": "JSXIdentifier",
+ "name": "name"
}
}
}
- },
- "property": {
- "type": "Identifier",
- "name": "name"
- },
- "computed": false
+ }
},
"right": {
Index:
===================================================================
---
+++
@@ -1,9 +1,5 @@
-import * as Benchmark from 'benchmark';
+import * as Benchmark from "benchmark";
-import {
- times,
- cloneDeep,
- merge,
-} from 'lodash';
+import { times, cloneDeep, merge } from "lodash";
// This file implements utilities around benchmark.js that make it
@@ -23,6 +19,6 @@
export interface DescriptionObject {
- name: string;
- [other: string]: any;
+ name: string,
+ [other: string]: any
}
@@ -30,8 +26,16 @@
export type Description = DescriptionObject | string;
export type CycleFunction = (doneFn: DoneFunction) => void;
-export type BenchmarkFunction = (description: Description, cycleFn: CycleFunction) => void;
+export type BenchmarkFunction = (
+ description: Description,
+ cycleFn: CycleFunction
+) => void;
export type GroupFunction = (done: DoneFunction) => void;
-export type AfterEachCallbackFunction = (descr: Description, event: any) => void;
-export type AfterEachFunction = (afterEachFnArg: AfterEachCallbackFunction) => void;
+export type AfterEachCallbackFunction = (
+ descr: Description,
+ event: any
+) => void;
+export type AfterEachFunction = (
+ afterEachFnArg: AfterEachCallbackFunction
+) => void;
export type AfterAllCallbackFunction = () => void;
export type AfterAllFunction = (afterAllFn: AfterAllCallbackFunction) => void;
@@ -51,5 +55,5 @@
export const dataIdFromObject = (object: any) => {
if (object.__typename && object.id) {
- return object.__typename + '__' + object.id;
+ return object.__typename + "__" + object.id;
}
return null;
@@ -57,7 +61,7 @@
interface Scope {
- benchmark?: BenchmarkFunction;
- afterEach?: AfterEachFunction;
- afterAll?: AfterAllFunction;
+ benchmark?: BenchmarkFunction,
+ afterEach?: AfterEachFunction,
+ afterAll?: AfterAllFunction
}
@@ -68,5 +72,5 @@
benchmark,
afterEach,
- afterAll,
+ afterAll
};
}
@@ -87,5 +91,5 @@
benchmark?: BenchmarkFunction,
afterEach?: AfterEachFunction,
- afterAll?: AfterAllFunction,
+ afterAll?: AfterAllFunction
} = {};
@@ -102,61 +106,67 @@
const benchmarkPromises: Promise<void>[] = [];
- scope.benchmark = (description: string | Description, benchmarkFn: CycleFunction) => {
- const name = (description as DescriptionObject).name || (description as string);
- log('Adding benchmark: ', name);
+ scope.benchmark = (
+ description: string | Description,
+ benchmarkFn: CycleFunction
+ ) => {
+ const name = description as DescriptionObject.name || description as string;
+ log("Adding benchmark: ", name);
const scopes: Object[] = [];
let cycleCount = 0;
- benchmarkPromises.push(new Promise<void>((resolve, reject) => {
- bsuite.add(name, {
- defer: true,
- fn: (deferred: any) => {
- const done = () => {
- cycleCount++;
- deferred.resolve();
- };
+ benchmarkPromises.push(
+ new Promise<void>((resolve, reject) => {
+ bsuite.add(name, {
+ defer: true,
+ fn: (deferred: any) => {
+ const done = () => {
+ cycleCount++;
+ deferred.resolve();
+ };
- benchmarkFn(done);
- },
+ benchmarkFn(done);
+ },
- onComplete: (event: any) => {
- if (afterEachFn) {
- afterEachFn(description, event);
+ onComplete: (event: any) => {
+ if (afterEachFn) {
+ afterEachFn(description, event);
+ }
+ resolve();
}
- resolve();
- },
- });
- }));
+ });
+ })
+ );
};
+ groupPromises.push(
+ new Promise<void>((resolve, reject) => {
+ const groupDone = () => {
+ Promise.all(benchmarkPromises).then(() => {
+ if (afterAllFn) {
+ afterAllFn();
+ }
+ });
+ resolve();
+ };
- groupPromises.push(new Promise<void>((resolve, reject) => {
- const groupDone = () => {
- Promise.all(benchmarkPromises).then(() => {
- if (afterAllFn) {
- afterAllFn();
- }
- });
- resolve();
- };
-
- setScope(scope);
- groupFn(groupDone);
- setScope(oldScope);
- }));
+ setScope(scope);
+ groupFn(groupDone);
+ setScope(oldScope);
+ })
+ );
};
export function runBenchmarks() {
Promise.all(groupPromises).then(() => {
- log('Running benchmarks.');
+ log("Running benchmarks.");
bsuite
- .on('error', (error: any) => {
- log('Error: ', error);
+ .on("error", (error: any) => {
+ log("Error: ", error);
})
- .on('cycle', (event: any) => {
- log('Mean time in ms: ', event.target.stats.mean * 1000);
+ .on("cycle", (event: any) => {
+ log("Mean time in ms: ", event.target.stats.mean * 1000);
log(String(event.target));
})
- .run({'async': false});
+ .run({ async: false });
});
}
./fetch-mock.typings.d.ts
prettier(input) !== prettier(prettier(input))
Index:
===================================================================
---
+++
@@ -27,5 +27,5 @@
* an exact url to match e.g. 'http:www.site.com/page.html'
* if the string begins with a `^`, the string following the `^` must
- begin the url e.g. '^http://www.site.com' would match
+ begin the url e.g. '^http:www.site.com' would match
'http://www.site.com' or 'http://www.site.com/page.html'
* '*' to match any url
./src/actions.ts
./src/ApolloClient.ts
./src/ApolloClient.ts: { index: 5568,
lineNumber: 196,
column: 38,
message: '\';\' expected.' }
./src/core/ObservableQuery.ts
./src/core/ObservableQuery.ts: { index: 3681,
lineNumber: 124,
column: 52,
message: '\';\' expected.' }
./src/core/QueryManager.ts
./src/core/QueryManager.ts: { index: 10288,
lineNumber: 349,
column: 36,
message: 'Identifier expected.' }
./src/core/types.ts
ast(input) !== ast(prettier(input))
Index:
===================================================================
---
+++
@@ -295,8 +295,4 @@
"type": "Identifier",
"name": "normal"
- },
- "initializer": {
- "type": "Literal",
- "value": 1
}
},
@@ -306,8 +302,4 @@
"type": "Identifier",
"name": "refetch"
- },
- "initializer": {
- "type": "Literal",
- "value": 2
}
},
@@ -317,8 +309,4 @@
"type": "Identifier",
"name": "poll"
- },
- "initializer": {
- "type": "Literal",
- "value": 3
}
}
Index:
===================================================================
---
+++
@@ -1,5 +1,5 @@
-import { DocumentNode } from 'graphql';
-import { QueryStoreValue } from '../queries/store';
-import { NetworkStatus } from '../queries/networkStatus';
+import { DocumentNode } from "graphql";
+import { QueryStoreValue } from "../queries/store";
+import { NetworkStatus } from "../queries/networkStatus";
export type QueryListener = (queryStoreValue: QueryStoreValue) => void;
@@ -7,12 +7,12 @@
export type PureQueryOptions = {
query: DocumentNode,
- variables?: { [key: string]: any};
+ variables?: { [key: string]: any }
};
export type ApolloQueryResult<T> = {
- data: T;
- loading: boolean;
- networkStatus: NetworkStatus;
- stale: boolean;
+ data: T,
+ loading: boolean,
+ networkStatus: NetworkStatus,
+ stale: boolean
// This type is different from the GraphQLResult type because it doesn't include errors.
@@ -20,9 +20,5 @@
};
-export enum FetchType {
- normal = 1,
- refetch = 2,
- poll = 3,
-}
+export enum FetchType { normal, refetch, poll }
export type IdGetter = (value: Object) => string | null | undefined;
./src/core/watchQueryOptions.ts
./src/data/debug.ts
./src/data/fragmentMatcher.ts
./src/data/fragmentMatcher.ts: Error: Comment location overlaps with node location
at decorateComment (/Users/vjeux/random/prettier/src/comments.js:115:11)
at decorateComment (/Users/vjeux/random/prettier/src/comments.js:91:7)
at decorateComment (/Users/vjeux/random/prettier/src/comments.js:91:7)
at decorateComment (/Users/vjeux/random/prettier/src/comments.js:91:7)
at decorateComment (/Users/vjeux/random/prettier/src/comments.js:91:7)
at decorateComment (/Users/vjeux/random/prettier/src/comments.js:91:7)
at decorateComment (/Users/vjeux/random/prettier/src/comments.js:91:7)
at decorateComment (/Users/vjeux/random/prettier/src/comments.js:91:7)
at comments.forEach (/Users/vjeux/random/prettier/src/comments.js:135:5)
at Array.forEach (native)
./src/data/fragmentMatcherIntrospectionQuery.ts
./src/data/mutationResults.ts
./src/data/proxy.ts
ast(input) !== ast(prettier(input))
Index:
===================================================================
---
+++
@@ -556,13 +556,4 @@
"name": "readQuery"
},
- "typeParameters": [
- {
- "type": "TSTypeParameter",
- "name": {
- "type": "Identifier",
- "name": "QueryType"
- }
- }
- ],
"parameters": [
{
@@ -598,13 +589,4 @@
"name": "readFragment"
},
- "typeParameters": [
- {
- "type": "TSTypeParameter",
- "name": {
- "type": "Identifier",
- "name": "FragmentType"
- }
- }
- ],
"parameters": [
{
Index:
===================================================================
---
+++
@@ -1,13 +1,13 @@
-import { DocumentNode } from 'graphql';
-import { ApolloStore, Store, ApolloReducerConfig } from '../store';
-import { DataWrite } from '../actions';
-import { IdGetter } from '../core/types';
-import { NormalizedCache } from '../data/storeUtils';
-import { getFragmentQueryDocument } from '../queries/getFromAST';
-import { getDataWithOptimisticResults } from '../optimistic-data/store';
-import { readQueryFromStore } from './readFromStore';
-import { writeResultToStore } from './writeToStore';
-import { FragmentMatcherInterface } from './fragmentMatcher';
-import { addTypenameToDocument } from '../queries/queryTransform';
+import { DocumentNode } from "graphql";
+import { ApolloStore, Store, ApolloReducerConfig } from "../store";
+import { DataWrite } from "../actions";
+import { IdGetter } from "../core/types";
+import { NormalizedCache } from "../data/storeUtils";
+import { getFragmentQueryDocument } from "../queries/getFromAST";
+import { getDataWithOptimisticResults } from "../optimistic-data/store";
+import { readQueryFromStore } from "./readFromStore";
+import { writeResultToStore } from "./writeToStore";
+import { FragmentMatcherInterface } from "./fragmentMatcher";
+import { addTypenameToDocument } from "../queries/queryTransform";
export interface DataProxyReadQueryOptions {
@@ -17,10 +17,10 @@
* shape of the data to be read.
*/
- query: DocumentNode;
+ query: DocumentNode,
/**
* Any variables that the GraphQL query may depend on.
*/
- variables?: Object;
+ variables?: Object
}
@@ -31,5 +31,5 @@
* id does not exist in the store, `null` will be returned.
*/
- id: string;
+ id: string,
/**
@@ -39,5 +39,5 @@
* document then you must also specify `fragmentName` to select a single.
*/
- fragment: DocumentNode;
+ fragment: DocumentNode,
/**
@@ -46,10 +46,10 @@
* `fragment` document then that fragment will be used.
*/
- fragmentName?: string;
+ fragmentName?: string,
/**
* Any variables that your GraphQL fragments depend on.
*/
- variables?: Object;
+ variables?: Object
}
@@ -58,5 +58,5 @@
* The data you will be writing to the store.
*/
- data: any;
+ data: any,
/**
@@ -65,10 +65,10 @@
* shape of the data to be written.
*/
- query: DocumentNode;
+ query: DocumentNode,
/**
* Any variables that the GraphQL query may depend on.
*/
- variables?: Object;
+ variables?: Object
}
@@ -77,5 +77,5 @@
* The data you will be writing to the store.
*/
- data: any;
+ data: any,
/**
@@ -83,5 +83,5 @@
* returned by your `dataIdFromObject` function.
*/
- id: string;
+ id: string,
/**
@@ -91,5 +91,5 @@
* document then you must also specify `fragmentName` to select a single.
*/
- fragment: DocumentNode;
+ fragment: DocumentNode,
/**
@@ -98,10 +98,10 @@
* `fragment` document then that fragment will be used.
*/
- fragmentName?: string;
+ fragmentName?: string,
/**
* Any variables that your GraphQL fragments depend on.
*/
- variables?: Object;
+ variables?: Object
}
@@ -116,5 +116,5 @@
* Reads a GraphQL query from the root query id.
*/
- readQuery<QueryType>(options: DataProxyReadQueryOptions): QueryType;
+ readQuery(options: DataProxyReadQueryOptions): QueryType,
/**
@@ -123,10 +123,10 @@
* provided to select the correct fragment.
*/
- readFragment<FragmentType>(options: DataProxyReadFragmentOptions): FragmentType | null;
+ readFragment(options: DataProxyReadFragmentOptions): FragmentType | null,
/**
* Writes a GraphQL query to the root query id.
*/
- writeQuery(options: DataProxyWriteQueryOptions): void;
+ writeQuery(options: DataProxyWriteQueryOptions): void,
/**
@@ -135,5 +135,5 @@
* provided to select the correct fragment.
*/
- writeFragment(options: DataProxyWriteFragmentOptions): void;
+ writeFragment(options: DataProxyWriteFragmentOptions): void
}
@@ -165,5 +165,5 @@
reduxRootSelector: (state: any) => Store,
fragmentMatcher: FragmentMatcherInterface,
- reducerConfig: ApolloReducerConfig,
+ reducerConfig: ApolloReducerConfig
) {
this.store = store;
@@ -178,7 +178,6 @@
public readQuery<QueryType>({
query,
- variables,
+ variables
}: DataProxyReadQueryOptions): QueryType {
-
if (this.reducerConfig.addTypename) {
query = addTypenameToDocument(query);
@@ -186,10 +185,12 @@
return readQueryFromStore<QueryType>({
- rootId: 'ROOT_QUERY',
- store: getDataWithOptimisticResults(this.reduxRootSelector(this.store.getState())),
+ rootId: "ROOT_QUERY",
+ store: getDataWithOptimisticResults(
+ this.reduxRootSelector(this.store.getState())
+ ),
query,
variables,
fragmentMatcherFunction: this.fragmentMatcher.match,
- config: this.reducerConfig,
+ config: this.reducerConfig
});
}
@@ -202,12 +203,14 @@
fragment,
fragmentName,
- variables,
+ variables
}: DataProxyReadFragmentOptions): FragmentType | null {
let query = getFragmentQueryDocument(fragment, fragmentName);
- const data = getDataWithOptimisticResults(this.reduxRootSelector(this.store.getState()));
+ const data = getDataWithOptimisticResults(
+ this.reduxRootSelector(this.store.getState())
+ );
// If we could not find an item in the store with the provided id then we
// just return `null`.
- if (typeof data[id] === 'undefined') {
+ if (typeof data[id] === "undefined") {
return null;
}
@@ -223,5 +226,5 @@
variables,
fragmentMatcherFunction: this.fragmentMatcher.match,
- config: this.reducerConfig,
+ config: this.reducerConfig
});
}
@@ -233,7 +236,6 @@
data,
query,
- variables,
+ variables
}: DataProxyWriteQueryOptions): void {
-
if (this.reducerConfig.addTypename) {
query = addTypenameToDocument(query);
@@ -241,11 +243,13 @@
this.store.dispatch({
- type: 'APOLLO_WRITE',
- writes: [{
- rootId: 'ROOT_QUERY',
- result: data,
- document: query,
- variables: variables || {},
- }],
+ type: "APOLLO_WRITE",
+ writes: [
+ {
+ rootId: "ROOT_QUERY",
+ result: data,
+ document: query,
+ variables: variables || {}
+ }
+ ]
});
}
@@ -259,7 +263,6 @@
fragment,
fragmentName,
- variables,
+ variables
}: DataProxyWriteFragmentOptions): void {
-
let document = getFragmentQueryDocument(fragment, fragmentName);
@@ -269,11 +272,13 @@
this.store.dispatch({
- type: 'APOLLO_WRITE',
- writes: [{
- rootId: id,
- result: data,
- document,
- variables: variables || {},
- }],
+ type: "APOLLO_WRITE",
+ writes: [
+ {
+ rootId: id,
+ result: data,
+ document,
+ variables: variables || {}
+ }
+ ]
});
}
@@ -336,9 +341,8 @@
public readQuery<QueryType>({
query,
- variables,
+ variables
}: DataProxyReadQueryOptions): QueryType {
this.assertNotFinished();
-
if (this.reducerConfig.addTypename) {
query = addTypenameToDocument(query);
@@ -346,10 +350,10 @@
return readQueryFromStore<QueryType>({
- rootId: 'ROOT_QUERY',
+ rootId: "ROOT_QUERY",
store: this.data,
query,
variables,
config: this.reducerConfig,
- fragmentMatcherFunction: this.reducerConfig.fragmentMatcher,
+ fragmentMatcherFunction: this.reducerConfig.fragmentMatcher
});
}
@@ -364,5 +368,5 @@
fragment,
fragmentName,
- variables,
+ variables
}: DataProxyReadFragmentOptions): FragmentType | null {
this.assertNotFinished();
@@ -376,5 +380,5 @@
// If we could not find an item in the store with the provided id then we
// just return `null`.
- if (typeof data[id] === 'undefined') {
+ if (typeof data[id] === "undefined") {
return null;
}
@@ -386,5 +390,5 @@
variables,
config: this.reducerConfig,
- fragmentMatcherFunction: this.reducerConfig.fragmentMatcher,
+ fragmentMatcherFunction: this.reducerConfig.fragmentMatcher
});
}
@@ -398,5 +402,5 @@
data,
query,
- variables,
+ variables
}: DataProxyWriteQueryOptions): void {
this.assertNotFinished();
@@ -407,8 +411,8 @@
this.applyWrite({
- rootId: 'ROOT_QUERY',
+ rootId: "ROOT_QUERY",
result: data,
document: query,
- variables: variables || {},
+ variables: variables || {}
});
}
@@ -424,5 +428,5 @@
fragment,
fragmentName,
- variables,
+ variables
}: DataProxyWriteFragmentOptions): void {
this.assertNotFinished();
@@ -438,5 +442,5 @@
result: data,
document: query,
- variables: variables || {},
+ variables: variables || {}
});
}
@@ -448,5 +452,7 @@
private assertNotFinished() {
if (this.isFinished) {
- throw new Error('Cannot call transaction methods after the transaction has finished.');
+ throw new Error(
+ "Cannot call transaction methods after the transaction has finished."
+ );
}
}
@@ -464,5 +470,5 @@
store: this.data,
dataIdFromObject: this.reducerConfig.dataIdFromObject || (() => null),
- fragmentMatcherFunction: this.reducerConfig.fragmentMatcher,
+ fragmentMatcherFunction: this.reducerConfig.fragmentMatcher
});
this.writes.push(write);
./src/data/readFromStore.ts
./src/data/replaceQueryResults.ts
./src/data/resultReducers.ts
./src/data/store.ts
./src/data/storeUtils.ts
./src/data/storeUtils.ts: { index: 4261,
lineNumber: 175,
column: 37,
message: '\')\' expected.' }
./src/data/writeToStore.ts
ast(input) !== ast(prettier(input))
Index:
===================================================================
---
+++
@@ -4628,27 +4628,26 @@
},
{
- "type": "MemberExpression",
- "object": {
- "type": "TSAsExpression",
- "expression": {
- "type": "Identifier",
- "name": "storeValue"
- },
+ "type": "TSAsExpression",
+ "expression": {
+ "type": "Identifier",
+ "name": "storeValue"
+ },
+ "typeAnnotation": {
+ "type": "TypeAnnotation",
"typeAnnotation": {
- "type": "TypeAnnotation",
- "typeAnnotation": {
- "type": "TSTypeReference",
- "typeName": {
- "type": "Identifier",
+ "type": "TSTypeReference",
+ "typeName": {
+ "type": "JSXMemberExpression",
+ "object": {
+ "type": "JSXIdentifier",
"name": "IdValue"
+ },
+ "property": {
+ "type": "JSXIdentifier",
+ "name": "id"
}
}
}
- },
- "property": {
- "type": "Identifier",
- "name": "id"
- },
- "computed": false
+ }
},
{
Index:
===================================================================
---
+++
@@ -1,3 +1,2 @@
-
import {
getDefaultValues,
@@ -6,6 +5,6 @@
FragmentMap,
getFragmentDefinitions,
- createFragmentMap,
-} from '../queries/getFromAST';
+ createFragmentMap
+} from "../queries/getFromAST";
import {
@@ -13,10 +12,8 @@
resultKeyNameFromField,
isField,
- isInlineFragment,
-} from './storeUtils';
+ isInlineFragment
+} from "./storeUtils";
-import {
- ReadStoreContext,
-} from '../data/readFromStore';
+import { ReadStoreContext } from "../data/readFromStore";
import {
@@ -26,36 +23,21 @@
DocumentNode,
InlineFragmentNode,
- FragmentDefinitionNode,
-} from 'graphql';
+ FragmentDefinitionNode
+} from "graphql";
-import {
- FragmentMatcher,
-} from 'graphql-anywhere';
+import { FragmentMatcher } from "graphql-anywhere";
-import {
- NormalizedCache,
- StoreObject,
- IdValue,
- isIdValue,
-} from './storeUtils';
+import { NormalizedCache, StoreObject, IdValue, isIdValue } from "./storeUtils";
-import {
- IdGetter,
-} from '../core/types';
+import { IdGetter } from "../core/types";
-import {
- shouldInclude,
-} from '../queries/directives';
+import { shouldInclude } from "../queries/directives";
-import {
- isProduction,
-} from '../util/environment';
+import { isProduction } from "../util/environment";
-import {
- assign,
-} from '../util/assign';
+import { assign } from "../util/assign";
class WriteError extends Error {
- public type = 'WriteError';
+ public type = "WriteError";
}
@@ -87,5 +69,5 @@
dataIdFromObject,
fragmentMap = {} as FragmentMap,
- fragmentMatcherFunction,
+ fragmentMatcherFunction
}: {
result: Object,
@@ -95,5 +77,5 @@
dataIdFromObject?: IdGetter,
fragmentMap?: FragmentMap,
- fragmentMatcherFunction?: FragmentMatcher,
+ fragmentMatcherFunction?: FragmentMatcher
}): NormalizedCache {
const queryDefinition: OperationDefinitionNode = getQueryDefinition(query);
@@ -102,5 +84,5 @@
return writeSelectionSetToStore({
- dataId: 'ROOT_QUERY',
+ dataId: "ROOT_QUERY",
result,
selectionSet: queryDefinition.selectionSet,
@@ -110,15 +92,15 @@
dataIdFromObject,
fragmentMap,
- fragmentMatcherFunction,
- },
+ fragmentMatcherFunction
+ }
});
}
export type WriteContext = {
- store: NormalizedCache;
- variables?: any;
- dataIdFromObject?: IdGetter;
- fragmentMap?: FragmentMap;
- fragmentMatcherFunction?: FragmentMatcher;
+ store: NormalizedCache,
+ variables?: any,
+ dataIdFromObject?: IdGetter,
+ fragmentMap?: FragmentMap,
+ fragmentMatcherFunction?: FragmentMatcher
};
@@ -130,5 +112,5 @@
variables,
dataIdFromObject,
- fragmentMatcherFunction,
+ fragmentMatcherFunction
}: {
dataId: string,
@@ -138,7 +120,6 @@
variables?: Object,
dataIdFromObject?: IdGetter,
- fragmentMatcherFunction?: FragmentMatcher,
+ fragmentMatcherFunction?: FragmentMatcher
}): NormalizedCache {
-
// XXX TODO REFACTOR: this is a temporary workaround until query normalization is made to work with documents.
const operationDefinition = getOperationDefinition(document);
@@ -158,11 +139,13 @@
dataIdFromObject,
fragmentMap,
- fragmentMatcherFunction,
- },
+ fragmentMatcherFunction
+ }
});
} catch (e) {
// XXX A bit hacky maybe ...
- const e2 = new Error(`Error writing result to store for query ${document.loc && document.loc.source.body}`);
- e2.message += '/n' + e.message;
+ const e2 = new Error(
+ `Error writing result to store for query ${document.loc && document.loc.source.body}`
+ );
+ e2.message += "/n" + e.message;
e2.stack = e.stack;
throw e2;
@@ -174,14 +157,14 @@
dataId,
selectionSet,
- context,
+ context
}: {
dataId: string,
result: any,
selectionSet: SelectionSetNode,
- context: WriteContext,
+ context: WriteContext
}): NormalizedCache {
const { variables, store, dataIdFromObject, fragmentMap } = context;
- selectionSet.selections.forEach((selection) => {
+ selectionSet.selections.forEach(selection => {
const included = shouldInclude(selection, variables);
@@ -191,16 +174,13 @@
if (included) {
- if (typeof value !== 'undefined') {
+ if (typeof value !== "undefined") {
writeFieldToStore({
dataId,
value,
field: selection,
- context,
+ context
});
} else {
if (context.fragmentMatcherFunction) {
- // XXX We'd like to throw an error, but for backwards compatibility's sake
- // we just print a warning for the time being.
- //throw new WriteError(`Missing field ${resultFieldKey}`);
if (!isProduction()) {
console.warn(`Missing field ${resultFieldKey}`);
@@ -210,5 +190,4 @@
}
} else {
- // This is not a field, so it must be a fragment, either inline or named
let fragment: InlineFragmentNode | FragmentDefinitionNode;
@@ -216,5 +195,4 @@
fragment = selection;
} else {
- // Named fragment
fragment = (fragmentMap || {})[selection.name.value];
@@ -226,21 +204,18 @@
let matches = true;
if (context.fragmentMatcherFunction && fragment.typeCondition) {
- // TODO we need to rewrite the fragment matchers for this to work properly and efficiently
- // Right now we have to pretend that we're passing in an idValue and that there's a store
- // on the context.
- const idValue: IdValue = { type: 'id', id: 'self', generated: false };
+ const idValue: IdValue = { type: "id", id: "self", generated: false };
const fakeContext: ReadStoreContext = {
- store: { 'self': result },
+ store: { self: result },
returnPartialData: false,
hasMissingField: false,
- customResolvers: {},
+ customResolvers: {}
};
matches = context.fragmentMatcherFunction(
idValue,
fragment.typeCondition.name.value,
- fakeContext,
+ fakeContext
);
if (fakeContext.returnPartialData) {
- console.error('WARNING: heuristic fragment matching going on!');
+ console.error("WARNING: heuristic fragment matching going on!");
}
}
@@ -251,5 +226,5 @@
selectionSet: fragment.selectionSet,
dataId,
- context,
+ context
});
}
@@ -260,21 +235,20 @@
}
-
-// Checks if the id given is an id that was generated by Apollo
-// rather than by dataIdFromObject.
function isGeneratedId(id: string): boolean {
- return (id[0] === '$');
+ return id[0] === "$";
}
-function mergeWithGenerated(generatedKey: string, realKey: string, cache: NormalizedCache) {
+function mergeWithGenerated(
+ generatedKey: string,
+ realKey: string,
+ cache: NormalizedCache
+) {
const generated = cache[generatedKey];
const real = cache[realKey];
- Object.keys(generated).forEach((key) => {
+ Object.keys(generated).forEach(key => {
const value = generated[key];
const realValue = real[key];
- if (isIdValue(value)
- && isGeneratedId(value.id)
- && isIdValue(realValue)) {
+ if (isIdValue(value) && isGeneratedId(value.id) && isIdValue(realValue)) {
mergeWithGenerated(value.id, realValue.id, cache);
}
@@ -288,10 +262,10 @@
value,
dataId,
- context,
+ context
}: {
field: FieldNode,
value: any,
dataId: string,
- context: WriteContext,
+ context: WriteContext
}) {
const { variables, dataIdFromObject, store, fragmentMap } = context;
@@ -300,31 +274,26 @@
const storeFieldName: string = storeKeyNameFromField(field, variables);
- // specifies if we need to merge existing keys in the store
let shouldMerge = false;
- // If we merge, this will be the generatedKey
- let generatedKey: string = '';
+ let generatedKey: string = "";
- // If this is a scalar value...
if (!field.selectionSet || value === null) {
- storeValue =
- value != null && typeof value === 'object'
- // If the scalar value is a JSON blob, we have to "escape" it so it can’t pretend to be
- // an id.
- ? { type: 'json', json: value }
- // Otherwise, just store the scalar directly in the store.
- : value;
+ storeValue = value != null && typeof value === "object"
+ ? { type: "json", json: value }
+ : value;
} else if (Array.isArray(value)) {
const generatedId = `${dataId}.${storeFieldName}`;
- storeValue = processArrayValue(value, generatedId, field.selectionSet, context);
+ storeValue = processArrayValue(
+ value,
+ generatedId,
+ field.selectionSet,
+ context
+ );
} else {
- // It's an object
let valueDataId = `${dataId}.${storeFieldName}`;
let generated = true;
- // We only prepend the '$' if the valueDataId isn't already a generated
- // id.
if (!isGeneratedId(valueDataId)) {
- valueDataId = '$' + valueDataId;
+ valueDataId = "$" + valueDataId;
}
@@ -332,10 +301,8 @@
const semanticId = dataIdFromObject(value);
- // We throw an error if the first character of the id is '$. This is
- // because we use that character to designate an Apollo-generated id
- // and we use the distinction between user-desiginated and application-provided
- // ids when managing overwrites.
if (semanticId && isGeneratedId(semanticId)) {
- throw new Error('IDs returned by dataIdFromObject cannot begin with the "$" character.');
+ throw new Error(
+ 'IDs returned by dataIdFromObject cannot begin with the "$" character.'
+ );
}
@@ -350,27 +317,26 @@
result: value,
selectionSet: field.selectionSet,
- context,
+ context
});
- // We take the id and escape it (i.e. wrap it with an enclosing object).
- // This allows us to distinguish IDs from normal scalars.
storeValue = {
- type: 'id',
+ type: "id",
id: valueDataId,
- generated,
+ generated
};
- // check if there was a generated id at the location where we're
- // about to place this new id. If there was, we have to merge the
- // data from that id with the data we're about to write in the store.
if (store[dataId] && store[dataId][storeFieldName] !== storeValue) {
const escapedId = store[dataId][storeFieldName] as IdValue;
- // If there is already a real id in the store and the current id we
- // are dealing with is generated, we throw an error.
- if (isIdValue(storeValue) && storeValue.generated
- && isIdValue(escapedId) && !escapedId.generated) {
- throw new Error(`Store error: the application attempted to write an object with no provided id` +
- ` but the store already contains an id of ${escapedId.id} for this object.`);
+ if (
+ isIdValue(storeValue) &&
+ storeValue.generated &&
+ isIdValue(escapedId) &&
+ !escapedId.generated
+ ) {
+ throw new Error(
+ `Store error: the application attempted to write an object with no provided id` +
+ ` but the store already contains an id of ${escapedId.id} for this object.`
+ );
}
@@ -384,9 +350,9 @@
const newStoreObj = {
...store[dataId],
- [storeFieldName]: storeValue,
+ [storeFieldName]: storeValue
} as StoreObject;
if (shouldMerge) {
- mergeWithGenerated(generatedKey, (storeValue as IdValue).id, store);
+ mergeWithGenerated(generatedKey, storeValue as IdValue.id, store);
}
@@ -400,5 +366,5 @@
generatedId: string,
selectionSet: SelectionSetNode,
- context: WriteContext,
+ context: WriteContext
): any[] {
return value.map((item: any, index: any) => {
@@ -428,11 +394,11 @@
result: item,
selectionSet,
- context,
+ context
});
const idStoreValue: IdValue = {
- type: 'id',
+ type: "id",
id: itemDataId,
- generated,
+ generated
};
./src/errors/ApolloError.ts
./src/index.ts
./src/mutations/store.ts
./src/optimistic-data/store.ts
./src/queries/directives.ts
prettier(input) !== prettier(prettier(input))
Index:
===================================================================
---
+++
@@ -41,5 +41,5 @@
);
} else {
- evaledValue = variables[ifValue as VariableNode.name.value];
+ evaledValue = variables[ifValue as undefined.value];
if (evaledValue === undefined) {
throw new Error(
./src/queries/getFromAST.ts
ast(input) !== ast(prettier(input))
Index:
===================================================================
---
+++
@@ -244,27 +244,26 @@
"operator": "===",
"left": {
- "type": "MemberExpression",
- "object": {
- "type": "TSAsExpression",
- "expression": {
- "type": "Identifier",
- "name": "definition"
- },
+ "type": "TSAsExpression",
+ "expression": {
+ "type": "Identifier",
+ "name": "definition"
+ },
+ "typeAnnotation": {
+ "type": "TypeAnnotation",
"typeAnnotation": {
- "type": "TypeAnnotation",
- "typeAnnotation": {
- "type": "TSTypeReference",
- "typeName": {
- "type": "Identifier",
+ "type": "TSTypeReference",
+ "typeName": {
+ "type": "JSXMemberExpression",
+ "object": {
+ "type": "JSXIdentifier",
"name": "OperationDefinitionNode"
+ },
+ "property": {
+ "type": "JSXIdentifier",
+ "name": "operation"
}
}
}
- },
- "property": {
- "type": "Identifier",
- "name": "operation"
- },
- "computed": false
+ }
},
"right": {
@@ -1196,27 +1195,26 @@
"operator": "===",
"left": {
- "type": "MemberExpression",
- "object": {
- "type": "TSAsExpression",
- "expression": {
- "type": "Identifier",
- "name": "definition"
- },
+ "type": "TSAsExpression",
+ "expression": {
+ "type": "Identifier",
+ "name": "definition"
+ },
+ "typeAnnotation": {
+ "type": "TypeAnnotation",
"typeAnnotation": {
- "type": "TypeAnnotation",
- "typeAnnotation": {
- "type": "TSTypeReference",
- "typeName": {
- "type": "Identifier",
+ "type": "TSTypeReference",
+ "typeName": {
+ "type": "JSXMemberExpression",
+ "object": {
+ "type": "JSXIdentifier",
"name": "OperationDefinitionNode"
+ },
+ "property": {
+ "type": "JSXIdentifier",
+ "name": "operation"
}
}
}
- },
- "property": {
- "type": "Identifier",
- "name": "operation"
- },
- "computed": false
+ }
},
"right": {
Index:
===================================================================
---
+++
@@ -3,21 +3,22 @@
OperationDefinitionNode,
FragmentDefinitionNode,
- ValueNode,
-} from 'graphql';
+ ValueNode
+} from "graphql";
+import { valueToObjectRepresentation } from "../data/storeUtils";
-import {
- valueToObjectRepresentation,
-} from '../data/storeUtils';
+import { assign } from "../util/assign";
-import { assign } from '../util/assign';
-
-export function getMutationDefinition(doc: DocumentNode): OperationDefinitionNode {
+export function getMutationDefinition(
+ doc: DocumentNode
+): OperationDefinitionNode {
checkDocument(doc);
let mutationDef: OperationDefinitionNode | null = null;
- doc.definitions.forEach((definition) => {
- if (definition.kind === 'OperationDefinition'
- && (definition as OperationDefinitionNode).operation === 'mutation') {
+ doc.definitions.forEach(definition => {
+ if (
+ definition.kind === "OperationDefinition" &&
+ definition as OperationDefinitionNode.operation === "mutation"
+ ) {
mutationDef = definition as OperationDefinitionNode;
}
@@ -25,5 +26,5 @@
if (!mutationDef) {
- throw new Error('Must contain a mutation definition.');
+ throw new Error("Must contain a mutation definition.");
}
@@ -33,21 +34,25 @@
// Checks the document for errors and throws an exception if there is an error.
export function checkDocument(doc: DocumentNode) {
- if (doc.kind !== 'Document') {
- throw new Error(`Expecting a parsed GraphQL document. Perhaps you need to wrap the query \
-string in a "gql" tag? http://docs.apollostack.com/apollo-client/core.html#gql`);
+ if (doc.kind !== "Document") {
+ throw new Error(
+ `Expecting a parsed GraphQL document. Perhaps you need to wrap the query \
+string in a "gql" tag? http://docs.apollostack.com/apollo-client/core.html#gql`
+ );
}
let foundOperation = false;
- doc.definitions.forEach((definition) => {
+ doc.definitions.forEach(definition => {
switch (definition.kind) {
// If this is a fragment that’s fine.
- case 'FragmentDefinition':
+ case "FragmentDefinition":
break;
// We can only find one operation, so the first time nothing happens. The second time we
// encounter an operation definition we throw an error.
- case 'OperationDefinition':
+ case "OperationDefinition":
if (foundOperation) {
- throw new Error('Queries must have exactly one operation definition.');
+ throw new Error(
+ "Queries must have exactly one operation definition."
+ );
}
foundOperation = true;
@@ -55,5 +60,7 @@
// If this is any other operation kind, throw an error.
default:
- throw new Error(`Schema type definitions not allowed in queries. Found: "${definition.kind}"`);
+ throw new Error(
+ `Schema type definitions not allowed in queries. Found: "${definition.kind}"`
+ );
}
});
@@ -61,7 +68,7 @@
export function getOperationName(doc: DocumentNode): string {
- let res: string = '';
- doc.definitions.forEach((definition) => {
- if (definition.kind === 'OperationDefinition' && definition.name) {
+ let res: string = "";
+ doc.definitions.forEach(definition => {
+ if (definition.kind === "OperationDefinition" && definition.name) {
res = definition.name.value;
}
@@ -71,12 +78,16 @@
// Returns the FragmentDefinitions from a particular document as an array
-export function getFragmentDefinitions(doc: DocumentNode): FragmentDefinitionNode[] {
- let fragmentDefinitions: FragmentDefinitionNode[] = doc.definitions.filter((definition) => {
- if (definition.kind === 'FragmentDefinition') {
- return true;
- } else {
- return false;
+export function getFragmentDefinitions(
+ doc: DocumentNode
+): FragmentDefinitionNode[] {
+ let fragmentDefinitions: FragmentDefinitionNode[] = doc.definitions.filter(
+ definition => {
+ if (definition.kind === "FragmentDefinition") {
+ return true;
+ } else {
+ return false;
+ }
}
- }) as FragmentDefinitionNode[];
+ ) as FragmentDefinitionNode[];
return fragmentDefinitions;
@@ -87,7 +98,9 @@
let queryDef: OperationDefinitionNode | null = null;
- doc.definitions.map((definition) => {
- if (definition.kind === 'OperationDefinition'
- && (definition as OperationDefinitionNode).operation === 'query') {
+ doc.definitions.map(definition => {
+ if (
+ definition.kind === "OperationDefinition" &&
+ definition as OperationDefinitionNode.operation === "query"
+ ) {
queryDef = definition as OperationDefinitionNode;
}
@@ -95,5 +108,5 @@
if (!queryDef) {
- throw new Error('Must contain a query definition.');
+ throw new Error("Must contain a query definition.");
}
@@ -102,10 +115,12 @@
// TODO REFACTOR: fix this and query/mutation definition to not use map, please.
-export function getOperationDefinition(doc: DocumentNode): OperationDefinitionNode {
+export function getOperationDefinition(
+ doc: DocumentNode
+): OperationDefinitionNode {
checkDocument(doc);
let opDef: OperationDefinitionNode | null = null;
- doc.definitions.map((definition) => {
- if (definition.kind === 'OperationDefinition') {
+ doc.definitions.map(definition => {
+ if (definition.kind === "OperationDefinition") {
opDef = definition as OperationDefinitionNode;
}
@@ -113,5 +128,5 @@
if (!opDef) {
- throw new Error('Must contain a query definition.');
+ throw new Error("Must contain a query definition.");
}
@@ -119,18 +134,22 @@
}
-export function getFragmentDefinition(doc: DocumentNode): FragmentDefinitionNode {
- if (doc.kind !== 'Document') {
- throw new Error(`Expecting a parsed GraphQL document. Perhaps you need to wrap the query \
-string in a "gql" tag? http://docs.apollostack.com/apollo-client/core.html#gql`);
+export function getFragmentDefinition(
+ doc: DocumentNode
+): FragmentDefinitionNode {
+ if (doc.kind !== "Document") {
+ throw new Error(
+ `Expecting a parsed GraphQL document. Perhaps you need to wrap the query \
+string in a "gql" tag? http://docs.apollostack.com/apollo-client/core.html#gql`
+ );
}
if (doc.definitions.length > 1) {
- throw new Error('Fragment must have exactly one definition.');
+ throw new Error("Fragment must have exactly one definition.");
}
const fragmentDef = doc.definitions[0] as FragmentDefinitionNode;
- if (fragmentDef.kind !== 'FragmentDefinition') {
- throw new Error('Must be a fragment definition.');
+ if (fragmentDef.kind !== "FragmentDefinition") {
+ throw new Error("Must be a fragment definition.");
}
@@ -142,12 +161,14 @@
*/
export interface FragmentMap {
- [fragmentName: string]: FragmentDefinitionNode;
+ [fragmentName: string]: FragmentDefinitionNode
}
// Utility function that takes a list of fragment definitions and makes a hash out of them
// that maps the name of the fragment to the fragment definition.
-export function createFragmentMap(fragments: FragmentDefinitionNode[] = []): FragmentMap {
+export function createFragmentMap(
+ fragments: FragmentDefinitionNode[] = []
+): FragmentMap {
const symTable: FragmentMap = {};
- fragments.forEach((fragment) => {
+ fragments.forEach(fragment => {
symTable[fragment.name.value] = fragment;
});
@@ -178,5 +199,8 @@
* fragment, but a `fragmentName` was not defined then an error will be thrown.
*/
-export function getFragmentQueryDocument(document: DocumentNode, fragmentName?: string): DocumentNode {
+export function getFragmentQueryDocument(
+ document: DocumentNode,
+ fragmentName?: string
+): DocumentNode {
let actualFragmentName = fragmentName;
@@ -188,13 +212,13 @@
// Throw an error if we encounter an operation definition because we will
// define our own operation definition later on.
- if (definition.kind === 'OperationDefinition') {
+ if (definition.kind === "OperationDefinition") {
throw new Error(
- `Found a ${definition.operation} operation${definition.name ? ` named '${definition.name.value}'` : ''}. ` +
- 'No operations are allowed when using a fragment as a query. Only fragments are allowed.',
+ `Found a ${definition.operation} operation${definition.name ? ` named '${definition.name.value}'` : ""}. ` +
+ "No operations are allowed when using a fragment as a query. Only fragments are allowed."
);
}
// Add our definition to the fragments array if it is a fragment
// definition.
- if (definition.kind === 'FragmentDefinition') {
+ if (definition.kind === "FragmentDefinition") {
fragments.push(definition);
}
@@ -203,7 +227,9 @@
// If the user did not give us a fragment name then let us try to get a
// name from a single fragment in the definition.
- if (typeof actualFragmentName === 'undefined') {
+ if (typeof actualFragmentName === "undefined") {
if (fragments.length !== 1) {
- throw new Error(`Found ${fragments.length} fragments. \`fragmentName\` must be provided when there is not exactly 1 fragment.`);
+ throw new Error(
+ `Found ${fragments.length} fragments. \`fragmentName\` must be provided when there is not exactly 1 fragment.`
+ );
}
actualFragmentName = fragments[0].name.value;
@@ -216,21 +242,21 @@
definitions: [
{
- kind: 'OperationDefinition',
- operation: 'query',
+ kind: "OperationDefinition",
+ operation: "query",
selectionSet: {
- kind: 'SelectionSet',
+ kind: "SelectionSet",
selections: [
{
- kind: 'FragmentSpread',
+ kind: "FragmentSpread",
name: {
- kind: 'Name',
- value: actualFragmentName,
- },
- },
- ],
- },
+ kind: "Name",
+ value: actualFragmentName
+ }
+ }
+ ]
+ }
},
- ...document.definitions,
- ],
+ ...document.definitions
+ ]
};
@@ -238,14 +264,16 @@
}
-export function getDefaultValues(definition: OperationDefinitionNode): { [key: string]: any } {
+export function getDefaultValues(
+ definition: OperationDefinitionNode
+): { [key: string]: any } {
if (definition.variableDefinitions && definition.variableDefinitions.length) {
const defaultValues = definition.variableDefinitions
.filter(({ defaultValue }) => defaultValue)
- .map(({ variable, defaultValue }) : { [key: string]: any } => {
+ .map(({ variable, defaultValue }): { [key: string]: any } => {
const defaultValueObj: { [key: string]: any } = {};
valueToObjectRepresentation(
defaultValueObj,
variable.name,
- defaultValue as ValueNode,
+ defaultValue as ValueNode
);
./src/queries/networkStatus.ts
ast(input) !== ast(prettier(input))
Index:
===================================================================
---
+++
@@ -19,8 +19,4 @@
"type": "Identifier",
"name": "loading"
- },
- "initializer": {
- "type": "Literal",
- "value": 1
}
},
@@ -30,8 +26,4 @@
"type": "Identifier",
"name": "setVariables"
- },
- "initializer": {
- "type": "Literal",
- "value": 2
}
},
@@ -41,8 +33,4 @@
"type": "Identifier",
"name": "fetchMore"
- },
- "initializer": {
- "type": "Literal",
- "value": 3
}
},
@@ -52,8 +40,4 @@
"type": "Identifier",
"name": "refetch"
- },
- "initializer": {
- "type": "Literal",
- "value": 4
}
},
@@ -63,8 +47,4 @@
"type": "Identifier",
"name": "poll"
- },
- "initializer": {
- "type": "Literal",
- "value": 6
}
},
@@ -74,8 +54,4 @@
"type": "Identifier",
"name": "ready"
- },
- "initializer": {
- "type": "Literal",
- "value": 7
}
},
@@ -85,8 +61,4 @@
"type": "Identifier",
"name": "error"
- },
- "initializer": {
- "type": "Literal",
- "value": 8
}
}
Index:
===================================================================
---
+++
@@ -3,45 +3,53 @@
*/
export enum NetworkStatus {
- /**
+/**
* The query has never been run before and the query is now currently running. A query will still
* have this network status even if a partial data result was returned from the cache, but a
* query was dispatched anyway.
*/
- loading = 1,
- /**
+/**
* If `setVariables` was called and a query was fired because of that then the network status
* will be `setVariables` until the result of that query comes back.
*/
- setVariables = 2,
- /**
+/**
* Indicates that `fetchMore` was called on this query and that the query created is currently in
* flight.
*/
- fetchMore = 3,
- /**
+/**
* Similar to the `setVariables` network status. It means that `refetch` was called on a query
* and the refetch request is currently in flight.
*/
- refetch = 4,
- /**
+/**
* Indicates that a polling query is currently in flight. So for example if you are polling a
* query every 10 seconds then the network status will switch to `poll` every 10 seconds whenever
* a poll request has been sent but not resolved.
*/
- poll = 6,
- /**
+/**
* No request is in flight for this query, and no errors happened. Everything is OK.
*/
- ready = 7,
- /**
+/**
* No request is in flight for this query, but one or more errors were detected.
*/
- error = 8,
+
+ loading,
+
+ setVariables,
+
+ fetchMore,
+
+ refetch,
+
+ poll,
+
+ ready,
+
+ error
+
}
@@ -50,5 +58,7 @@
* status.
*/
-export function isNetworkRequestInFlight (networkStatus: NetworkStatus): boolean {
+export function isNetworkRequestInFlight(
+ networkStatus: NetworkStatus
+): boolean {
return networkStatus < 7;
}
./src/queries/queryTransform.ts
prettier(input) !== prettier(prettier(input))
Index:
===================================================================
---
+++
@@ -29,5 +29,5 @@
return (
selection.kind === "Field" &&
- selection as FieldNode.name.value === "__typename"
+ selection as undefined.value === "__typename"
);
});
./src/queries/store.ts
./src/scheduler/scheduler.ts
ast(input) !== ast(prettier(input))
Index:
===================================================================
---
+++
@@ -719,18 +719,5 @@
"name": "fetchType"
}
- ],
- "typeParameters": {
- "type": "TypeParameterInstantiation",
- "params": [
- {
- "type": "GenericTypeAnnotation",
- "id": {
- "type": "Identifier",
- "name": "T"
- },
- "typeParameters": null
- }
- ]
- }
+ ]
},
"property": {
@@ -1085,18 +1072,5 @@
"name": "options"
}
- ],
- "typeParameters": {
- "type": "TypeParameterInstantiation",
- "params": [
- {
- "type": "GenericTypeAnnotation",
- "id": {
- "type": "Identifier",
- "name": "T"
- },
- "typeParameters": null
- }
- ]
- }
+ ]
}
},
@@ -1537,18 +1511,5 @@
"computed": false
}
- ],
- "typeParameters": {
- "type": "TypeParameterInstantiation",
- "params": [
- {
- "type": "GenericTypeAnnotation",
- "id": {
- "type": "Identifier",
- "name": "T"
- },
- "typeParameters": null
- }
- ]
- }
+ ]
}
},
@@ -2020,18 +1981,5 @@
"name": "interval"
}
- ],
- "typeParameters": {
- "type": "TypeParameterInstantiation",
- "params": [
- {
- "type": "GenericTypeAnnotation",
- "id": {
- "type": "Identifier",
- "name": "T"
- },
- "typeParameters": null
- }
- ]
- }
+ ]
}
}
Index:
===================================================================
---
+++
@@ -9,18 +9,13 @@
// adds queries to the QueryBatcher queue.
-import {
- QueryManager,
-} from '../core/QueryManager';
+import { QueryManager } from "../core/QueryManager";
-import {
- FetchType,
- QueryListener,
-} from '../core/types';
+import { FetchType, QueryListener } from "../core/types";
-import { ObservableQuery } from '../core/ObservableQuery';
+import { ObservableQuery } from "../core/ObservableQuery";
-import { WatchQueryOptions } from '../core/watchQueryOptions';
+import { WatchQueryOptions } from "../core/watchQueryOptions";
-import { NetworkStatus } from '../queries/networkStatus';
+import { NetworkStatus } from "../queries/networkStatus";
export class QueryScheduler {
@@ -44,7 +39,7 @@
constructor({
- queryManager,
+ queryManager
}: {
- queryManager: QueryManager;
+ queryManager: QueryManager
}) {
this.queryManager = queryManager;
@@ -59,14 +54,23 @@
// XXX we do this because some legacy tests use a fake queryId. We should rewrite those tests
- return queries[queryId] && queries[queryId].networkStatus !== NetworkStatus.ready;
+ return (
+ queries[queryId] && queries[queryId].networkStatus !== NetworkStatus.ready
+ );
}
- public fetchQuery<T>(queryId: string, options: WatchQueryOptions, fetchType: FetchType) {
+ public fetchQuery<T>(
+ queryId: string,
+ options: WatchQueryOptions,
+ fetchType: FetchType
+ ) {
return new Promise((resolve, reject) => {
- this.queryManager.fetchQuery<T>(queryId, options, fetchType).then((result) => {
- resolve(result);
- }).catch((error) => {
- reject(error);
- });
+ this.queryManager
+ .fetchQuery(queryId, options, fetchType)
+ .then(result => {
+ resolve(result);
+ })
+ .catch(error => {
+ reject(error);
+ });
});
}
@@ -75,8 +79,10 @@
options: WatchQueryOptions,
queryId: string,
- listener?: QueryListener,
+ listener?: QueryListener
): string {
if (!options.pollInterval) {
- throw new Error('Attempted to start a polling query without a polling interval.');
+ throw new Error(
+ "Attempted to start a polling query without a polling interval."
+ );
}
@@ -91,5 +97,5 @@
this.queryManager.addQueryListener(queryId, listener);
}
- this.addQueryOnInterval<T>(queryId, options);
+ this.addQueryOnInterval(queryId, options);
return queryId;
@@ -108,5 +114,7 @@
// 2. call fetchQueries for queries that are polling and not in flight.
// TODO: refactor this to make it cleaner
- this.intervalQueries[interval] = this.intervalQueries[interval].filter((queryId) => {
+ this.intervalQueries[interval] = this.intervalQueries[
+ interval
+ ].filter(queryId => {
// If queryOptions can't be found from registeredQueries, it means that this queryId
// is no longer registered and should be removed from the list of queries firing on this
@@ -124,6 +132,6 @@
const queryOptions = this.registeredQueries[queryId];
const pollingOptions = { ...queryOptions } as WatchQueryOptions;
- pollingOptions.fetchPolicy = 'network-only';
- this.fetchQuery<T>(queryId, pollingOptions, FetchType.poll);
+ pollingOptions.fetchPolicy = "network-only";
+ this.fetchQuery(queryId, pollingOptions, FetchType.poll);
return true;
});
@@ -138,14 +146,22 @@
// that query with all the other queries executing on that interval. Note that the query id
// and query options must have been added to this.registeredQueries before this function is called.
- public addQueryOnInterval<T>(queryId: string, queryOptions: WatchQueryOptions) {
+ public addQueryOnInterval<T>(
+ queryId: string,
+ queryOptions: WatchQueryOptions
+ ) {
const interval = queryOptions.pollInterval;
if (!interval) {
- throw new Error(`A poll interval is required to start polling query with id '${queryId}'.`);
+ throw new Error(
+ `A poll interval is required to start polling query with id '${queryId}'.`
+ );
}
// If there are other queries on this interval, this query will just fire with those
// and we don't need to create a new timer.
- if (this.intervalQueries.hasOwnProperty(interval.toString()) && this.intervalQueries[interval].length > 0) {
+ if (
+ this.intervalQueries.hasOwnProperty(interval.toString()) &&
+ this.intervalQueries[interval].length > 0
+ ) {
this.intervalQueries[interval].push(queryId);
} else {
@@ -153,5 +169,5 @@
// set up the timer for the function that will handle this interval
this.pollingTimers[interval] = setInterval(() => {
- this.fetchQueriesOnInterval<T>(interval);
+ this.fetchQueriesOnInterval(interval);
}, interval);
}
@@ -159,11 +175,15 @@
// Used only for unit testing.
- public registerPollingQuery<T>(queryOptions: WatchQueryOptions): ObservableQuery<T> {
+ public registerPollingQuery<T>(
+ queryOptions: WatchQueryOptions
+ ): ObservableQuery<T> {
if (!queryOptions.pollInterval) {
- throw new Error('Attempted to register a non-polling query with the scheduler.');
+ throw new Error(
+ "Attempted to register a non-polling query with the scheduler."
+ );
}
return new ObservableQuery<T>({
scheduler: this,
- options: queryOptions,
+ options: queryOptions
});
}
./src/store.ts
./src/transport/afterware.ts
./src/transport/batchedNetworkInterface.ts
./src/transport/batchedNetworkInterface.ts: { index: 2601,
lineNumber: 82,
column: 44,
message: '\';\' expected.' }
./src/transport/batching.ts
./src/transport/Deduplicator.ts
./src/transport/middleware.ts
./src/transport/networkInterface.ts
./src/transport/networkInterface.ts: { index: 6108,
lineNumber: 213,
column: 36,
message: '\';\' expected.' }
./src/util/assign.ts
./src/util/cloneDeep.ts
./src/util/environment.ts
./src/util/errorHandling.ts
./src/util/isEqual.ts
./src/util/maybeDeepFreeze.ts
./src/util/Observable.ts
./src/util/Observable.ts: { index: 524,
lineNumber: 14,
column: 10,
message: '\'}\' expected.' }
./src/util/warnOnce.ts
./src/version.ts
./test/ApolloClient.ts
ast(input) !== ast(prettier(input))
Index:
===================================================================
---
+++
@@ -7328,5 +7328,5 @@
"value": null,
"regex": {
- "pattern": "Missing field description"
+ "pattern": "missing field description"
}
}
@@ -10602,5 +10602,5 @@
"value": null,
"regex": {
- "pattern": "Missing field e"
+ "pattern": "missing field e"
}
}
Index:
===================================================================
---
+++
@@ -1,256 +1,317 @@
-import { assert } from 'chai';
-import gql from 'graphql-tag';
-import { Store } from '../src/store';
-import ApolloClient from '../src/ApolloClient';
+import { assert } from "chai";
+import gql from "graphql-tag";
+import { Store } from "../src/store";
+import ApolloClient from "../src/ApolloClient";
-import { withWarning } from './util/wrap';
+import { withWarning } from "./util/wrap";
-describe('ApolloClient', () => {
- describe('readQuery', () => {
- it('will read some data from the store', () => {
+describe("ApolloClient", () => {
+ describe("readQuery", () => {
+ it("will read some data from the store", () => {
const client = new ApolloClient({
initialState: {
apollo: {
data: {
- 'ROOT_QUERY': {
+ ROOT_QUERY: {
a: 1,
b: 2,
- c: 3,
- },
- },
- },
- },
+ c: 3
+ }
+ }
+ }
+ }
});
assert.deepEqual(client.readQuery({ query: gql`{ a }` }), { a: 1 });
- assert.deepEqual(client.readQuery({ query: gql`{ b c }` }), { b: 2, c: 3 });
- assert.deepEqual(client.readQuery({ query: gql`{ a b c }` }), { a: 1, b: 2, c: 3 });
+ assert.deepEqual(client.readQuery({ query: gql`{ b c }` }), {
+ b: 2,
+ c: 3
+ });
+ assert.deepEqual(client.readQuery({ query: gql`{ a b c }` }), {
+ a: 1,
+ b: 2,
+ c: 3
+ });
});
- it('will read some deeply nested data from the store', () => {
+ it("will read some deeply nested data from the store", () => {
const client = new ApolloClient({
initialState: {
apollo: {
data: {
- 'ROOT_QUERY': {
+ ROOT_QUERY: {
a: 1,
b: 2,
c: 3,
d: {
- type: 'id',
- id: 'foo',
- generated: false,
- },
+ type: "id",
+ id: "foo",
+ generated: false
+ }
},
- 'foo': {
- __typename: 'Foo',
+ foo: {
+ __typename: "Foo",
e: 4,
f: 5,
g: 6,
h: {
- type: 'id',
- id: 'bar',
- generated: false,
- },
+ type: "id",
+ id: "bar",
+ generated: false
+ }
},
- 'bar': {
- __typename: 'Bar',
+ bar: {
+ __typename: "Bar",
i: 7,
j: 8,
- k: 9,
- },
- },
- },
- },
+ k: 9
+ }
+ }
+ }
+ }
});
+ assert.deepEqual(client.readQuery({ query: gql`{ a d { e } }` }), {
+ a: 1,
+ d: { e: 4, __typename: "Foo" }
+ });
assert.deepEqual(
- client.readQuery({ query: gql`{ a d { e } }` }),
- { a: 1, d: { e: 4, __typename: 'Foo' } },
- );
- assert.deepEqual(
client.readQuery({ query: gql`{ a d { e h { i } } }` }),
- { a: 1, d: { __typename: 'Foo', e: 4, h: { i: 7, __typename: 'Bar' } } },
+ { a: 1, d: { __typename: "Foo", e: 4, h: { i: 7, __typename: "Bar" } } }
);
assert.deepEqual(
client.readQuery({ query: gql`{ a b c d { e f g h { i j k } } }` }),
- { a: 1, b: 2, c: 3, d: { __typename: 'Foo', e: 4, f: 5, g: 6, h: { __typename: 'Bar', i: 7, j: 8, k: 9 } } },
+ {
+ a: 1,
+ b: 2,
+ c: 3,
+ d: {
+ __typename: "Foo",
+ e: 4,
+ f: 5,
+ g: 6,
+ h: { __typename: "Bar", i: 7, j: 8, k: 9 }
+ }
+ }
);
});
- it('will read some data from the store with variables', () => {
+ it("will read some data from the store with variables", () => {
const client = new ApolloClient({
initialState: {
apollo: {
data: {
- 'ROOT_QUERY': {
+ ROOT_QUERY: {
'field({"literal":true,"value":42})': 1,
- 'field({"literal":false,"value":42})': 2,
- },
- },
- },
- },
+ 'field({"literal":false,"value":42})': 2
+ }
+ }
+ }
+ }
});
- assert.deepEqual(client.readQuery({
- query: gql`query ($literal: Boolean, $value: Int) {
+ assert.deepEqual(
+ client.readQuery({
+ query: gql`query ($literal: Boolean, $value: Int) {
a: field(literal: true, value: 42)
b: field(literal: $literal, value: $value)
}`,
- variables: {
- literal: false,
- value: 42,
- },
- }), { a: 1, b: 2 });
+ variables: {
+ literal: false,
+ value: 42
+ }
+ }),
+ { a: 1, b: 2 }
+ );
});
});
- it('will read some data from the store with default values', () => {
+ it("will read some data from the store with default values", () => {
const client = new ApolloClient({
initialState: {
apollo: {
data: {
- 'ROOT_QUERY': {
+ ROOT_QUERY: {
'field({"literal":true,"value":-1})': 1,
- 'field({"literal":false,"value":42})': 2,
- },
- },
- },
- },
+ 'field({"literal":false,"value":42})': 2
+ }
+ }
+ }
+ }
});
- assert.deepEqual(client.readQuery({
- query: gql`query ($literal: Boolean, $value: Int = -1) {
+ assert.deepEqual(
+ client.readQuery({
+ query: gql`query ($literal: Boolean, $value: Int = -1) {
a: field(literal: $literal, value: $value)
}`,
- variables: {
- literal: false,
- value: 42,
- },
- }), { a: 2 });
+ variables: {
+ literal: false,
+ value: 42
+ }
+ }),
+ { a: 2 }
+ );
- assert.deepEqual(client.readQuery({
- query: gql`query ($literal: Boolean, $value: Int = -1) {
+ assert.deepEqual(
+ client.readQuery({
+ query: gql`query ($literal: Boolean, $value: Int = -1) {
a: field(literal: $literal, value: $value)
}`,
- variables: {
- literal: true,
- },
- }), { a: 1 });
+ variables: {
+ literal: true
+ }
+ }),
+ { a: 1 }
+ );
});
- describe('readFragment', () => {
- it('will throw an error when there is no fragment', () => {
+ describe("readFragment", () => {
+ it("will throw an error when there is no fragment", () => {
const client = new ApolloClient();
assert.throws(() => {
- client.readFragment({ id: 'x', fragment: gql`query { a b c }` });
- }, 'Found a query operation. No operations are allowed when using a fragment as a query. Only fragments are allowed.');
+ client.readFragment({ id: "x", fragment: gql`query { a b c }` });
+ }, "Found a query operation. No operations are allowed when using a fragment as a query. Only fragments are allowed.");
assert.throws(() => {
- client.readFragment({ id: 'x', fragment: gql`schema { query: Query }` });
- }, 'Found 0 fragments. `fragmentName` must be provided when there is not exactly 1 fragment.');
+ client.readFragment({
+ id: "x",
+ fragment: gql`schema { query: Query }`
+ });
+ }, "Found 0 fragments. `fragmentName` must be provided when there is not exactly 1 fragment.");
});
- it('will throw an error when there is more than one fragment but no fragment name', () => {
+ it("will throw an error when there is more than one fragment but no fragment name", () => {
const client = new ApolloClient();
assert.throws(() => {
- client.readFragment({ id: 'x', fragment: gql`fragment a on A { a } fragment b on B { b }` });
- }, 'Found 2 fragments. `fragmentName` must be provided when there is not exactly 1 fragment.');
+ client.readFragment({
+ id: "x",
+ fragment: gql`fragment a on A { a } fragment b on B { b }`
+ });
+ }, "Found 2 fragments. `fragmentName` must be provided when there is not exactly 1 fragment.");
assert.throws(() => {
- client.readFragment({ id: 'x', fragment: gql`fragment a on A { a } fragment b on B { b } fragment c on C { c }` });
- }, 'Found 3 fragments. `fragmentName` must be provided when there is not exactly 1 fragment.');
+ client.readFragment({
+ id: "x",
+ fragment: gql`fragment a on A { a } fragment b on B { b } fragment c on C { c }`
+ });
+ }, "Found 3 fragments. `fragmentName` must be provided when there is not exactly 1 fragment.");
});
- it('will read some deeply nested data from the store at any id', () => {
+ it("will read some deeply nested data from the store at any id", () => {
const client = new ApolloClient({
initialState: {
apollo: {
data: {
- 'ROOT_QUERY': {
- __typename: 'Foo',
+ ROOT_QUERY: {
+ __typename: "Foo",
a: 1,
b: 2,
c: 3,
d: {
- type: 'id',
- id: 'foo',
- generated: false,
- },
+ type: "id",
+ id: "foo",
+ generated: false
+ }
},
- 'foo': {
- __typename: 'Foo',
+ foo: {
+ __typename: "Foo",
e: 4,
f: 5,
g: 6,
h: {
- type: 'id',
- id: 'bar',
- generated: false,
- },
+ type: "id",
+ id: "bar",
+ generated: false
+ }
},
- 'bar': {
- __typename: 'Bar',
+ bar: {
+ __typename: "Bar",
i: 7,
j: 8,
- k: 9,
- },
- },
- },
- },
+ k: 9
+ }
+ }
+ }
+ }
});
assert.deepEqual(
- client.readFragment({ id: 'foo', fragment: gql`fragment fragmentFoo on Foo { e h { i } }` }),
- { __typename: 'Foo', e: 4, h: { __typename: 'Bar', i: 7 } },
+ client.readFragment({
+ id: "foo",
+ fragment: gql`fragment fragmentFoo on Foo { e h { i } }`
+ }),
+ { __typename: "Foo", e: 4, h: { __typename: "Bar", i: 7 } }
);
assert.deepEqual(
- client.readFragment({ id: 'foo', fragment: gql`fragment fragmentFoo on Foo { e f g h { i j k } }` }),
- { __typename: 'Foo', e: 4, f: 5, g: 6, h: { __typename: 'Bar', i: 7, j: 8, k: 9 } },
+ client.readFragment({
+ id: "foo",
+ fragment: gql`fragment fragmentFoo on Foo { e f g h { i j k } }`
+ }),
+ {
+ __typename: "Foo",
+ e: 4,
+ f: 5,
+ g: 6,
+ h: { __typename: "Bar", i: 7, j: 8, k: 9 }
+ }
);
assert.deepEqual(
- client.readFragment({ id: 'bar', fragment: gql`fragment fragmentBar on Bar { i }` }),
- { __typename: 'Bar', i: 7 },
+ client.readFragment({
+ id: "bar",
+ fragment: gql`fragment fragmentBar on Bar { i }`
+ }),
+ { __typename: "Bar", i: 7 }
);
assert.deepEqual(
- client.readFragment({ id: 'bar', fragment: gql`fragment fragmentBar on Bar { i j k }` }),
- { __typename: 'Bar', i: 7, j: 8, k: 9 },
+ client.readFragment({
+ id: "bar",
+ fragment: gql`fragment fragmentBar on Bar { i j k }`
+ }),
+ { __typename: "Bar", i: 7, j: 8, k: 9 }
);
assert.deepEqual(
client.readFragment({
- id: 'foo',
+ id: "foo",
fragment: gql`fragment fragmentFoo on Foo { e f g h { i j k } } fragment fragmentBar on Bar { i j k }`,
- fragmentName: 'fragmentFoo',
+ fragmentName: "fragmentFoo"
}),
- { __typename: 'Foo', e: 4, f: 5, g: 6, h: { __typename: 'Bar', i: 7, j: 8, k: 9 } },
+ {
+ __typename: "Foo",
+ e: 4,
+ f: 5,
+ g: 6,
+ h: { __typename: "Bar", i: 7, j: 8, k: 9 }
+ }
);
assert.deepEqual(
client.readFragment({
- id: 'bar',
+ id: "bar",
fragment: gql`fragment fragmentFoo on Foo { e f g h { i j k } } fragment fragmentBar on Bar { i j k }`,
- fragmentName: 'fragmentBar',
+ fragmentName: "fragmentBar"
}),
- { __typename: 'Bar', i: 7, j: 8, k: 9 },
+ { __typename: "Bar", i: 7, j: 8, k: 9 }
);
});
- it('will read some data from the store with variables', () => {
+ it("will read some data from the store with variables", () => {
const client = new ApolloClient({
initialState: {
apollo: {
data: {
- 'foo': {
- __typename: 'Foo',
+ foo: {
+ __typename: "Foo",
'field({"literal":true,"value":42})': 1,
- 'field({"literal":false,"value":42})': 2,
- },
- },
- },
- },
+ 'field({"literal":false,"value":42})': 2
+ }
+ }
+ }
+ }
});
- assert.deepEqual(client.readFragment({
- id: 'foo',
- fragment: gql`
+ assert.deepEqual(
+ client.readFragment({
+ id: "foo",
+ fragment: gql`
fragment foo on Foo {
a: field(literal: true, value: 42)
@@ -258,12 +319,14 @@
}
`,
- variables: {
- literal: false,
- value: 42,
- },
- }), { __typename: 'Foo', a: 1, b: 2 });
+ variables: {
+ literal: false,
+ value: 42
+ }
+ }),
+ { __typename: "Foo", a: 1, b: 2 }
+ );
});
- it('will return null when an id that can’t be found is provided', () => {
+ it("will return null when an id that can’t be found is provided", () => {
const client1 = new ApolloClient();
const client2 = new ApolloClient({
@@ -271,8 +334,8 @@
apollo: {
data: {
- 'bar': { __typename: 'Foo', a: 1, b: 2, c: 3 },
- },
- },
- },
+ bar: { __typename: "Foo", a: 1, b: 2, c: 3 }
+ }
+ }
+ }
});
const client3 = new ApolloClient({
@@ -280,19 +343,36 @@
apollo: {
data: {
- 'foo': { __typename: 'Foo', a: 1, b: 2, c: 3 },
- },
- },
- },
+ foo: { __typename: "Foo", a: 1, b: 2, c: 3 }
+ }
+ }
+ }
});
- assert.equal(client1.readFragment({ id: 'foo', fragment: gql`fragment fooFragment on Foo { a b c }` }), null);
- assert.equal(client2.readFragment({ id: 'foo', fragment: gql`fragment fooFragment on Foo { a b c }` }), null);
- assert.deepEqual(client3.readFragment({ id: 'foo', fragment: gql`fragment fooFragment on Foo { a b c }` }),
- { __typename: 'Foo', a: 1, b: 2, c: 3 });
+ assert.equal(
+ client1.readFragment({
+ id: "foo",
+ fragment: gql`fragment fooFragment on Foo { a b c }`
+ }),
+ null
+ );
+ assert.equal(
+ client2.readFragment({
+ id: "foo",
+ fragment: gql`fragment fooFragment on Foo { a b c }`
+ }),
+ null
+ );
+ assert.deepEqual(
+ client3.readFragment({
+ id: "foo",
+ fragment: gql`fragment fooFragment on Foo { a b c }`
+ }),
+ { __typename: "Foo", a: 1, b: 2, c: 3 }
+ );
});
});
- describe('writeQuery', () => {
- it('will write some data to the store', () => {
+ describe("writeQuery", () => {
+ it("will write some data to the store", () => {
const client = new ApolloClient();
@@ -300,7 +380,7 @@
assert.deepEqual(client.store.getState().apollo.data, {
- 'ROOT_QUERY': {
- a: 1,
- },
+ ROOT_QUERY: {
+ a: 1
+ }
});
@@ -308,9 +388,9 @@
assert.deepEqual(client.store.getState().apollo.data, {
- 'ROOT_QUERY': {
+ ROOT_QUERY: {
a: 1,
b: 2,
- c: 3,
- },
+ c: 3
+ }
});
@@ -318,105 +398,117 @@
assert.deepEqual(client.store.getState().apollo.data, {
- 'ROOT_QUERY': {
+ ROOT_QUERY: {
a: 4,
b: 5,
- c: 6,
- },
+ c: 6
+ }
});
});
- it('will write some deeply nested data to the store', () => {
+ it("will write some deeply nested data to the store", () => {
const client = new ApolloClient();
client.writeQuery({
- data: { a: 1, d: { __typename: 'D', e: 4 } },
- query: gql`{ a d { e } }`,
+ data: { a: 1, d: { __typename: "D", e: 4 } },
+ query: gql`{ a d { e } }`
});
assert.deepEqual(client.store.getState().apollo.data, {
- 'ROOT_QUERY': {
+ ROOT_QUERY: {
a: 1,
d: {
- type: 'id',
- id: '$ROOT_QUERY.d',
- generated: true,
- },
+ type: "id",
+ id: "$ROOT_QUERY.d",
+ generated: true
+ }
},
- '$ROOT_QUERY.d': {
- __typename: 'D',
- e: 4,
- },
+ "$ROOT_QUERY.d": {
+ __typename: "D",
+ e: 4
+ }
});
client.writeQuery({
- data: { a: 1, d: { __typename: 'D', h: { __typename: 'H', i: 7 } } },
- query: gql`{ a d { h { i } } }`,
+ data: { a: 1, d: { __typename: "D", h: { __typename: "H", i: 7 } } },
+ query: gql`{ a d { h { i } } }`
});
assert.deepEqual(client.store.getState().apollo.data, {
- 'ROOT_QUERY': {
+ ROOT_QUERY: {
a: 1,
d: {
- type: 'id',
- id: '$ROOT_QUERY.d',
- generated: true,
- },
+ type: "id",
+ id: "$ROOT_QUERY.d",
+ generated: true
+ }
},
- '$ROOT_QUERY.d': {
- __typename: 'D',
+ "$ROOT_QUERY.d": {
+ __typename: "D",
e: 4,
h: {
- type: 'id',
- id: '$ROOT_QUERY.d.h',
- generated: true,
- },
+ type: "id",
+ id: "$ROOT_QUERY.d.h",
+ generated: true
+ }
},
- '$ROOT_QUERY.d.h': {
- __typename: 'H',
- i: 7,
- },
+ "$ROOT_QUERY.d.h": {
+ __typename: "H",
+ i: 7
+ }
});
client.writeQuery({
- data: { a: 1, b: 2, c: 3, d: {
- __typename: 'D', e: 4, f: 5, g: 6, h: {
- __typename: 'H', i: 7, j: 8, k: 9,
- },
- } },
- query: gql`{ a b c d { e f g h { i j k } } }`,
+ data: {
+ a: 1,
+ b: 2,
+ c: 3,
+ d: {
+ __typename: "D",
+ e: 4,
+ f: 5,
+ g: 6,
+ h: {
+ __typename: "H",
+ i: 7,
+ j: 8,
+ k: 9
+ }
+ }
+ },
+ query: gql`{ a b c d { e f g h { i j k } } }`
});
assert.deepEqual(client.store.getState().apollo.data, {
- 'ROOT_QUERY': {
+ ROOT_QUERY: {
a: 1,
b: 2,
c: 3,
d: {
- type: 'id',
- id: '$ROOT_QUERY.d',
- generated: true,
- },
+ type: "id",
+ id: "$ROOT_QUERY.d",
+ generated: true
+ }
},
- '$ROOT_QUERY.d': {
- __typename: 'D',
+ "$ROOT_QUERY.d": {
+ __typename: "D",
e: 4,
f: 5,
g: 6,
h: {
- type: 'id',
- id: '$ROOT_QUERY.d.h',
- generated: true,
- },
+ type: "id",
+ id: "$ROOT_QUERY.d.h",
+ generated: true
+ }
},
- '$ROOT_QUERY.d.h': {
- __typename: 'H',
+ "$ROOT_QUERY.d.h": {
+ __typename: "H",
i: 7,
j: 8,
- k: 9,
- },
+ k: 9
+ }
});
});
- it('will write some data to the store with variables', () => {
+ it("will write some data to the store with variables", () => {
const client = new ApolloClient();
@@ -424,5 +516,5 @@
data: {
a: 1,
- b: 2,
+ b: 2
},
query: gql`
@@ -434,22 +526,22 @@
variables: {
literal: false,
- value: 42,
- },
+ value: 42
+ }
});
assert.deepEqual(client.store.getState().apollo.data, {
- 'ROOT_QUERY': {
+ ROOT_QUERY: {
'field({"literal":true,"value":42})': 1,
- 'field({"literal":false,"value":42})': 2,
- },
+ 'field({"literal":false,"value":42})': 2
+ }
});
});
- it('will write some data to the store with default values for variables', () => {
+ it("will write some data to the store with default values for variables", () => {
const client = new ApolloClient();
client.writeQuery({
data: {
- a: 2,
+ a: 2
},
query: gql`
@@ -460,11 +552,11 @@
variables: {
literal: true,
- value: 42,
- },
+ value: 42
+ }
});
client.writeQuery({
data: {
- a: 1,
+ a: 1
},
query: gql`
@@ -474,17 +566,17 @@
`,
variables: {
- literal: false,
- },
+ literal: false
+ }
});
assert.deepEqual(client.store.getState().apollo.data, {
- 'ROOT_QUERY': {
+ ROOT_QUERY: {
'field({"literal":true,"value":42})': 2,
- 'field({"literal":false,"value":-1})': 1,
- },
+ 'field({"literal":false,"value":-1})': 1
+ }
});
});
- it('should warn when the data provided does not match the query shape', () => {
+ it("should warn when the data provided does not match the query shape", () => {
const client = new ApolloClient();
@@ -494,211 +586,242 @@
todos: [
{
- id: '1',
- name: 'Todo 1',
- __typename: 'Todo',
- },
- ],
+ id: "1",
+ name: "Todo 1",
+ __typename: "Todo"
+ }
+ ]
},
query: gql`
query { todos { id name description } }
- `,
+ `
});
- }, /Missing field description/);
+ }, /missing field description/);
});
});
- describe('writeFragment', () => {
- it('will throw an error when there is no fragment', () => {
+ describe("writeFragment", () => {
+ it("will throw an error when there is no fragment", () => {
const client = new ApolloClient();
assert.throws(() => {
- client.writeFragment({ data: {}, id: 'x', fragment: gql`query { a b c }` });
- }, 'Found a query operation. No operations are allowed when using a fragment as a query. Only fragments are allowed.');
+ client.writeFragment({
+ data: {},
+ id: "x",
+ fragment: gql`query { a b c }`
+ });
+ }, "Found a query operation. No operations are allowed when using a fragment as a query. Only fragments are allowed.");
assert.throws(() => {
- client.writeFragment({ data: {}, id: 'x', fragment: gql`schema { query: Query }` });
- }, 'Found 0 fragments. `fragmentName` must be provided when there is not exactly 1 fragment.');
+ client.writeFragment({
+ data: {},
+ id: "x",
+ fragment: gql`schema { query: Query }`
+ });
+ }, "Found 0 fragments. `fragmentName` must be provided when there is not exactly 1 fragment.");
});
- it('will throw an error when there is more than one fragment but no fragment name', () => {
+ it("will throw an error when there is more than one fragment but no fragment name", () => {
const client = new ApolloClient();
assert.throws(() => {
- client.writeFragment({ data: {}, id: 'x', fragment: gql`fragment a on A { a } fragment b on B { b }` });
- }, 'Found 2 fragments. `fragmentName` must be provided when there is not exactly 1 fragment.');
+ client.writeFragment({
+ data: {},
+ id: "x",
+ fragment: gql`fragment a on A { a } fragment b on B { b }`
+ });
+ }, "Found 2 fragments. `fragmentName` must be provided when there is not exactly 1 fragment.");
assert.throws(() => {
- client.writeFragment({ data: {}, id: 'x', fragment: gql`fragment a on A { a } fragment b on B { b } fragment c on C { c }` });
- }, 'Found 3 fragments. `fragmentName` must be provided when there is not exactly 1 fragment.');
+ client.writeFragment({
+ data: {},
+ id: "x",
+ fragment: gql`fragment a on A { a } fragment b on B { b } fragment c on C { c }`
+ });
+ }, "Found 3 fragments. `fragmentName` must be provided when there is not exactly 1 fragment.");
});
- it('will write some deeply nested data into the store at any id', () => {
+ it("will write some deeply nested data into the store at any id", () => {
const client = new ApolloClient({
- dataIdFromObject: (o: any) => o.id,
+ dataIdFromObject: (o: any) => o.id
});
client.writeFragment({
- data: { __typename: 'Foo', e: 4, h: { __typename: 'Bar', id: 'bar', i: 7 } },
- id: 'foo',
- fragment: gql`fragment fragmentFoo on Foo { e h { i } }`,
+ data: {
+ __typename: "Foo",
+ e: 4,
+ h: { __typename: "Bar", id: "bar", i: 7 }
+ },
+ id: "foo",
+ fragment: gql`fragment fragmentFoo on Foo { e h { i } }`
});
assert.deepEqual(client.store.getState().apollo.data, {
- 'foo': {
- __typename: 'Foo',
+ foo: {
+ __typename: "Foo",
e: 4,
h: {
- type: 'id',
- id: 'bar',
- generated: false,
- },
+ type: "id",
+ id: "bar",
+ generated: false
+ }
},
- 'bar': {
- __typename: 'Bar',
- i: 7,
- },
+ bar: {
+ __typename: "Bar",
+ i: 7
+ }
});
client.writeFragment({
- data: { __typename: 'Foo', f: 5, g: 6, h: { __typename: 'Bar', id: 'bar', j: 8, k: 9 } },
- id: 'foo',
- fragment: gql`fragment fragmentFoo on Foo { f g h { j k } }`,
+ data: {
+ __typename: "Foo",
+ f: 5,
+ g: 6,
+ h: { __typename: "Bar", id: "bar", j: 8, k: 9 }
+ },
+ id: "foo",
+ fragment: gql`fragment fragmentFoo on Foo { f g h { j k } }`
});
assert.deepEqual(client.store.getState().apollo.data, {
- 'foo': {
- __typename: 'Foo',
+ foo: {
+ __typename: "Foo",
e: 4,
f: 5,
g: 6,
h: {
- type: 'id',
- id: 'bar',
- generated: false,
- },
+ type: "id",
+ id: "bar",
+ generated: false
+ }
},
- 'bar': {
- __typename: 'Bar',
+ bar: {
+ __typename: "Bar",
i: 7,
j: 8,
- k: 9,
- },
+ k: 9
+ }
});
client.writeFragment({
- data: { __typename: 'Bar', i: 10 },
- id: 'bar',
- fragment: gql`fragment fragmentBar on Bar { i }`,
+ data: { __typename: "Bar", i: 10 },
+ id: "bar",
+ fragment: gql`fragment fragmentBar on Bar { i }`
});
assert.deepEqual(client.store.getState().apollo.data, {
- 'foo': {
- __typename: 'Foo',
+ foo: {
+ __typename: "Foo",
e: 4,
f: 5,
g: 6,
h: {
- type: 'id',
- id: 'bar',
- generated: false,
- },
+ type: "id",
+ id: "bar",
+ generated: false
+ }
},
- 'bar': {
- __typename: 'Bar',
+ bar: {
+ __typename: "Bar",
i: 10,
j: 8,
- k: 9,
- },
+ k: 9
+ }
});
client.writeFragment({
- data: { __typename: 'Bar', j: 11, k: 12 },
- id: 'bar',
- fragment: gql`fragment fragmentBar on Bar { j k }`,
+ data: { __typename: "Bar", j: 11, k: 12 },
+ id: "bar",
+ fragment: gql`fragment fragmentBar on Bar { j k }`
});
assert.deepEqual(client.store.getState().apollo.data, {
- 'foo': {
- __typename: 'Foo',
+ foo: {
+ __typename: "Foo",
e: 4,
f: 5,
g: 6,
h: {
- type: 'id',
- id: 'bar',
- generated: false,
- },
+ type: "id",
+ id: "bar",
+ generated: false
+ }
},
- 'bar': {
- __typename: 'Bar',
+ bar: {
+ __typename: "Bar",
i: 10,
j: 11,
- k: 12,
- },
+ k: 12
+ }
});
client.writeFragment({
- data: { __typename: 'Foo', e: 4, f: 5, g: 6, h: { __typename: 'Bar', id: 'bar', i: 7, j: 8, k: 9 } },
- id: 'foo',
+ data: {
+ __typename: "Foo",
+ e: 4,
+ f: 5,
+ g: 6,
+ h: { __typename: "Bar", id: "bar", i: 7, j: 8, k: 9 }
+ },
+ id: "foo",
fragment: gql`fragment fooFragment on Foo { e f g h { i j k } } fragment barFragment on Bar { i j k }`,
- fragmentName: 'fooFragment',
+ fragmentName: "fooFragment"
});
assert.deepEqual(client.store.getState().apollo.data, {
- 'foo': {
- __typename: 'Foo',
+ foo: {
+ __typename: "Foo",
e: 4,
f: 5,
g: 6,
h: {
- type: 'id',
- id: 'bar',
- generated: false,
- },
+ type: "id",
+ id: "bar",
+ generated: false
+ }
},
- 'bar': {
- __typename: 'Bar',
+ bar: {
+ __typename: "Bar",
i: 7,
j: 8,
- k: 9,
- },
+ k: 9
+ }
});
client.writeFragment({
- data: { __typename: 'Bar', i: 10, j: 11, k: 12 },
- id: 'bar',
+ data: { __typename: "Bar", i: 10, j: 11, k: 12 },
+ id: "bar",
fragment: gql`fragment fooFragment on Foo { e f g h { i j k } } fragment barFragment on Bar { i j k }`,
- fragmentName: 'barFragment',
+ fragmentName: "barFragment"
});
assert.deepEqual(client.store.getState().apollo.data, {
- 'foo': {
- __typename: 'Foo',
+ foo: {
+ __typename: "Foo",
e: 4,
f: 5,
g: 6,
h: {
- type: 'id',
- id: 'bar',
- generated: false,
- },
+ type: "id",
+ id: "bar",
+ generated: false
+ }
},
- 'bar': {
- __typename: 'Bar',
+ bar: {
+ __typename: "Bar",
i: 10,
j: 11,
- k: 12,
- },
+ k: 12
+ }
});
});
- it('will write some data to the store with variables', () => {
+ it("will write some data to the store with variables", () => {
const client = new ApolloClient();
client.writeFragment({
data: {
- __typename: 'Foo',
+ __typename: "Foo",
a: 1,
- b: 2,
+ b: 2
},
- id: 'foo',
+ id: "foo",
fragment: gql`
fragment foo on Foo {
@@ -709,181 +832,242 @@
variables: {
literal: false,
- value: 42,
- },
+ value: 42
+ }
});
assert.deepEqual(client.store.getState().apollo.data, {
- 'foo': {
- __typename: 'Foo',
+ foo: {
+ __typename: "Foo",
'field({"literal":true,"value":42})': 1,
- 'field({"literal":false,"value":42})': 2,
- },
+ 'field({"literal":false,"value":42})': 2
+ }
});
});
- it('should warn when the data provided does not match the fragment shape', () => {
+ it("should warn when the data provided does not match the fragment shape", () => {
const client = new ApolloClient();
return withWarning(() => {
- client.writeFragment({
- data: { __typename: 'Bar', i: 10 },
- id: 'bar',
- fragment: gql`fragment fragmentBar on Bar { i e }`,
+ client.writeFragment({
+ data: { __typename: "Bar", i: 10 },
+ id: "bar",
+ fragment: gql`fragment fragmentBar on Bar { i e }`
});
- }, /Missing field e/);
+ }, /missing field e/);
});
});
- describe('write then read', () => {
- it('will write data locally which will then be read back', () => {
+ describe("write then read", () => {
+ it("will write data locally which will then be read back", () => {
const client = new ApolloClient({
initialState: {
apollo: {
data: {
- 'foo': {
- __typename: 'Foo',
+ foo: {
+ __typename: "Foo",
a: 1,
b: 2,
c: 3,
bar: {
- type: 'id',
- id: '$foo.bar',
- generated: true,
- },
+ type: "id",
+ id: "$foo.bar",
+ generated: true
+ }
},
- '$foo.bar': {
- __typename: 'Bar',
+ "$foo.bar": {
+ __typename: "Bar",
d: 4,
e: 5,
- f: 6,
- },
- },
- },
- },
+ f: 6
+ }
+ }
+ }
+ }
});
assert.deepEqual(
- client.readFragment({ id: 'foo', fragment: gql`fragment x on Foo { a b c bar { d e f } }` }),
- { __typename: 'Foo', a: 1, b: 2, c: 3, bar: { d: 4, e: 5, f: 6, __typename: 'Bar' } },
+ client.readFragment({
+ id: "foo",
+ fragment: gql`fragment x on Foo { a b c bar { d e f } }`
+ }),
+ {
+ __typename: "Foo",
+ a: 1,
+ b: 2,
+ c: 3,
+ bar: { d: 4, e: 5, f: 6, __typename: "Bar" }
+ }
);
client.writeFragment({
- id: 'foo',
+ id: "foo",
fragment: gql`fragment x on Foo { a }`,
- data: { __typename: 'Foo', a: 7 },
+ data: { __typename: "Foo", a: 7 }
});
assert.deepEqual(
- client.readFragment({ id: 'foo', fragment: gql`fragment x on Foo { a b c bar { d e f } }` }),
- { __typename: 'Foo', a: 7, b: 2, c: 3, bar: { __typename: 'Bar', d: 4, e: 5, f: 6 } },
+ client.readFragment({
+ id: "foo",
+ fragment: gql`fragment x on Foo { a b c bar { d e f } }`
+ }),
+ {
+ __typename: "Foo",
+ a: 7,
+ b: 2,
+ c: 3,
+ bar: { __typename: "Bar", d: 4, e: 5, f: 6 }
+ }
);
client.writeFragment({
- id: 'foo',
+ id: "foo",
fragment: gql`fragment x on Foo { bar { d } }`,
- data: { __typename: 'Foo', bar: { __typename: 'Bar', d: 8 } },
+ data: { __typename: "Foo", bar: { __typename: "Bar", d: 8 } }
});
assert.deepEqual(
- client.readFragment({ id: 'foo', fragment: gql`fragment x on Foo { a b c bar { d e f } }` }),
- { __typename: 'Foo', a: 7, b: 2, c: 3, bar: { __typename: 'Bar', d: 8, e: 5, f: 6 } },
+ client.readFragment({
+ id: "foo",
+ fragment: gql`fragment x on Foo { a b c bar { d e f } }`
+ }),
+ {
+ __typename: "Foo",
+ a: 7,
+ b: 2,
+ c: 3,
+ bar: { __typename: "Bar", d: 8, e: 5, f: 6 }
+ }
);
client.writeFragment({
- id: '$foo.bar',
+ id: "$foo.bar",
fragment: gql`fragment y on Bar { e }`,
- data: { __typename: 'Bar', e: 9 },
+ data: { __typename: "Bar", e: 9 }
});
assert.deepEqual(
- client.readFragment({ id: 'foo', fragment: gql`fragment x on Foo { a b c bar { d e f } }` }),
- { __typename: 'Foo', a: 7, b: 2, c: 3, bar: { __typename: 'Bar', d: 8, e: 9, f: 6 } },
+ client.readFragment({
+ id: "foo",
+ fragment: gql`fragment x on Foo { a b c bar { d e f } }`
+ }),
+ {
+ __typename: "Foo",
+ a: 7,
+ b: 2,
+ c: 3,
+ bar: { __typename: "Bar", d: 8, e: 9, f: 6 }
+ }
);
assert.deepEqual(client.store.getState().apollo.data, {
- 'foo': {
- __typename: 'Foo',
+ foo: {
+ __typename: "Foo",
a: 7,
b: 2,
c: 3,
bar: {
- type: 'id',
- id: '$foo.bar',
- generated: true,
- },
+ type: "id",
+ id: "$foo.bar",
+ generated: true
+ }
},
- '$foo.bar': {
- __typename: 'Bar',
+ "$foo.bar": {
+ __typename: "Bar",
d: 8,
e: 9,
- f: 6,
- },
+ f: 6
+ }
});
});
- it('will write data to a specific id', () => {
+ it("will write data to a specific id", () => {
const client = new ApolloClient({
initialState: { apollo: { data: {} } },
- dataIdFromObject: (o: any) => o.key,
+ dataIdFromObject: (o: any) => o.key
});
client.writeQuery({
query: gql`{ a b foo { c d bar { key e f } } }`,
- data: { a: 1, b: 2, foo: { __typename: 'foo', c: 3, d: 4, bar: { key: 'foobar', __typename: 'bar', e: 5, f: 6 } } },
+ data: {
+ a: 1,
+ b: 2,
+ foo: {
+ __typename: "foo",
+ c: 3,
+ d: 4,
+ bar: { key: "foobar", __typename: "bar", e: 5, f: 6 }
+ }
+ }
});
assert.deepEqual(
client.readQuery({ query: gql`{ a b foo { c d bar { key e f } } }` }),
- { a: 1, b: 2, foo: { __typename: 'foo', c: 3, d: 4, bar: { __typename: 'bar', key: 'foobar', e: 5, f: 6 } } },
+ {
+ a: 1,
+ b: 2,
+ foo: {
+ __typename: "foo",
+ c: 3,
+ d: 4,
+ bar: { __typename: "bar", key: "foobar", e: 5, f: 6 }
+ }
+ }
);
assert.deepEqual(client.store.getState().apollo.data, {
- 'ROOT_QUERY': {
+ ROOT_QUERY: {
a: 1,
b: 2,
foo: {
- type: 'id',
- id: '$ROOT_QUERY.foo',
- generated: true,
- },
+ type: "id",
+ id: "$ROOT_QUERY.foo",
+ generated: true
+ }
},
- '$ROOT_QUERY.foo': {
- __typename: 'foo',
+ "$ROOT_QUERY.foo": {
+ __typename: "foo",
c: 3,
d: 4,
bar: {
- type: 'id',
- id: 'foobar',
- generated: false,
- },
+ type: "id",
+ id: "foobar",
+ generated: false
+ }
},
- 'foobar': {
- key: 'foobar',
- __typename: 'bar',
+ foobar: {
+ key: "foobar",
+ __typename: "bar",
e: 5,
- f: 6,
- },
+ f: 6
+ }
});
});
-
- it('will not use a default id getter if __typename is not present', () => {
+ it("will not use a default id getter if __typename is not present", () => {
const client = new ApolloClient({
initialState: { apollo: { data: {} } },
- addTypename: false,
+ addTypename: false
});
client.writeQuery({
query: gql`{ a b foo { c d bar { id e f } } }`,
- data: { a: 1, b: 2, foo: { c: 3, d: 4, bar: { id: 'foobar', e: 5, f: 6 } } },
+ data: {
+ a: 1,
+ b: 2,
+ foo: { c: 3, d: 4, bar: { id: "foobar", e: 5, f: 6 } }
+ }
});
client.writeQuery({
query: gql`{ g h bar { i j foo { _id k l } } }`,
- data: { g: 8, h: 9, bar: { i: 10, j: 11, foo: { _id: 'barfoo', k: 12, l: 13 } } },
+ data: {
+ g: 8,
+ h: 9,
+ bar: { i: 10, j: 11, foo: { _id: "barfoo", k: 12, l: 13 } }
+ }
});
assert.deepEqual(client.store.getState().apollo.data, {
- 'ROOT_QUERY': {
+ ROOT_QUERY: {
a: 1,
b: 2,
@@ -891,63 +1075,80 @@
h: 9,
bar: {
- type: 'id',
- id: '$ROOT_QUERY.bar',
- generated: true,
+ type: "id",
+ id: "$ROOT_QUERY.bar",
+ generated: true
},
foo: {
- type: 'id',
- id: '$ROOT_QUERY.foo',
- generated: true,
- },
+ type: "id",
+ id: "$ROOT_QUERY.foo",
+ generated: true
+ }
},
- '$ROOT_QUERY.foo': {
+ "$ROOT_QUERY.foo": {
c: 3,
d: 4,
bar: {
- type: 'id',
- id: '$ROOT_QUERY.foo.bar',
- generated: true,
- },
+ type: "id",
+ id: "$ROOT_QUERY.foo.bar",
+ generated: true
+ }
},
- '$ROOT_QUERY.bar': {
+ "$ROOT_QUERY.bar": {
i: 10,
j: 11,
foo: {
- type: 'id',
- id: '$ROOT_QUERY.bar.foo',
- generated: true,
- },
+ type: "id",
+ id: "$ROOT_QUERY.bar.foo",
+ generated: true
+ }
},
- '$ROOT_QUERY.foo.bar': {
- id: 'foobar',
+ "$ROOT_QUERY.foo.bar": {
+ id: "foobar",
e: 5,
- f: 6,
+ f: 6
},
- '$ROOT_QUERY.bar.foo': {
- _id: 'barfoo',
+ "$ROOT_QUERY.bar.foo": {
+ _id: "barfoo",
k: 12,
- l: 13,
- },
+ l: 13
+ }
});
});
-
- it('will not use a default id getter if id and _id are not present', () => {
+ it("will not use a default id getter if id and _id are not present", () => {
const client = new ApolloClient({
- initialState: { apollo: { data: {} } },
+ initialState: { apollo: { data: {} } }
});
client.writeQuery({
query: gql`{ a b foo { c d bar { e f } } }`,
- data: { a: 1, b: 2, foo: { __typename: 'foo', c: 3, d: 4, bar: { __typename: 'bar', e: 5, f: 6 } } },
+ data: {
+ a: 1,
+ b: 2,
+ foo: {
+ __typename: "foo",
+ c: 3,
+ d: 4,
+ bar: { __typename: "bar", e: 5, f: 6 }
+ }
+ }
});
client.writeQuery({
query: gql`{ g h bar { i j foo { k l } } }`,
- data: { g: 8, h: 9, bar: { __typename: 'bar', i: 10, j: 11, foo: { __typename: 'foo', k: 12, l: 13 } } },
+ data: {
+ g: 8,
+ h: 9,
+ bar: {
+ __typename: "bar",
+ i: 10,
+ j: 11,
+ foo: { __typename: "foo", k: 12, l: 13 }
+ }
+ }
});
assert.deepEqual(client.store.getState().apollo.data, {
- 'ROOT_QUERY': {
+ ROOT_QUERY: {
a: 1,
b: 2,
@@ -955,224 +1156,257 @@
h: 9,
bar: {
- type: 'id',
- id: '$ROOT_QUERY.bar',
- generated: true,
+ type: "id",
+ id: "$ROOT_QUERY.bar",
+ generated: true
},
foo: {
- type: 'id',
- id: '$ROOT_QUERY.foo',
- generated: true,
- },
+ type: "id",
+ id: "$ROOT_QUERY.foo",
+ generated: true
+ }
},
- '$ROOT_QUERY.foo': {
- __typename: 'foo',
+ "$ROOT_QUERY.foo": {
+ __typename: "foo",
c: 3,
d: 4,
bar: {
- type: 'id',
- id: '$ROOT_QUERY.foo.bar',
- generated: true,
- },
+ type: "id",
+ id: "$ROOT_QUERY.foo.bar",
+ generated: true
+ }
},
- '$ROOT_QUERY.bar': {
- __typename: 'bar',
+ "$ROOT_QUERY.bar": {
+ __typename: "bar",
i: 10,
j: 11,
foo: {
- type: 'id',
- id: '$ROOT_QUERY.bar.foo',
- generated: true,
- },
+ type: "id",
+ id: "$ROOT_QUERY.bar.foo",
+ generated: true
+ }
},
- '$ROOT_QUERY.foo.bar': {
- __typename: 'bar',
+ "$ROOT_QUERY.foo.bar": {
+ __typename: "bar",
e: 5,
- f: 6,
+ f: 6
},
- '$ROOT_QUERY.bar.foo': {
- __typename: 'foo',
+ "$ROOT_QUERY.bar.foo": {
+ __typename: "foo",
k: 12,
- l: 13,
- },
+ l: 13
+ }
});
});
-
- it('will use a default id getter if __typename and id are present', () => {
+ it("will use a default id getter if __typename and id are present", () => {
const client = new ApolloClient({
- initialState: { apollo: { data: {} } },
+ initialState: { apollo: { data: {} } }
});
client.writeQuery({
query: gql`{ a b foo { c d bar { id e f } } }`,
- data: { a: 1, b: 2, foo: { __typename: 'foo', c: 3, d: 4, bar: { __typename: 'bar', id: 'foobar', e: 5, f: 6 } } },
+ data: {
+ a: 1,
+ b: 2,
+ foo: {
+ __typename: "foo",
+ c: 3,
+ d: 4,
+ bar: { __typename: "bar", id: "foobar", e: 5, f: 6 }
+ }