Created
May 6, 2017 03:55
-
-
Save vjeux/8088979c0f53922c9948e8d8c693a0ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 } | |
+ } | |
+ } | |
}); | |
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: 'bar:foobar', | |
- generated: false, | |
- }, | |
+ type: "id", | |
+ id: "bar:foobar", | |
+ generated: false | |
+ } | |
}, | |
- 'bar:foobar': { | |
- id: 'foobar', | |
- __typename: 'bar', | |
+ "bar:foobar": { | |
+ id: "foobar", | |
+ __typename: "bar", | |
e: 5, | |
- f: 6, | |
- }, | |
+ f: 6 | |
+ } | |
}); | |
}); | |
- | |
- 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 } | |
+ } | |
+ } | |
}); | |
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: 'bar:foobar', | |
- generated: false, | |
- }, | |
+ type: "id", | |
+ id: "bar:foobar", | |
+ generated: false | |
+ } | |
}, | |
- 'bar:foobar': { | |
- __typename: 'bar', | |
- _id: 'foobar', | |
+ "bar:foobar": { | |
+ __typename: "bar", | |
+ _id: "foobar", | |
e: 5, | |
- f: 6, | |
- }, | |
+ f: 6 | |
+ } | |
}); | |
}); | |
- | |
- it('will not use a default id getter if id is present and __typename is not present', () => { | |
+ it("will not use a default id getter if id is present and __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 } } | |
+ } | |
}); | |
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': { | |
+ "$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.foo.bar': { | |
- id: 'foobar', | |
+ "$ROOT_QUERY.foo.bar": { | |
+ id: "foobar", | |
e: 5, | |
- f: 6, | |
- }, | |
+ f: 6 | |
+ } | |
}); | |
}); | |
- | |
- it('will not use a default id getter if _id is present but __typename is not present', () => { | |
+ it("will not use a default id getter if _id is present but __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 } } | |
+ } | |
}); | |
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': { | |
+ "$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.foo.bar': { | |
- _id: 'foobar', | |
+ "$ROOT_QUERY.foo.bar": { | |
+ _id: "foobar", | |
e: 5, | |
- f: 6, | |
- }, | |
+ f: 6 | |
+ } | |
}); | |
}); | |
- | |
- it('will not use a default id getter if either _id or id is present when __typename is not also present', () => { | |
+ it("will not use a default id getter if either _id or id is present when __typename is not also 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: { __typename: 'bar', id: 'foobar', e: 5, f: 6 } } }, | |
+ data: { | |
+ a: 1, | |
+ b: 2, | |
+ foo: { | |
+ c: 3, | |
+ d: 4, | |
+ bar: { __typename: "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, | |
@@ -1180,63 +1414,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: 'bar:foobar', | |
- generated: false, | |
- }, | |
+ type: "id", | |
+ id: "bar:foobar", | |
+ generated: false | |
+ } | |
}, | |
- '$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 | |
+ } | |
}, | |
- 'bar:foobar': { | |
- id: 'foobar', | |
+ "bar:foobar": { | |
+ 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 use a default id getter if one is not specified and __typename is present along with either _id or id', () => { | |
+ it("will use a default id getter if one is not specified and __typename is present along with either _id or id", () => { | |
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 } | |
+ } | |
+ } | |
}); | |
client.writeQuery({ | |
query: gql`{ g h bar { i j foo { _id k l } } }`, | |
- data: { g: 8, h: 9, bar: { __typename: 'bar', i: 10, j: 11, foo: { __typename: 'foo', _id: 'barfoo', k: 12, l: 13 } } }, | |
+ data: { | |
+ g: 8, | |
+ h: 9, | |
+ bar: { | |
+ __typename: "bar", | |
+ i: 10, | |
+ j: 11, | |
+ foo: { __typename: "foo", _id: "barfoo", k: 12, l: 13 } | |
+ } | |
+ } | |
}); | |
assert.deepEqual(client.store.getState().apollo.data, { | |
- 'ROOT_QUERY': { | |
+ ROOT_QUERY: { | |
a: 1, | |
b: 2, | |
@@ -1244,49 +1495,48 @@ | |
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: 'bar:foobar', | |
- generated: false, | |
- }, | |
+ type: "id", | |
+ id: "bar:foobar", | |
+ generated: false | |
+ } | |
}, | |
- '$ROOT_QUERY.bar': { | |
- __typename: 'bar', | |
+ "$ROOT_QUERY.bar": { | |
+ __typename: "bar", | |
i: 10, | |
j: 11, | |
foo: { | |
- type: 'id', | |
- id: 'foo:barfoo', | |
- generated: false, | |
- }, | |
+ type: "id", | |
+ id: "foo:barfoo", | |
+ generated: false | |
+ } | |
}, | |
- 'bar:foobar': { | |
- __typename: 'bar', | |
- id: 'foobar', | |
+ "bar:foobar": { | |
+ __typename: "bar", | |
+ id: "foobar", | |
e: 5, | |
- f: 6, | |
+ f: 6 | |
}, | |
- 'foo:barfoo': { | |
- __typename: 'foo', | |
- _id: 'barfoo', | |
+ "foo:barfoo": { | |
+ __typename: "foo", | |
+ _id: "barfoo", | |
k: 12, | |
- l: 13, | |
- }, | |
+ l: 13 | |
+ } | |
}); | |
}); | |
}); | |
}); | |
- | |
./test/assign.ts | |
./test/batchedNetworkInterface.ts | |
./test/batchedNetworkInterface.ts: { index: 8171, | |
lineNumber: 328, | |
column: 49, | |
message: '\';\' expected.' } | |
./test/batching.ts | |
./test/client.ts | |
./test/client.ts: { index: 35410, | |
lineNumber: 1510, | |
column: 58, | |
message: '\',\' expected.' } | |
./test/cloneDeep.ts | |
./test/customResolvers.ts | |
./test/deduplicator.ts | |
./test/diffAgainstStore.ts | |
ast(input) !== ast(prettier(input)) | |
Index: | |
=================================================================== | |
--- | |
+++ | |
@@ -1077,5 +1077,5 @@ | |
"value": null, | |
"regex": { | |
- "pattern": "No fragment" | |
+ "pattern": "no fragment" | |
} | |
} | |
@@ -1103,5 +1103,5 @@ | |
"value": null, | |
"regex": { | |
- "pattern": "IntrospectionFragmentMatcher" | |
+ "pattern": "introspectionfragmentmatcher" | |
} | |
} | |
@@ -1465,5 +1465,5 @@ | |
"value": null, | |
"regex": { | |
- "pattern": "IntrospectionFragmentMatcher" | |
+ "pattern": "introspectionfragmentmatcher" | |
} | |
} | |
Index: | |
=================================================================== | |
--- | |
+++ | |
@@ -1,23 +1,16 @@ | |
-import { assert } from 'chai'; | |
+import { assert } from "chai"; | |
-import { | |
- diffQueryAgainstStore, | |
- ID_KEY, | |
-} from '../src/data/readFromStore'; | |
+import { diffQueryAgainstStore, ID_KEY } from "../src/data/readFromStore"; | |
-import { writeQueryToStore } from '../src/data/writeToStore'; | |
+import { writeQueryToStore } from "../src/data/writeToStore"; | |
-import gql from 'graphql-tag'; | |
-import { | |
- withError, | |
-} from './util/wrap'; | |
+import gql from "graphql-tag"; | |
+import { withError } from "./util/wrap"; | |
-import { | |
- HeuristicFragmentMatcher, | |
-} from '../src/data/fragmentMatcher'; | |
+import { HeuristicFragmentMatcher } from "../src/data/fragmentMatcher"; | |
const fragmentMatcherFunction = new HeuristicFragmentMatcher().match; | |
-describe('diffing queries against the store', () => { | |
- it('returns nothing when the store is enough', () => { | |
+describe("diffing queries against the store", () => { | |
+ it("returns nothing when the store is enough", () => { | |
const query = gql` | |
{ | |
@@ -30,20 +23,22 @@ | |
const result = { | |
people_one: { | |
- name: 'Luke Skywalker', | |
- }, | |
+ name: "Luke Skywalker" | |
+ } | |
}; | |
const store = writeQueryToStore({ | |
result, | |
- query, | |
+ query | |
}); | |
- assert.notOk(diffQueryAgainstStore({ | |
- store, | |
- query, | |
- }).isMissing); | |
+ assert.notOk( | |
+ diffQueryAgainstStore({ | |
+ store, | |
+ query | |
+ }).isMissing | |
+ ); | |
}); | |
- it('caches root queries both under the ID of the node and the query name', () => { | |
+ it("caches root queries both under the ID of the node and the query name", () => { | |
const firstQuery = gql` | |
{ | |
@@ -58,16 +53,16 @@ | |
const result = { | |
people_one: { | |
- __typename: 'Person', | |
- id: '1', | |
- name: 'Luke Skywalker', | |
- }, | |
+ __typename: "Person", | |
+ id: "1", | |
+ name: "Luke Skywalker" | |
+ } | |
}; | |
- const getIdField = ({id}: {id: string}) => id; | |
+ const getIdField = ({ id }: { id: string }) => id; | |
const store = writeQueryToStore({ | |
result, | |
query: firstQuery, | |
- dataIdFromObject: getIdField, | |
+ dataIdFromObject: getIdField | |
}); | |
@@ -84,13 +79,13 @@ | |
const { isMissing } = diffQueryAgainstStore({ | |
store, | |
- query: secondQuery, | |
+ query: secondQuery | |
}); | |
assert.notOk(isMissing); | |
- assert.deepEqual(store['1'], result.people_one); | |
+ assert.deepEqual(store["1"], result.people_one); | |
}); | |
- it('does not swallow errors other than field errors', (done) => { | |
- withError( () => { | |
+ it("does not swallow errors other than field errors", done => { | |
+ withError(() => { | |
const firstQuery = gql` | |
query { | |
@@ -101,10 +96,10 @@ | |
const firstResult = { | |
person: { | |
- powers: 'the force', | |
- }, | |
+ powers: "the force" | |
+ } | |
}; | |
const store = writeQueryToStore({ | |
result: firstResult, | |
- query: firstQuery, | |
+ query: firstQuery | |
}); | |
const unionQuery = gql` | |
@@ -115,12 +110,12 @@ | |
diffQueryAgainstStore({ | |
store, | |
- query: unionQuery, | |
+ query: unionQuery | |
}); | |
- }, /No fragment/); | |
+ }, /no fragment/); | |
done(); | |
- }, /IntrospectionFragmentMatcher/); | |
+ }, /introspectionfragmentmatcher/); | |
}); | |
- it('does not error on a correct query with union typed fragments', (done) => { | |
+ it("does not error on a correct query with union typed fragments", done => { | |
withError(() => { | |
const firstQuery = gql` | |
@@ -134,12 +129,12 @@ | |
const firstResult = { | |
person: { | |
- __typename: 'Author', | |
- firstName: 'John', | |
- lastName: 'Smith', | |
- }, | |
+ __typename: "Author", | |
+ firstName: "John", | |
+ lastName: "Smith" | |
+ } | |
}; | |
const store = writeQueryToStore({ | |
result: firstResult, | |
- query: firstQuery, | |
+ query: firstQuery | |
}); | |
const unionQuery = gql` | |
@@ -161,13 +156,13 @@ | |
query: unionQuery, | |
returnPartialData: false, | |
- fragmentMatcherFunction, | |
+ fragmentMatcherFunction | |
}); | |
assert.isTrue(isMissing); | |
done(); | |
- }, /IntrospectionFragmentMatcher/); | |
+ }, /introspectionfragmentmatcher/); | |
}); | |
- it('does not error on a query with fields missing from all but one named fragment', () => { | |
+ it("does not error on a query with fields missing from all but one named fragment", () => { | |
const firstQuery = gql` | |
query { | |
@@ -180,12 +175,12 @@ | |
const firstResult = { | |
person: { | |
- __typename: 'Author', | |
- firstName: 'John', | |
- lastName: 'Smith', | |
- }, | |
+ __typename: "Author", | |
+ firstName: "John", | |
+ lastName: "Smith" | |
+ } | |
}; | |
const store = writeQueryToStore({ | |
result: firstResult, | |
- query: firstQuery, | |
+ query: firstQuery | |
}); | |
const unionQuery = gql` | |
@@ -206,5 +201,5 @@ | |
const { isMissing } = diffQueryAgainstStore({ | |
store, | |
- query: unionQuery, | |
+ query: unionQuery | |
}); | |
@@ -212,5 +207,5 @@ | |
}); | |
- it('throws an error on a query with fields missing from matching named fragments', () => { | |
+ it("throws an error on a query with fields missing from matching named fragments", () => { | |
const firstQuery = gql` | |
query { | |
@@ -223,12 +218,12 @@ | |
const firstResult = { | |
person: { | |
- __typename: 'Author', | |
- firstName: 'John', | |
- lastName: 'Smith', | |
- }, | |
+ __typename: "Author", | |
+ firstName: "John", | |
+ lastName: "Smith" | |
+ } | |
}; | |
const store = writeQueryToStore({ | |
result: firstResult, | |
- query: firstQuery, | |
+ query: firstQuery | |
}); | |
const unionQuery = gql` | |
@@ -251,10 +246,10 @@ | |
store, | |
query: unionQuery, | |
- returnPartialData: false, | |
+ returnPartialData: false | |
}); | |
}); | |
}); | |
- it('returns available fields if returnPartialData is true', () => { | |
+ it("returns available fields if returnPartialData is true", () => { | |
const firstQuery = gql` | |
{ | |
@@ -269,13 +264,13 @@ | |
const firstResult = { | |
people_one: { | |
- __typename: 'Person', | |
- id: 'lukeId', | |
- name: 'Luke Skywalker', | |
- }, | |
+ __typename: "Person", | |
+ id: "lukeId", | |
+ name: "Luke Skywalker" | |
+ } | |
}; | |
const store = writeQueryToStore({ | |
result: firstResult, | |
- query: firstQuery, | |
+ query: firstQuery | |
}); | |
@@ -315,33 +310,33 @@ | |
const simpleDiff = diffQueryAgainstStore({ | |
store, | |
- query: simpleQuery, | |
+ query: simpleQuery | |
}); | |
assert.deepEqual(simpleDiff.result, { | |
people_one: { | |
- name: 'Luke Skywalker', | |
- }, | |
+ name: "Luke Skywalker" | |
+ } | |
}); | |
const inlineDiff = diffQueryAgainstStore({ | |
store, | |
- query: inlineFragmentQuery, | |
+ query: inlineFragmentQuery | |
}); | |
assert.deepEqual(inlineDiff.result, { | |
people_one: { | |
- name: 'Luke Skywalker', | |
- }, | |
+ name: "Luke Skywalker" | |
+ } | |
}); | |
const namedDiff = diffQueryAgainstStore({ | |
store, | |
- query: namedFragmentQuery, | |
+ query: namedFragmentQuery | |
}); | |
assert.deepEqual(namedDiff.result, { | |
people_one: { | |
- name: 'Luke Skywalker', | |
- }, | |
+ name: "Luke Skywalker" | |
+ } | |
}); | |
@@ -350,10 +345,10 @@ | |
store, | |
query: simpleQuery, | |
- returnPartialData: false, | |
+ returnPartialData: false | |
}); | |
}); | |
}); | |
- it('will add a private id property', () => { | |
+ it("will add a private id property", () => { | |
const query = gql` | |
query { | |
@@ -364,20 +359,16 @@ | |
const queryResult = { | |
- a: [ | |
- { id: 'a:1', b: 1.1 }, | |
- { id: 'a:2', b: 1.2 }, | |
- { id: 'a:3', b: 1.3 }, | |
- ], | |
+ a: [{ id: "a:1", b: 1.1 }, { id: "a:2", b: 1.2 }, { id: "a:3", b: 1.3 }], | |
c: { | |
d: 2, | |
e: [ | |
- { id: 'e:1', f: 3.1 }, | |
- { id: 'e:2', f: 3.2 }, | |
- { id: 'e:3', f: 3.3 }, | |
- { id: 'e:4', f: 3.4 }, | |
- { id: 'e:5', f: 3.5 }, | |
+ { id: "e:1", f: 3.1 }, | |
+ { id: "e:2", f: 3.2 }, | |
+ { id: "e:3", f: 3.3 }, | |
+ { id: "e:4", f: 3.4 }, | |
+ { id: "e:5", f: 3.5 } | |
], | |
- g: { h: 4 }, | |
- }, | |
+ g: { h: 4 } | |
+ } | |
}; | |
@@ -385,28 +376,28 @@ | |
query, | |
result: queryResult, | |
- dataIdFromObject: ({ id }: { id: string }) => id, | |
+ dataIdFromObject: ({ id }: { id: string }) => id | |
}); | |
const { result } = diffQueryAgainstStore({ | |
store, | |
- query, | |
+ query | |
}); | |
assert.deepEqual(result, queryResult); | |
- assert.equal(result[ID_KEY], 'ROOT_QUERY'); | |
- assert.equal(result.a[0][ID_KEY], 'a:1'); | |
- assert.equal(result.a[1][ID_KEY], 'a:2'); | |
- assert.equal(result.a[2][ID_KEY], 'a:3'); | |
- assert.equal(result.c[ID_KEY], '$ROOT_QUERY.c'); | |
- assert.equal(result.c.e[0][ID_KEY], 'e:1'); | |
- assert.equal(result.c.e[1][ID_KEY], 'e:2'); | |
- assert.equal(result.c.e[2][ID_KEY], 'e:3'); | |
- assert.equal(result.c.e[3][ID_KEY], 'e:4'); | |
- assert.equal(result.c.e[4][ID_KEY], 'e:5'); | |
- assert.equal(result.c.g[ID_KEY], '$ROOT_QUERY.c.g'); | |
+ assert.equal(result[ID_KEY], "ROOT_QUERY"); | |
+ assert.equal(result.a[0][ID_KEY], "a:1"); | |
+ assert.equal(result.a[1][ID_KEY], "a:2"); | |
+ assert.equal(result.a[2][ID_KEY], "a:3"); | |
+ assert.equal(result.c[ID_KEY], "$ROOT_QUERY.c"); | |
+ assert.equal(result.c.e[0][ID_KEY], "e:1"); | |
+ assert.equal(result.c.e[1][ID_KEY], "e:2"); | |
+ assert.equal(result.c.e[2][ID_KEY], "e:3"); | |
+ assert.equal(result.c.e[3][ID_KEY], "e:4"); | |
+ assert.equal(result.c.e[4][ID_KEY], "e:5"); | |
+ assert.equal(result.c.g[ID_KEY], "$ROOT_QUERY.c.g"); | |
}); | |
- describe('referential equality preservation', () => { | |
- it('will return the previous result if there are no changes', () => { | |
+ describe("referential equality preservation", () => { | |
+ it("will return the previous result if there are no changes", () => { | |
const query = gql` | |
query { | |
@@ -418,15 +409,15 @@ | |
const queryResult = { | |
a: { b: 1 }, | |
- c: { d: 2, e: { f: 3 } }, | |
+ c: { d: 2, e: { f: 3 } } | |
}; | |
const store = writeQueryToStore({ | |
query, | |
- result: queryResult, | |
+ result: queryResult | |
}); | |
const previousResult = { | |
a: { b: 1 }, | |
- c: { d: 2, e: { f: 3 } }, | |
+ c: { d: 2, e: { f: 3 } } | |
}; | |
@@ -434,5 +425,5 @@ | |
store, | |
query, | |
- previousResult, | |
+ previousResult | |
}); | |
@@ -441,5 +432,5 @@ | |
}); | |
- it('will return parts of the previous result that changed', () => { | |
+ it("will return parts of the previous result that changed", () => { | |
const query = gql` | |
query { | |
@@ -451,15 +442,15 @@ | |
const queryResult = { | |
a: { b: 1 }, | |
- c: { d: 2, e: { f: 3 } }, | |
+ c: { d: 2, e: { f: 3 } } | |
}; | |
const store = writeQueryToStore({ | |
query, | |
- result: queryResult, | |
+ result: queryResult | |
}); | |
const previousResult = { | |
a: { b: 1 }, | |
- c: { d: 20, e: { f: 3 } }, | |
+ c: { d: 20, e: { f: 3 } } | |
}; | |
@@ -467,5 +458,5 @@ | |
store, | |
query, | |
- previousResult, | |
+ previousResult | |
}); | |
@@ -477,5 +468,5 @@ | |
}); | |
- it('will return the previous result if there are no changes in child arrays', () => { | |
+ it("will return the previous result if there are no changes in child arrays", () => { | |
const query = gql` | |
query { | |
@@ -487,15 +478,21 @@ | |
const queryResult = { | |
a: [{ b: 1.1 }, { b: 1.2 }, { b: 1.3 }], | |
- c: { d: 2, e: [{ f: 3.1 }, { f: 3.2 }, { f: 3.3 }, { f: 3.4 }, { f: 3.5 }] }, | |
+ c: { | |
+ d: 2, | |
+ e: [{ f: 3.1 }, { f: 3.2 }, { f: 3.3 }, { f: 3.4 }, { f: 3.5 }] | |
+ } | |
}; | |
const store = writeQueryToStore({ | |
query, | |
- result: queryResult, | |
+ result: queryResult | |
}); | |
const previousResult = { | |
a: [{ b: 1.1 }, { b: 1.2 }, { b: 1.3 }], | |
- c: { d: 2, e: [{ f: 3.1 }, { f: 3.2 }, { f: 3.3 }, { f: 3.4 }, { f: 3.5 }] }, | |
+ c: { | |
+ d: 2, | |
+ e: [{ f: 3.1 }, { f: 3.2 }, { f: 3.3 }, { f: 3.4 }, { f: 3.5 }] | |
+ } | |
}; | |
@@ -503,5 +500,5 @@ | |
store, | |
query, | |
- previousResult, | |
+ previousResult | |
}); | |
@@ -510,5 +507,5 @@ | |
}); | |
- it('will not add zombie items when previousResult starts with the same items', () => { | |
+ it("will not add zombie items when previousResult starts with the same items", () => { | |
const query = gql` | |
query { | |
@@ -518,14 +515,14 @@ | |
const queryResult = { | |
- a: [{ b: 1.1 }, { b: 1.2 }], | |
+ a: [{ b: 1.1 }, { b: 1.2 }] | |
}; | |
const store = writeQueryToStore({ | |
query, | |
- result: queryResult, | |
+ result: queryResult | |
}); | |
const previousResult = { | |
- a: [{ b: 1.1 }, { b: 1.2 }, { b: 1.3 }], | |
+ a: [{ b: 1.1 }, { b: 1.2 }, { b: 1.3 }] | |
}; | |
@@ -533,5 +530,5 @@ | |
store, | |
query, | |
- previousResult, | |
+ previousResult | |
}); | |
@@ -541,5 +538,5 @@ | |
}); | |
- it('will return the previous result if there are no changes in nested child arrays', () => { | |
+ it("will return the previous result if there are no changes in nested child arrays", () => { | |
const query = gql` | |
query { | |
@@ -551,15 +548,21 @@ | |
const queryResult = { | |
a: [[[[[{ b: 1.1 }, { b: 1.2 }, { b: 1.3 }]]]]], | |
- c: { d: 2, e: [[{ f: 3.1 }, { f: 3.2 }, { f: 3.3 }], [{ f: 3.4 }, { f: 3.5 }]] }, | |
+ c: { | |
+ d: 2, | |
+ e: [[{ f: 3.1 }, { f: 3.2 }, { f: 3.3 }], [{ f: 3.4 }, { f: 3.5 }]] | |
+ } | |
}; | |
const store = writeQueryToStore({ | |
query, | |
- result: queryResult, | |
+ result: queryResult | |
}); | |
const previousResult = { | |
a: [[[[[{ b: 1.1 }, { b: 1.2 }, { b: 1.3 }]]]]], | |
- c: { d: 2, e: [[{ f: 3.1 }, { f: 3.2 }, { f: 3.3 }], [{ f: 3.4 }, { f: 3.5 }]] }, | |
+ c: { | |
+ d: 2, | |
+ e: [[{ f: 3.1 }, { f: 3.2 }, { f: 3.3 }], [{ f: 3.4 }, { f: 3.5 }]] | |
+ } | |
}; | |
@@ -567,5 +570,5 @@ | |
store, | |
query, | |
- previousResult, | |
+ previousResult | |
}); | |
@@ -574,5 +577,5 @@ | |
}); | |
- it('will return parts of the previous result if there are changes in child arrays', () => { | |
+ it("will return parts of the previous result if there are changes in child arrays", () => { | |
const query = gql` | |
query { | |
@@ -584,15 +587,21 @@ | |
const queryResult = { | |
a: [{ b: 1.1 }, { b: 1.2 }, { b: 1.3 }], | |
- c: { d: 2, e: [{ f: 3.1 }, { f: 3.2 }, { f: 3.3 }, { f: 3.4 }, { f: 3.5 }] }, | |
+ c: { | |
+ d: 2, | |
+ e: [{ f: 3.1 }, { f: 3.2 }, { f: 3.3 }, { f: 3.4 }, { f: 3.5 }] | |
+ } | |
}; | |
const store = writeQueryToStore({ | |
query, | |
- result: queryResult, | |
+ result: queryResult | |
}); | |
const previousResult = { | |
a: [{ b: 1.1 }, { b: -1.2 }, { b: 1.3 }], | |
- c: { d: 20, e: [{ f: 3.1 }, { f: 3.2 }, { f: 3.3 }, { f: 3.4 }, { f: 3.5 }] }, | |
+ c: { | |
+ d: 20, | |
+ e: [{ f: 3.1 }, { f: 3.2 }, { f: 3.3 }, { f: 3.4 }, { f: 3.5 }] | |
+ } | |
}; | |
@@ -600,5 +609,5 @@ | |
store, | |
query, | |
- previousResult, | |
+ previousResult | |
}); | |
@@ -618,5 +627,5 @@ | |
}); | |
- it('will return the same items in a different order with `dataIdFromObject`', () => { | |
+ it("will return the same items in a different order with `dataIdFromObject`", () => { | |
const query = gql` | |
query { | |
@@ -628,19 +637,19 @@ | |
const queryResult = { | |
a: [ | |
- { id: 'a:1', b: 1.1 }, | |
- { id: 'a:2', b: 1.2 }, | |
- { id: 'a:3', b: 1.3 }, | |
+ { id: "a:1", b: 1.1 }, | |
+ { id: "a:2", b: 1.2 }, | |
+ { id: "a:3", b: 1.3 } | |
], | |
c: { | |
d: 2, | |
e: [ | |
- { id: 'e:1', f: 3.1 }, | |
- { id: 'e:2', f: 3.2 }, | |
- { id: 'e:3', f: 3.3 }, | |
- { id: 'e:4', f: 3.4 }, | |
- { id: 'e:5', f: 3.5 }, | |
+ { id: "e:1", f: 3.1 }, | |
+ { id: "e:2", f: 3.2 }, | |
+ { id: "e:3", f: 3.3 }, | |
+ { id: "e:4", f: 3.4 }, | |
+ { id: "e:5", f: 3.5 } | |
], | |
- g: { h: 4 }, | |
- }, | |
+ g: { h: 4 } | |
+ } | |
}; | |
@@ -648,24 +657,24 @@ | |
query, | |
result: queryResult, | |
- dataIdFromObject: ({ id }: { id: string }) => id, | |
+ dataIdFromObject: ({ id }: { id: string }) => id | |
}); | |
const previousResult = { | |
a: [ | |
- { id: 'a:3', b: 1.3, [ID_KEY]: 'a:3' }, | |
- { id: 'a:2', b: 1.2, [ID_KEY]: 'a:2' }, | |
- { id: 'a:1', b: 1.1, [ID_KEY]: 'a:1' }, | |
+ { id: "a:3", b: 1.3, [ID_KEY]: "a:3" }, | |
+ { id: "a:2", b: 1.2, [ID_KEY]: "a:2" }, | |
+ { id: "a:1", b: 1.1, [ID_KEY]: "a:1" } | |
], | |
c: { | |
d: 2, | |
e: [ | |
- { id: 'e:4', f: 3.4, [ID_KEY]: 'e:4' }, | |
- { id: 'e:2', f: 3.2, [ID_KEY]: 'e:2' }, | |
- { id: 'e:5', f: 3.5, [ID_KEY]: 'e:5' }, | |
- { id: 'e:3', f: 3.3, [ID_KEY]: 'e:3' }, | |
- { id: 'e:1', f: 3.1, [ID_KEY]: 'e:1' }, | |
+ { id: "e:4", f: 3.4, [ID_KEY]: "e:4" }, | |
+ { id: "e:2", f: 3.2, [ID_KEY]: "e:2" }, | |
+ { id: "e:5", f: 3.5, [ID_KEY]: "e:5" }, | |
+ { id: "e:3", f: 3.3, [ID_KEY]: "e:3" }, | |
+ { id: "e:1", f: 3.1, [ID_KEY]: "e:1" } | |
], | |
- g: { h: 4 }, | |
- }, | |
+ g: { h: 4 } | |
+ } | |
}; | |
@@ -673,5 +682,5 @@ | |
store, | |
query, | |
- previousResult, | |
+ previousResult | |
}); | |
@@ -692,5 +701,5 @@ | |
}); | |
- it('will return the same JSON scalar field object', () => { | |
+ it("will return the same JSON scalar field object", () => { | |
const query = gql` | |
{ | |
@@ -702,15 +711,15 @@ | |
const queryResult = { | |
a: { b: 1, c: { x: 2, y: 3, z: 4 } }, | |
- d: { e: 5, f: { x: 6, y: 7, z: 8 } }, | |
+ d: { e: 5, f: { x: 6, y: 7, z: 8 } } | |
}; | |
const store = writeQueryToStore({ | |
query, | |
- result: queryResult, | |
+ result: queryResult | |
}); | |
const previousResult = { | |
a: { b: 1, c: { x: 2, y: 3, z: 4 } }, | |
- d: { e: 50, f: { x: 6, y: 7, z: 8 } }, | |
+ d: { e: 50, f: { x: 6, y: 7, z: 8 } } | |
}; | |
@@ -718,5 +727,5 @@ | |
store, | |
query, | |
- previousResult, | |
+ previousResult | |
}); | |
./test/directives.ts | |
./test/environment.ts | |
./test/errors.ts | |
./test/fetchMore.ts | |
prettier(input) !== prettier(prettier(input)) | |
Index: | |
=================================================================== | |
--- | |
+++ | |
@@ -258,5 +258,5 @@ | |
state.entry.comments = [ | |
...state.entry.comments, | |
- ...options.fetchMoreResult as any.entry.comments | |
+ ...options.fetchMoreResult as undefined.comments | |
]; | |
return state; | |
@@ -339,5 +339,5 @@ | |
case 0: | |
assert.equal(networkStatus, NetworkStatus.ready); | |
- assert.equal(data as any.entry.comments.length, 10); | |
+ assert.equal(data as undefined.length, 10); | |
observable.fetchMore({ | |
variables: { start: 10 }, | |
@@ -346,5 +346,5 @@ | |
state.entry.comments = [ | |
...state.entry.comments, | |
- ...options.fetchMoreResult as any.entry.comments | |
+ ...options.fetchMoreResult as undefined.comments | |
]; | |
return state; | |
@@ -354,13 +354,13 @@ | |
case 1: | |
assert.equal(networkStatus, NetworkStatus.fetchMore); | |
- assert.equal(data as any.entry.comments.length, 10); | |
+ assert.equal(data as undefined.length, 10); | |
break; | |
case 2: | |
assert.equal(networkStatus, NetworkStatus.ready); | |
- assert.equal(data as any.entry.comments.length, 10); | |
+ assert.equal(data as undefined.length, 10); | |
break; | |
case 3: | |
assert.equal(networkStatus, NetworkStatus.ready); | |
- assert.equal(data as any.entry.comments.length, 20); | |
+ assert.equal(data as undefined.length, 20); | |
done(); | |
break; | |
@@ -401,5 +401,5 @@ | |
case 0: | |
assert.equal(networkStatus, NetworkStatus.ready); | |
- assert.equal(data as any.entry.comments.length, 10); | |
+ assert.equal(data as undefined.length, 10); | |
observable.fetchMore({ | |
variables: { start: 10 }, | |
@@ -408,5 +408,5 @@ | |
state.entry.comments = [ | |
...state.entry.comments, | |
- ...options.fetchMoreResult as any.entry.comments | |
+ ...options.fetchMoreResult as undefined.comments | |
]; | |
return state; | |
@@ -416,5 +416,5 @@ | |
case 1: | |
assert.equal(networkStatus, NetworkStatus.fetchMore); | |
- assert.equal(data as any.entry.comments.length, 10); | |
+ assert.equal(data as undefined.length, 10); | |
break; | |
default: | |
./test/fixtures/redux-todomvc/actions.ts | |
./test/fixtures/redux-todomvc/index.ts | |
./test/fixtures/redux-todomvc/reducers.ts | |
./test/fixtures/redux-todomvc/types.ts | |
./test/fragmentMatcher.ts | |
./test/fragmentMatcher.ts: { index: 658, | |
lineNumber: 24, | |
column: 40, | |
message: '\',\' expected.' } | |
./test/getFromAST.ts | |
./test/graphqlSubscriptions.ts | |
ast(input) !== ast(prettier(input)) | |
Index: | |
=================================================================== | |
--- | |
+++ | |
@@ -1830,23 +1830,26 @@ | |
}, | |
"init": { | |
- "type": "MemberExpression", | |
- "object": { | |
- "type": "TSAsExpression", | |
- "expression": { | |
- "type": "Identifier", | |
- "name": "sub" | |
- }, | |
+ "type": "TSAsExpression", | |
+ "expression": { | |
+ "type": "Identifier", | |
+ "name": "sub" | |
+ }, | |
+ "typeAnnotation": { | |
+ "type": "TypeAnnotation", | |
"typeAnnotation": { | |
- "type": "TypeAnnotation", | |
- "typeAnnotation": { | |
- "type": "TSAnyKeyword" | |
+ "type": "TSTypeReference", | |
+ "typeName": { | |
+ "type": "JSXMemberExpression", | |
+ "object": { | |
+ "type": "JSXIdentifier", | |
+ "name": "any" | |
+ }, | |
+ "property": { | |
+ "type": "JSXIdentifier", | |
+ "name": "_networkSubscriptionId" | |
+ } | |
} | |
} | |
- }, | |
- "property": { | |
- "type": "Identifier", | |
- "name": "_networkSubscriptionId" | |
- }, | |
- "computed": false | |
+ } | |
} | |
} | |
@@ -2275,23 +2278,26 @@ | |
}, | |
"init": { | |
- "type": "MemberExpression", | |
- "object": { | |
- "type": "TSAsExpression", | |
- "expression": { | |
- "type": "Identifier", | |
- "name": "sub" | |
- }, | |
+ "type": "TSAsExpression", | |
+ "expression": { | |
+ "type": "Identifier", | |
+ "name": "sub" | |
+ }, | |
+ "typeAnnotation": { | |
+ "type": "TypeAnnotation", | |
"typeAnnotation": { | |
- "type": "TypeAnnotation", | |
- "typeAnnotation": { | |
- "type": "TSAnyKeyword" | |
+ "type": "TSTypeReference", | |
+ "typeName": { | |
+ "type": "JSXMemberExpression", | |
+ "object": { | |
+ "type": "JSXIdentifier", | |
+ "name": "any" | |
+ }, | |
+ "property": { | |
+ "type": "JSXIdentifier", | |
+ "name": "_networkSubscriptionId" | |
+ } | |
} | |
} | |
- }, | |
- "property": { | |
- "type": "Identifier", | |
- "name": "_networkSubscriptionId" | |
- }, | |
- "computed": false | |
+ } | |
} | |
} | |
Index: | |
=================================================================== | |
--- | |
+++ | |
@@ -1,30 +1,25 @@ | |
-import { | |
- mockSubscriptionNetworkInterface, | |
-} from './mocks/mockNetworkInterface'; | |
+import { mockSubscriptionNetworkInterface } from "./mocks/mockNetworkInterface"; | |
-import { | |
- assert, | |
-} from 'chai'; | |
+import { assert } from "chai"; | |
-import { cloneDeep } from 'lodash'; | |
+import { cloneDeep } from "lodash"; | |
-import { isSubscriptionResultAction } from '../src/actions'; | |
+import { isSubscriptionResultAction } from "../src/actions"; | |
-import ApolloClient from '../src'; | |
+import ApolloClient from "../src"; | |
-import gql from 'graphql-tag'; | |
+import gql from "graphql-tag"; | |
-import { | |
- QueryManager, | |
-} from '../src/core/QueryManager'; | |
+import { QueryManager } from "../src/core/QueryManager"; | |
-import { | |
- createApolloStore, | |
-} from '../src/store'; | |
+import { createApolloStore } from "../src/store"; | |
-describe('GraphQL Subscriptions', () => { | |
- const results = ['Dahivat Pandya', 'Vyacheslav Kim', 'Changping Chen', 'Amanda Liu'].map( | |
- name => ({ result: { user: { name: name } }, delay: 10 }), | |
- ); | |
+describe("GraphQL Subscriptions", () => { | |
+ const results = [ | |
+ "Dahivat Pandya", | |
+ "Vyacheslav Kim", | |
+ "Changping Chen", | |
+ "Amanda Liu" | |
+ ].map(name => ({ result: { user: { name: name } }, delay: 10 })); | |
let sub1: any; | |
@@ -41,5 +36,4 @@ | |
let commentsWatchQueryOptions: any; | |
beforeEach(() => { | |
- | |
sub1 = { | |
request: { | |
@@ -52,9 +46,9 @@ | |
`, | |
variables: { | |
- name: 'Changping Chen', | |
- }, | |
+ name: "Changping Chen" | |
+ } | |
}, | |
id: 0, | |
- results: [...results], | |
+ results: [...results] | |
}; | |
@@ -68,9 +62,8 @@ | |
`, | |
variables: { | |
- name: 'Changping Chen', | |
- }, | |
+ name: "Changping Chen" | |
+ } | |
}; | |
- | |
defaultSub1 = { | |
request: { | |
@@ -83,9 +76,9 @@ | |
`, | |
variables: { | |
- name: 'Changping Chen', | |
- }, | |
+ name: "Changping Chen" | |
+ } | |
}, | |
id: 0, | |
- results: [...results], | |
+ results: [...results] | |
}; | |
@@ -97,5 +90,5 @@ | |
} | |
} | |
- `, | |
+ ` | |
}; | |
@@ -109,6 +102,6 @@ | |
`, | |
variables: { | |
- name: 'Changping Chen', | |
- }, | |
+ name: "Changping Chen" | |
+ } | |
}; | |
@@ -131,10 +124,10 @@ | |
commentsVariables = { | |
- repoName: 'org/repo', | |
+ repoName: "org/repo" | |
}; | |
commentsWatchQueryOptions = { | |
query: commentsQuery, | |
- variables: commentsVariables, | |
+ variables: commentsVariables | |
}; | |
@@ -142,7 +135,7 @@ | |
data: { | |
entry: { | |
- comments: [], | |
- }, | |
- }, | |
+ comments: [] | |
+ } | |
+ } | |
}; | |
@@ -150,7 +143,7 @@ | |
result: { | |
entry: { | |
- comments: [], | |
- }, | |
- }, | |
+ comments: [] | |
+ } | |
+ } | |
}; | |
@@ -166,19 +159,16 @@ | |
request: { | |
query: commentsSub, | |
- variables: commentsVariables, | |
+ variables: commentsVariables | |
}, | |
id: 0, | |
- results: [commentsResultMore], | |
+ results: [commentsResultMore] | |
}; | |
- | |
}); | |
- | |
- it('should start a subscription on network interface and unsubscribe', (done) => { | |
+ it("should start a subscription on network interface and unsubscribe", done => { | |
const network = mockSubscriptionNetworkInterface([defaultSub1]); | |
- // This test calls directly through Apollo Client | |
const client = new ApolloClient({ | |
networkInterface: network, | |
- addTypename: false, | |
+ addTypename: false | |
}); | |
@@ -187,13 +177,12 @@ | |
assert.deepEqual(result, results[0].result); | |
- // Test unsubscribing | |
sub.unsubscribe(); | |
assert.equal(Object.keys(network.mockedSubscriptionsById).length, 0); | |
done(); | |
- }, | |
+ } | |
}); | |
- const id = (sub as any)._networkSubscriptionId; | |
+ const id = sub as any._networkSubscriptionId; | |
network.fireResult(id); | |
@@ -201,10 +190,9 @@ | |
}); | |
- it('should subscribe with default values', (done) => { | |
+ it("should subscribe with default values", done => { | |
const network = mockSubscriptionNetworkInterface([sub1]); | |
- // This test calls directly through Apollo Client | |
const client = new ApolloClient({ | |
networkInterface: network, | |
- addTypename: false, | |
+ addTypename: false | |
}); | |
@@ -213,13 +201,12 @@ | |
assert.deepEqual(result, results[0].result); | |
- // Test unsubscribing | |
sub.unsubscribe(); | |
assert.equal(Object.keys(network.mockedSubscriptionsById).length, 0); | |
done(); | |
- }, | |
+ } | |
}); | |
- const id = (sub as any)._networkSubscriptionId; | |
+ const id = sub as any._networkSubscriptionId; | |
network.fireResult(id); | |
@@ -227,5 +214,5 @@ | |
}); | |
- it('should multiplex subscriptions', (done) => { | |
+ it("should multiplex subscriptions", done => { | |
const network = mockSubscriptionNetworkInterface([sub1]); | |
const queryManager = new QueryManager({ | |
@@ -233,5 +220,5 @@ | |
reduxRootSelector: (state: any) => state.apollo, | |
store: createApolloStore(), | |
- addTypename: false, | |
+ addTypename: false | |
}); | |
@@ -247,8 +234,7 @@ | |
done(); | |
} | |
- }, | |
+ } | |
}) as any; | |
- // Subscribe again. Should also receive the same result. | |
const resub = obs.subscribe({ | |
next(result) { | |
@@ -258,5 +244,5 @@ | |
done(); | |
} | |
- }, | |
+ } | |
}) as any; | |
@@ -265,5 +251,5 @@ | |
}); | |
- it('should receive multiple results for a subscription', (done) => { | |
+ it("should receive multiple results for a subscription", done => { | |
const network = mockSubscriptionNetworkInterface([sub1]); | |
let numResults = 0; | |
@@ -272,5 +258,5 @@ | |
reduxRootSelector: (state: any) => state.apollo, | |
store: createApolloStore(), | |
- addTypename: false, | |
+ addTypename: false | |
}); | |
@@ -282,5 +268,5 @@ | |
done(); | |
} | |
- }, | |
+ } | |
}) as any; | |
@@ -292,5 +278,5 @@ | |
}); | |
- it('should fire redux action and call result reducers', (done) => { | |
+ it("should fire redux action and call result reducers", done => { | |
const query = gql` | |
query miniQuery { | |
@@ -301,11 +287,11 @@ | |
const res = { | |
data: { | |
- number: 0, | |
- }, | |
+ number: 0 | |
+ } | |
}; | |
const req1 = { | |
request: { query }, | |
- result: res, | |
+ result: res | |
}; | |
@@ -317,21 +303,23 @@ | |
reduxRootSelector: (state: any) => state.apollo, | |
store: createApolloStore(), | |
- addTypename: false, | |
+ addTypename: false | |
}); | |
- const observableQuery = queryManager.watchQuery({ | |
- query, | |
- reducer: (previousResult, action) => { | |
- counter++; | |
- if (isSubscriptionResultAction(action)) { | |
- const newResult = cloneDeep(previousResult) as any; | |
- newResult.number++; | |
- return newResult; | |
+ const observableQuery = queryManager | |
+ .watchQuery({ | |
+ query, | |
+ reducer: (previousResult, action) => { | |
+ counter++; | |
+ if (isSubscriptionResultAction(action)) { | |
+ const newResult = cloneDeep(previousResult) as any; | |
+ newResult.number++; | |
+ return newResult; | |
+ } | |
+ return previousResult; | |
} | |
- return previousResult; | |
- }, | |
- }).subscribe({ | |
- next: () => null, | |
- }); | |
+ }) | |
+ .subscribe({ | |
+ next: () => null | |
+ }); | |
const sub = queryManager.startGraphQLSubscription(options).subscribe({ | |
@@ -340,11 +328,15 @@ | |
numResults++; | |
if (numResults === 4) { | |
- // once for itself, four times for the subscription results. | |
observableQuery.unsubscribe(); | |
assert.equal(counter, 5); | |
- assert.equal(queryManager.store.getState()['apollo']['data']['ROOT_QUERY']['number'], 4); | |
+ assert.equal( | |
+ queryManager.store.getState()["apollo"]["data"]["ROOT_QUERY"][ | |
+ "number" | |
+ ], | |
+ 4 | |
+ ); | |
done(); | |
} | |
- }, | |
+ } | |
}) as any; | |
./test/isEqual.ts | |
./test/mockNetworkInterface.ts | |
./test/mocks/mockFetch.ts | |
./test/mocks/mockNetworkInterface.ts | |
./test/mocks/mockQueryManager.ts | |
./test/mocks/mockWatchQuery.ts | |
./test/mutationResults.ts | |
prettier(input) !== prettier(prettier(input)) | |
Index: | |
=================================================================== | |
--- | |
+++ | |
@@ -399,5 +399,5 @@ | |
updateQueries: { | |
todos: (prev, { mutationResult }) => { | |
- const newTodo = mutationResult as any.data.createTodo; | |
+ const newTodo = mutationResult as undefined.createTodo; | |
const newResults = { | |
@@ -729,5 +729,5 @@ | |
it('runs multiple reducers', () => { | |
- // TODO This test has sometimes failed on CI in the past, but I cannot reproduce it locally. | |
+ TODO This test has sometimes failed on CI in the past, but I cannot reproduce it locally. | |
// Could be some sort of race condition. Commenting it out for now, but this should be fixed. | |
// | |
./test/networkInterface.ts | |
./test/networkInterface.ts: { index: 7165, | |
lineNumber: 271, | |
column: 6, | |
message: 'Expression expected.' } | |
./test/ObservableQuery.ts | |
./test/ObservableQuery.ts: { index: 16248, | |
lineNumber: 553, | |
column: 36, | |
message: '\';\' expected.' } | |
./test/optimistic.ts | |
./test/optimistic.ts: { index: 56511, | |
lineNumber: 1938, | |
column: 41, | |
message: '\';\' expected.' } | |
./test/proxy.ts | |
./test/proxy.ts: { index: 11156, | |
lineNumber: 419, | |
column: 50, | |
message: '\',\' expected.' } | |
./test/QueryManager.ts | |
./test/QueryManager.ts: { index: 20858, | |
lineNumber: 935, | |
column: 52, | |
message: '\')\' expected.' } | |
./test/queryTransform.ts | |
./test/readFromStore.ts | |
ast(input) !== ast(prettier(input)) | |
Index: | |
=================================================================== | |
--- | |
+++ | |
@@ -3096,5 +3096,5 @@ | |
"value": null, | |
"regex": { | |
- "pattern": "IntrospectionFragmentMatcher" | |
+ "pattern": "introspectionfragmentmatcher" | |
} | |
} | |
@@ -5034,5 +5034,5 @@ | |
"value": null, | |
"regex": { | |
- "pattern": "field missingField on object" | |
+ "pattern": "field missingfield on object" | |
} | |
} | |
Index: | |
=================================================================== | |
--- | |
+++ | |
@@ -1,12 +1,8 @@ | |
-import { assert } from 'chai'; | |
-import { assign, omit } from 'lodash'; | |
+import { assert } from "chai"; | |
+import { assign, omit } from "lodash"; | |
-import { | |
- readQueryFromStore, | |
-} from '../src/data/readFromStore'; | |
+import { readQueryFromStore } from "../src/data/readFromStore"; | |
-import { | |
- withError, | |
-} from './util/wrap'; | |
+import { withError } from "./util/wrap"; | |
import { | |
@@ -15,17 +11,14 @@ | |
IdValue, | |
StoreValue, | |
- JsonValue, | |
-} from '../src/data/storeUtils'; | |
+ JsonValue | |
+} from "../src/data/storeUtils"; | |
-import { | |
- HeuristicFragmentMatcher, | |
-} from '../src/data/fragmentMatcher'; | |
+import { HeuristicFragmentMatcher } from "../src/data/fragmentMatcher"; | |
const fragmentMatcherFunction = new HeuristicFragmentMatcher().match; | |
-import gql from 'graphql-tag'; | |
+import gql from "graphql-tag"; | |
- | |
-describe('reading from the store', () => { | |
- it('rejects malformed queries', () => { | |
+describe("reading from the store", () => { | |
+ it("rejects malformed queries", () => { | |
assert.throws(() => { | |
readQueryFromStore({ | |
@@ -34,5 +27,5 @@ | |
query { name } | |
query { address } | |
- `, | |
+ ` | |
}); | |
}, /exactly one/); | |
@@ -43,19 +36,19 @@ | |
query: gql` | |
fragment x on y { name } | |
- `, | |
+ ` | |
}); | |
}, /contain a query/); | |
}); | |
- it('runs a basic query', () => { | |
+ it("runs a basic query", () => { | |
const result = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
- nullField: null, | |
+ nullField: null | |
} as StoreObject; | |
const store = { | |
- 'ROOT_QUERY': result, | |
+ ROOT_QUERY: result | |
} as NormalizedCache; | |
@@ -67,15 +60,15 @@ | |
numberField | |
} | |
- `, | |
+ ` | |
}); | |
// The result of the query shouldn't contain __data_id fields | |
assert.deepEqual(queryResult, { | |
- stringField: result['stringField'], | |
- numberField: result['numberField'], | |
+ stringField: result["stringField"], | |
+ numberField: result["numberField"] | |
}); | |
}); | |
- it('runs a basic query with arguments', () => { | |
+ it("runs a basic query with arguments", () => { | |
const query = gql` | |
query { | |
@@ -90,14 +83,14 @@ | |
intArg: 5, | |
floatArg: 3.14, | |
- stringArg: 'This is a string!', | |
+ stringArg: "This is a string!" | |
}; | |
const store = { | |
- 'ROOT_QUERY': { | |
- id: 'abcd', | |
+ ROOT_QUERY: { | |
+ id: "abcd", | |
nullField: null, | |
'numberField({"intArg":5,"floatArg":3.14})': 5, | |
- 'stringField({"arg":"This is a string!"})': 'Heyo', | |
- }, | |
+ 'stringField({"arg":"This is a string!"})': "Heyo" | |
+ } | |
} as NormalizedCache; | |
@@ -105,16 +98,16 @@ | |
store, | |
query, | |
- variables, | |
+ variables | |
}); | |
assert.deepEqual(result, { | |
- id: 'abcd', | |
+ id: "abcd", | |
nullField: null, | |
numberField: 5, | |
- stringField: 'Heyo', | |
+ stringField: "Heyo" | |
}); | |
}); | |
- it('runs a basic query with default values for arguments', () => { | |
+ it("runs a basic query with default values for arguments", () => { | |
const query = gql` | |
query someBigQuery( | |
@@ -131,14 +124,14 @@ | |
const variables = { | |
- floatArg: 3.14, | |
+ floatArg: 3.14 | |
}; | |
const store = { | |
- 'ROOT_QUERY': { | |
- id: 'abcd', | |
+ ROOT_QUERY: { | |
+ id: "abcd", | |
nullField: null, | |
'numberField({"intArg":0,"floatArg":3.14})': 5, | |
- 'stringField({"arg":"This is a default string!"})': 'Heyo', | |
- }, | |
+ 'stringField({"arg":"This is a default string!"})': "Heyo" | |
+ } | |
} as NormalizedCache; | |
@@ -146,38 +139,42 @@ | |
store, | |
query, | |
- variables, | |
+ variables | |
}); | |
assert.deepEqual(result, { | |
- id: 'abcd', | |
+ id: "abcd", | |
nullField: null, | |
numberField: 5, | |
- stringField: 'Heyo', | |
+ stringField: "Heyo" | |
}); | |
}); | |
- it('runs a nested query', () => { | |
+ it("runs a nested query", () => { | |
const result: any = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
nullField: null, | |
nestedObj: { | |
- id: 'abcde', | |
- stringField: 'This is a string too!', | |
+ id: "abcde", | |
+ stringField: "This is a string too!", | |
numberField: 6, | |
- nullField: null, | |
- } as StoreObject, | |
+ nullField: null | |
+ } as StoreObject | |
}; | |
const store = { | |
- 'ROOT_QUERY': assign({}, assign({}, omit(result, 'nestedObj')), { | |
- nestedObj: { | |
- type: 'id', | |
- id: 'abcde', | |
- generated: false, | |
- }, | |
- } as StoreObject), | |
- abcde: result.nestedObj, | |
+ ROOT_QUERY: assign( | |
+ {}, | |
+ assign({}, omit(result, "nestedObj")), | |
+ { | |
+ nestedObj: { | |
+ type: "id", | |
+ id: "abcde", | |
+ generated: false | |
+ } | |
+ } as StoreObject | |
+ ), | |
+ abcde: result.nestedObj | |
} as NormalizedCache; | |
@@ -193,56 +190,60 @@ | |
} | |
} | |
- `, | |
+ ` | |
}); | |
// The result of the query shouldn't contain __data_id fields | |
assert.deepEqual(queryResult, { | |
- stringField: 'This is a string!', | |
+ stringField: "This is a string!", | |
numberField: 5, | |
nestedObj: { | |
- stringField: 'This is a string too!', | |
- numberField: 6, | |
- }, | |
+ stringField: "This is a string too!", | |
+ numberField: 6 | |
+ } | |
}); | |
}); | |
- it('runs a nested query with multiple fragments', () => { | |
+ it("runs a nested query with multiple fragments", () => { | |
const result: any = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
nullField: null, | |
nestedObj: { | |
- id: 'abcde', | |
- stringField: 'This is a string too!', | |
+ id: "abcde", | |
+ stringField: "This is a string too!", | |
numberField: 6, | |
- nullField: null, | |
+ nullField: null | |
} as StoreObject, | |
deepNestedObj: { | |
- stringField: 'This is a deep string', | |
+ stringField: "This is a deep string", | |
numberField: 7, | |
- nullField: null, | |
+ nullField: null | |
} as StoreObject, | |
nullObject: null, | |
- __typename: 'Item', | |
+ __typename: "Item" | |
}; | |
const store = { | |
- 'ROOT_QUERY': assign({}, assign({}, omit(result, 'nestedObj', 'deepNestedObj')), { | |
- __typename: 'Query', | |
- nestedObj: { | |
- type: 'id', | |
- id: 'abcde', | |
- generated: false, | |
- }, | |
- } as StoreObject), | |
+ ROOT_QUERY: assign( | |
+ {}, | |
+ assign({}, omit(result, "nestedObj", "deepNestedObj")), | |
+ { | |
+ __typename: "Query", | |
+ nestedObj: { | |
+ type: "id", | |
+ id: "abcde", | |
+ generated: false | |
+ } | |
+ } as StoreObject | |
+ ), | |
abcde: assign({}, result.nestedObj, { | |
deepNestedObj: { | |
- type: 'id', | |
- id: 'abcdef', | |
- generated: false, | |
- }, | |
+ type: "id", | |
+ id: "abcdef", | |
+ generated: false | |
+ } | |
}) as StoreObject, | |
- abcdef: result.deepNestedObj as StoreObject, | |
+ abcdef: result.deepNestedObj as StoreObject | |
} as NormalizedCache; | |
@@ -278,41 +279,43 @@ | |
} | |
} | |
- `, | |
+ ` | |
}); | |
// The result of the query shouldn't contain __data_id fields | |
assert.deepEqual(queryResult, { | |
- stringField: 'This is a string!', | |
+ stringField: "This is a string!", | |
numberField: 5, | |
nullField: null, | |
nestedObj: { | |
- stringField: 'This is a string too!', | |
+ stringField: "This is a string too!", | |
numberField: 6, | |
nullField: null, | |
deepNestedObj: { | |
- stringField: 'This is a deep string', | |
+ stringField: "This is a deep string", | |
numberField: 7, | |
- nullField: null, | |
- }, | |
+ nullField: null | |
+ } | |
}, | |
- nullObject: null, | |
+ nullObject: null | |
}); | |
}); | |
- it('runs a nested query with proper fragment fields in arrays', (done) => { | |
+ it("runs a nested query with proper fragment fields in arrays", done => { | |
withError(() => { | |
const store = { | |
- 'ROOT_QUERY': { | |
- __typename: 'Query', | |
- nestedObj: { type: 'id', id: 'abcde', generated: false }, | |
+ ROOT_QUERY: { | |
+ __typename: "Query", | |
+ nestedObj: { type: "id", id: "abcde", generated: false } | |
} as StoreObject, | |
abcde: { | |
- id: 'abcde', | |
- innerArray: [{ type: 'id', generated: true, id: 'abcde.innerArray.0' } as any], | |
+ id: "abcde", | |
+ innerArray: [ | |
+ { type: "id", generated: true, id: "abcde.innerArray.0" } as any | |
+ ] | |
} as StoreObject, | |
- 'abcde.innerArray.0': { | |
- id: 'abcdef', | |
- someField: 3, | |
- } as StoreObject, | |
+ "abcde.innerArray.0": { | |
+ id: "abcdef", | |
+ someField: 3 | |
+ } as StoreObject | |
} as NormalizedCache; | |
@@ -338,46 +341,45 @@ | |
} | |
`, | |
- fragmentMatcherFunction, | |
+ fragmentMatcherFunction | |
}); | |
assert.deepEqual(queryResult, { | |
nestedObj: { | |
- innerArray: [{id: 'abcdef', someField: 3}], | |
- }, | |
+ innerArray: [{ id: "abcdef", someField: 3 }] | |
+ } | |
}); | |
done(); | |
- }, /IntrospectionFragmentMatcher/); | |
- | |
+ }, /introspectionfragmentmatcher/); | |
}); | |
- it('runs a nested query with an array without IDs', () => { | |
+ it("runs a nested query with an array without IDs", () => { | |
const result: any = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
nullField: null, | |
nestedArray: [ | |
{ | |
- stringField: 'This is a string too!', | |
+ stringField: "This is a string too!", | |
numberField: 6, | |
- nullField: null, | |
+ nullField: null | |
}, | |
{ | |
- stringField: 'This is a string also!', | |
+ stringField: "This is a string also!", | |
numberField: 7, | |
- nullField: null, | |
- }, | |
- ] as StoreObject[], | |
+ nullField: null | |
+ } | |
+ ] as StoreObject[] | |
}; | |
const store = { | |
- 'ROOT_QUERY': assign({}, assign({}, omit(result, 'nestedArray')), { | |
+ ROOT_QUERY: assign({}, assign({}, omit(result, "nestedArray")), { | |
nestedArray: [ | |
- { type: 'id', generated: true, id: 'abcd.nestedArray.0' } as IdValue, | |
- { type: 'id', generated: true, id: 'abcd.nestedArray.1' } as IdValue, | |
- ], | |
+ { type: "id", generated: true, id: "abcd.nestedArray.0" } as IdValue, | |
+ { type: "id", generated: true, id: "abcd.nestedArray.1" } as IdValue | |
+ ] | |
}) as StoreObject, | |
- 'abcd.nestedArray.0': result.nestedArray[0], | |
- 'abcd.nestedArray.1': result.nestedArray[1], | |
+ "abcd.nestedArray.0": result.nestedArray[0], | |
+ "abcd.nestedArray.1": result.nestedArray[1] | |
} as NormalizedCache; | |
@@ -393,28 +395,28 @@ | |
} | |
} | |
- `, | |
+ ` | |
}); | |
// The result of the query shouldn't contain __data_id fields | |
assert.deepEqual(queryResult, { | |
- stringField: 'This is a string!', | |
+ stringField: "This is a string!", | |
numberField: 5, | |
nestedArray: [ | |
{ | |
- stringField: 'This is a string too!', | |
- numberField: 6, | |
+ stringField: "This is a string too!", | |
+ numberField: 6 | |
}, | |
{ | |
- stringField: 'This is a string also!', | |
- numberField: 7, | |
- }, | |
- ], | |
+ stringField: "This is a string also!", | |
+ numberField: 7 | |
+ } | |
+ ] | |
}); | |
}); | |
- it('runs a nested query with an array without IDs and a null', () => { | |
+ it("runs a nested query with an array without IDs and a null", () => { | |
const result: any = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
nullField: null, | |
@@ -422,19 +424,19 @@ | |
null, | |
{ | |
- stringField: 'This is a string also!', | |
+ stringField: "This is a string also!", | |
numberField: 7, | |
- nullField: null, | |
- }, | |
- ] as StoreObject[], | |
+ nullField: null | |
+ } | |
+ ] as StoreObject[] | |
}; | |
const store = { | |
- 'ROOT_QUERY': assign({}, assign({}, omit(result, 'nestedArray')), { | |
+ ROOT_QUERY: assign({}, assign({}, omit(result, "nestedArray")), { | |
nestedArray: [ | |
null, | |
- { type: 'id', generated: true, id: 'abcd.nestedArray.1' } as IdValue, | |
- ], | |
+ { type: "id", generated: true, id: "abcd.nestedArray.1" } as IdValue | |
+ ] | |
}) as StoreObject, | |
- 'abcd.nestedArray.1': result.nestedArray[1], | |
+ "abcd.nestedArray.1": result.nestedArray[1] | |
} as NormalizedCache; | |
@@ -450,25 +452,25 @@ | |
} | |
} | |
- `, | |
+ ` | |
}); | |
// The result of the query shouldn't contain __data_id fields | |
assert.deepEqual(queryResult, { | |
- stringField: 'This is a string!', | |
+ stringField: "This is a string!", | |
numberField: 5, | |
nestedArray: [ | |
null, | |
{ | |
- stringField: 'This is a string also!', | |
- numberField: 7, | |
- }, | |
- ], | |
+ stringField: "This is a string also!", | |
+ numberField: 7 | |
+ } | |
+ ] | |
}); | |
}); | |
- it('runs a nested query with an array with IDs and a null', () => { | |
+ it("runs a nested query with an array with IDs and a null", () => { | |
const result: any = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
nullField: null, | |
@@ -476,20 +478,17 @@ | |
null, | |
{ | |
- id: 'abcde', | |
- stringField: 'This is a string also!', | |
+ id: "abcde", | |
+ stringField: "This is a string also!", | |
numberField: 7, | |
- nullField: null, | |
- }, | |
- ] as StoreObject[], | |
+ nullField: null | |
+ } | |
+ ] as StoreObject[] | |
}; | |
const store = { | |
- 'ROOT_QUERY': assign({}, assign({}, omit(result, 'nestedArray')), { | |
- nestedArray: [ | |
- null, | |
- { type: 'id', generated: false, id: 'abcde' }, | |
- ], | |
+ ROOT_QUERY: assign({}, assign({}, omit(result, "nestedArray")), { | |
+ nestedArray: [null, { type: "id", generated: false, id: "abcde" }] | |
}) as StoreObject, | |
- 'abcde': result.nestedArray[1], | |
+ abcde: result.nestedArray[1] | |
} as NormalizedCache; | |
@@ -506,31 +505,31 @@ | |
} | |
} | |
- `, | |
+ ` | |
}); | |
// The result of the query shouldn't contain __data_id fields | |
assert.deepEqual(queryResult, { | |
- stringField: 'This is a string!', | |
+ stringField: "This is a string!", | |
numberField: 5, | |
nestedArray: [ | |
null, | |
{ | |
- id: 'abcde', | |
- stringField: 'This is a string also!', | |
- numberField: 7, | |
- }, | |
- ], | |
+ id: "abcde", | |
+ stringField: "This is a string also!", | |
+ numberField: 7 | |
+ } | |
+ ] | |
}); | |
}); | |
- it('throws on a missing field', () => { | |
+ it("throws on a missing field", () => { | |
const result = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
- nullField: null, | |
+ nullField: null | |
} as StoreObject; | |
- const store = { 'ROOT_QUERY': result } as NormalizedCache; | |
+ const store = { ROOT_QUERY: result } as NormalizedCache; | |
assert.throws(() => { | |
@@ -542,20 +541,22 @@ | |
missingField | |
} | |
- `, | |
+ ` | |
}); | |
- }, /field missingField on object/); | |
+ }, /field missingfield on object/); | |
}); | |
- it('runs a nested query where the reference is null', () => { | |
+ it("runs a nested query where the reference is null", () => { | |
const result: any = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
nullField: null, | |
- nestedObj: null, | |
+ nestedObj: null | |
}; | |
const store = { | |
- 'ROOT_QUERY': assign({}, assign({}, omit(result, 'nestedObj')), { nestedObj: null }) as StoreObject, | |
+ ROOT_QUERY: assign({}, assign({}, omit(result, "nestedObj")), { | |
+ nestedObj: null | |
+ }) as StoreObject | |
} as NormalizedCache; | |
@@ -571,29 +572,31 @@ | |
} | |
} | |
- `, | |
+ ` | |
}); | |
// The result of the query shouldn't contain __data_id fields | |
assert.deepEqual(queryResult, { | |
- stringField: 'This is a string!', | |
+ stringField: "This is a string!", | |
numberField: 5, | |
- nestedObj: null, | |
+ nestedObj: null | |
}); | |
}); | |
- it('runs an array of non-objects', () => { | |
+ it("runs an array of non-objects", () => { | |
const result: any = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
nullField: null, | |
- simpleArray: ['one', 'two', 'three'], | |
+ simpleArray: ["one", "two", "three"] | |
}; | |
const store = { | |
- 'ROOT_QUERY': assign({}, assign({}, omit(result, 'simpleArray')), { simpleArray: { | |
- type: 'json', | |
- json: result.simpleArray, | |
- } as JsonValue }) as StoreObject, | |
+ ROOT_QUERY: assign({}, assign({}, omit(result, "simpleArray")), { | |
+ simpleArray: { | |
+ type: "json", | |
+ json: result.simpleArray | |
+ } as JsonValue | |
+ }) as StoreObject | |
} as NormalizedCache; | |
@@ -606,29 +609,31 @@ | |
simpleArray | |
} | |
- `, | |
+ ` | |
}); | |
// The result of the query shouldn't contain __data_id fields | |
assert.deepEqual(queryResult, { | |
- stringField: 'This is a string!', | |
+ stringField: "This is a string!", | |
numberField: 5, | |
- simpleArray: ['one', 'two', 'three'], | |
+ simpleArray: ["one", "two", "three"] | |
}); | |
}); | |
- it('runs an array of non-objects with null', () => { | |
+ it("runs an array of non-objects with null", () => { | |
const result: any = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
nullField: null, | |
- simpleArray: [null, 'two', 'three'], | |
+ simpleArray: [null, "two", "three"] | |
}; | |
const store = { | |
- 'ROOT_QUERY': assign({}, assign({}, omit(result, 'simpleArray')), { simpleArray: { | |
- type: 'json', | |
- json: result.simpleArray, | |
- } as JsonValue }) as StoreObject, | |
+ ROOT_QUERY: assign({}, assign({}, omit(result, "simpleArray")), { | |
+ simpleArray: { | |
+ type: "json", | |
+ json: result.simpleArray | |
+ } as JsonValue | |
+ }) as StoreObject | |
} as NormalizedCache; | |
@@ -641,26 +646,26 @@ | |
simpleArray | |
} | |
- `, | |
+ ` | |
}); | |
// The result of the query shouldn't contain __data_id fields | |
assert.deepEqual(queryResult, { | |
- stringField: 'This is a string!', | |
+ stringField: "This is a string!", | |
numberField: 5, | |
- simpleArray: [null, 'two', 'three'], | |
+ simpleArray: [null, "two", "three"] | |
}); | |
}); | |
- it('runs a query with custom resolvers for a computed field', () => { | |
+ it("runs a query with custom resolvers for a computed field", () => { | |
const result = { | |
- __typename: 'Thing', | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ __typename: "Thing", | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
- nullField: null, | |
+ nullField: null | |
} as StoreObject; | |
const store = { | |
- 'ROOT_QUERY': result, | |
+ ROOT_QUERY: result | |
} as NormalizedCache; | |
@@ -677,28 +682,29 @@ | |
customResolvers: { | |
Thing: { | |
- computedField: (obj, args) => obj.stringField + obj.numberField + args['extra'], | |
- }, | |
- }, | |
- }, | |
+ computedField: (obj, args) => | |
+ obj.stringField + obj.numberField + args["extra"] | |
+ } | |
+ } | |
+ } | |
}); | |
// The result of the query shouldn't contain __data_id fields | |
assert.deepEqual(queryResult, { | |
- stringField: result['stringField'], | |
- numberField: result['numberField'], | |
- computedField: 'This is a string!5bit', | |
+ stringField: result["stringField"], | |
+ numberField: result["numberField"], | |
+ computedField: "This is a string!5bit" | |
}); | |
}); | |
- it('runs a query with custom resolvers for a computed field on root Query', () => { | |
+ it("runs a query with custom resolvers for a computed field on root Query", () => { | |
const result = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
- nullField: null, | |
+ nullField: null | |
} as StoreObject; | |
const store = { | |
- 'ROOT_QUERY': result, | |
+ ROOT_QUERY: result | |
} as NormalizedCache; | |
@@ -715,61 +721,66 @@ | |
customResolvers: { | |
Query: { | |
- computedField: (obj, args) => obj.stringField + obj.numberField + args['extra'], | |
- }, | |
- }, | |
- }, | |
+ computedField: (obj, args) => | |
+ obj.stringField + obj.numberField + args["extra"] | |
+ } | |
+ } | |
+ } | |
}); | |
// The result of the query shouldn't contain __data_id fields | |
assert.deepEqual(queryResult, { | |
- stringField: result['stringField'], | |
- numberField: result['numberField'], | |
- computedField: 'This is a string!5bit', | |
+ stringField: result["stringField"], | |
+ numberField: result["numberField"], | |
+ computedField: "This is a string!5bit" | |
}); | |
}); | |
- it('will read from an arbitrary root id', () => { | |
+ it("will read from an arbitrary root id", () => { | |
const data: any = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
nullField: null, | |
nestedObj: { | |
- id: 'abcde', | |
- stringField: 'This is a string too!', | |
+ id: "abcde", | |
+ stringField: "This is a string too!", | |
numberField: 6, | |
- nullField: null, | |
+ nullField: null | |
} as StoreObject, | |
deepNestedObj: { | |
- stringField: 'This is a deep string', | |
+ stringField: "This is a deep string", | |
numberField: 7, | |
- nullField: null, | |
+ nullField: null | |
} as StoreObject, | |
nullObject: null, | |
- __typename: 'Item', | |
+ __typename: "Item" | |
}; | |
const store = { | |
- 'ROOT_QUERY': assign({}, assign({}, omit(data, 'nestedObj', 'deepNestedObj')), { | |
- __typename: 'Query', | |
- nestedObj: { | |
- type: 'id', | |
- id: 'abcde', | |
- generated: false, | |
- } as IdValue, | |
- }) as StoreObject, | |
+ ROOT_QUERY: assign( | |
+ {}, | |
+ assign({}, omit(data, "nestedObj", "deepNestedObj")), | |
+ { | |
+ __typename: "Query", | |
+ nestedObj: { | |
+ type: "id", | |
+ id: "abcde", | |
+ generated: false | |
+ } as IdValue | |
+ } | |
+ ) as StoreObject, | |
abcde: assign({}, data.nestedObj, { | |
deepNestedObj: { | |
- type: 'id', | |
- id: 'abcdef', | |
- generated: false, | |
- }, | |
+ type: "id", | |
+ id: "abcdef", | |
+ generated: false | |
+ } | |
}) as StoreObject, | |
- abcdef: data.deepNestedObj as StoreObject, | |
+ abcdef: data.deepNestedObj as StoreObject | |
} as NormalizedCache; | |
const queryResult1 = readQueryFromStore({ | |
store, | |
- rootId: 'abcde', | |
+ rootId: "abcde", | |
query: gql` | |
{ | |
@@ -783,21 +794,21 @@ | |
} | |
} | |
- `, | |
+ ` | |
}); | |
assert.deepEqual(queryResult1, { | |
- stringField: 'This is a string too!', | |
+ stringField: "This is a string too!", | |
numberField: 6, | |
nullField: null, | |
deepNestedObj: { | |
- stringField: 'This is a deep string', | |
+ stringField: "This is a deep string", | |
numberField: 7, | |
- nullField: null, | |
- }, | |
+ nullField: null | |
+ } | |
}); | |
const queryResult2 = readQueryFromStore({ | |
store, | |
- rootId: 'abcdef', | |
+ rootId: "abcdef", | |
query: gql` | |
{ | |
@@ -806,11 +817,11 @@ | |
nullField | |
} | |
- `, | |
+ ` | |
}); | |
assert.deepEqual(queryResult2, { | |
- stringField: 'This is a deep string', | |
+ stringField: "This is a deep string", | |
numberField: 7, | |
- nullField: null, | |
+ nullField: null | |
}); | |
}); | |
./test/roundtrip.ts | |
ast(input) !== ast(prettier(input)) | |
Index: | |
=================================================================== | |
--- | |
+++ | |
@@ -1784,5 +1784,5 @@ | |
"value": null, | |
"regex": { | |
- "pattern": "Can\\'t find field rank on object" | |
+ "pattern": "can\\'t find field rank on object" | |
} | |
} | |
@@ -1810,5 +1810,5 @@ | |
"value": null, | |
"regex": { | |
- "pattern": "IntrospectionFragmentMatcher" | |
+ "pattern": "introspectionfragmentmatcher" | |
} | |
} | |
@@ -2001,5 +2001,5 @@ | |
"value": null, | |
"regex": { | |
- "pattern": "IntrospectionFragmentMatcher" | |
+ "pattern": "introspectionfragmentmatcher" | |
} | |
} | |
@@ -2203,5 +2203,5 @@ | |
"value": null, | |
"regex": { | |
- "pattern": "IntrospectionFragmentMatcher" | |
+ "pattern": "introspectionfragmentmatcher" | |
} | |
} | |
@@ -2405,5 +2405,5 @@ | |
"value": null, | |
"regex": { | |
- "pattern": "IntrospectionFragmentMatcher" | |
+ "pattern": "introspectionfragmentmatcher" | |
} | |
} | |
@@ -2553,5 +2553,5 @@ | |
"value": null, | |
"regex": { | |
- "pattern": "Can\\'t find field rank on object" | |
+ "pattern": "can\\'t find field rank on object" | |
} | |
} | |
Index: | |
=================================================================== | |
--- | |
+++ | |
@@ -1,27 +1,24 @@ | |
-import { assert } from 'chai'; | |
+import { assert } from "chai"; | |
-import { writeQueryToStore } from '../src/data/writeToStore'; | |
-import { readQueryFromStore } from '../src/data/readFromStore'; | |
+import { writeQueryToStore } from "../src/data/writeToStore"; | |
+import { readQueryFromStore } from "../src/data/readFromStore"; | |
import { | |
getFragmentDefinitions, | |
- createFragmentMap, | |
-} from '../src/queries/getFromAST'; | |
+ createFragmentMap | |
+} from "../src/queries/getFromAST"; | |
-import { | |
- DocumentNode, | |
-} from 'graphql'; | |
+import { DocumentNode } from "graphql"; | |
-import gql from 'graphql-tag'; | |
+import gql from "graphql-tag"; | |
-import { withWarning, withError } from './util/wrap'; | |
+import { withWarning, withError } from "./util/wrap"; | |
-import { | |
- HeuristicFragmentMatcher, | |
-} from '../src/data/fragmentMatcher'; | |
+import { HeuristicFragmentMatcher } from "../src/data/fragmentMatcher"; | |
const fragmentMatcherFunction = new HeuristicFragmentMatcher().match; | |
-describe('roundtrip', () => { | |
- it('real graphql result', () => { | |
- storeRoundtrip(gql` | |
+describe("roundtrip", () => { | |
+ it("real graphql result", () => { | |
+ storeRoundtrip( | |
+ gql` | |
{ | |
people_one(id: "1") { | |
@@ -29,13 +26,16 @@ | |
} | |
} | |
- `, { | |
- people_one: { | |
- name: 'Luke Skywalker', | |
- }, | |
- }); | |
+ `, | |
+ { | |
+ people_one: { | |
+ name: "Luke Skywalker" | |
+ } | |
+ } | |
+ ); | |
}); | |
- it('multidimensional array (#776)', () => { | |
- storeRoundtrip(gql` | |
+ it("multidimensional array (#776)", () => { | |
+ storeRoundtrip( | |
+ gql` | |
{ | |
rows { | |
@@ -43,20 +43,14 @@ | |
} | |
} | |
- `, { | |
- rows: [ | |
- [ | |
- { value: 1 }, | |
- { value: 2 }, | |
- ], | |
- [ | |
- { value: 3 }, | |
- { value: 4 }, | |
- ], | |
- ], | |
- }); | |
+ `, | |
+ { | |
+ rows: [[{ value: 1 }, { value: 2 }], [{ value: 3 }, { value: 4 }]] | |
+ } | |
+ ); | |
}); | |
- it('array with null values (#1551)', () => { | |
- storeRoundtrip(gql` | |
+ it("array with null values (#1551)", () => { | |
+ storeRoundtrip( | |
+ gql` | |
{ | |
list { | |
@@ -64,14 +58,14 @@ | |
} | |
} | |
- `, { | |
- list: [ | |
- null, | |
- { value: 1 }, | |
- ], | |
- }); | |
+ `, | |
+ { | |
+ list: [null, { value: 1 }] | |
+ } | |
+ ); | |
}); | |
- it('enum arguments', () => { | |
- storeRoundtrip(gql` | |
+ it("enum arguments", () => { | |
+ storeRoundtrip( | |
+ gql` | |
{ | |
hero(episode: JEDI) { | |
@@ -79,13 +73,16 @@ | |
} | |
} | |
- `, { | |
- hero: { | |
- name: 'Luke Skywalker', | |
- }, | |
- }); | |
+ `, | |
+ { | |
+ hero: { | |
+ name: "Luke Skywalker" | |
+ } | |
+ } | |
+ ); | |
}); | |
- it('with an alias', () => { | |
- storeRoundtrip(gql` | |
+ it("with an alias", () => { | |
+ storeRoundtrip( | |
+ gql` | |
{ | |
luke: people_one(id: "1") { | |
@@ -96,16 +93,19 @@ | |
} | |
} | |
- `, { | |
- luke: { | |
- name: 'Luke Skywalker', | |
- }, | |
- vader: { | |
- name: 'Darth Vader', | |
- }, | |
- }); | |
+ `, | |
+ { | |
+ luke: { | |
+ name: "Luke Skywalker" | |
+ }, | |
+ vader: { | |
+ name: "Darth Vader" | |
+ } | |
+ } | |
+ ); | |
}); | |
- it('with variables', () => { | |
- storeRoundtrip(gql` | |
+ it("with variables", () => { | |
+ storeRoundtrip( | |
+ gql` | |
{ | |
luke: people_one(id: $lukeId) { | |
@@ -116,19 +116,23 @@ | |
} | |
} | |
- `, { | |
- luke: { | |
- name: 'Luke Skywalker', | |
+ `, | |
+ { | |
+ luke: { | |
+ name: "Luke Skywalker" | |
+ }, | |
+ vader: { | |
+ name: "Darth Vader" | |
+ } | |
}, | |
- vader: { | |
- name: 'Darth Vader', | |
- }, | |
- }, { | |
- lukeId: '1', | |
- vaderId: '4', | |
- }); | |
+ { | |
+ lukeId: "1", | |
+ vaderId: "4" | |
+ } | |
+ ); | |
}); | |
- it('with GraphQLJSON scalar type', () => { | |
- storeRoundtrip(gql` | |
+ it("with GraphQLJSON scalar type", () => { | |
+ storeRoundtrip( | |
+ gql` | |
{ | |
updateClub { | |
@@ -138,41 +142,50 @@ | |
} | |
} | |
- `, { | |
- updateClub: { | |
- uid: '1d7f836018fc11e68d809dfee940f657', | |
- name: 'Eple', | |
- settings: { | |
- name: 'eple', | |
- currency: 'AFN', | |
- calendarStretch: 2, | |
- defaultPreAllocationPeriod: 1, | |
- confirmationEmailCopy: null, | |
- emailDomains: null, | |
- }, | |
- }, | |
- }); | |
+ `, | |
+ { | |
+ updateClub: { | |
+ uid: "1d7f836018fc11e68d809dfee940f657", | |
+ name: "Eple", | |
+ settings: { | |
+ name: "eple", | |
+ currency: "AFN", | |
+ calendarStretch: 2, | |
+ defaultPreAllocationPeriod: 1, | |
+ confirmationEmailCopy: null, | |
+ emailDomains: null | |
+ } | |
+ } | |
+ } | |
+ ); | |
}); | |
- describe('directives', () => { | |
- it('should be able to query with skip directive true', () => { | |
- storeRoundtrip(gql` | |
+ describe("directives", () => { | |
+ it("should be able to query with skip directive true", () => { | |
+ storeRoundtrip( | |
+ gql` | |
query { | |
fortuneCookie @skip(if: true) | |
} | |
- `, {}); | |
+ `, | |
+ {} | |
+ ); | |
}); | |
- it('should be able to query with skip directive false', () => { | |
- storeRoundtrip(gql` | |
+ it("should be able to query with skip directive false", () => { | |
+ storeRoundtrip( | |
+ gql` | |
query { | |
fortuneCookie @skip(if: false) | |
} | |
- `, {fortuneCookie: 'live long and prosper'}); | |
+ `, | |
+ { fortuneCookie: "live long and prosper" } | |
+ ); | |
}); | |
}); | |
- describe('fragments', () => { | |
- it('should work on null fields', () => { | |
- storeRoundtrip(gql` | |
+ describe("fragments", () => { | |
+ it("should work on null fields", () => { | |
+ storeRoundtrip( | |
+ gql` | |
query { | |
field { | |
@@ -182,11 +195,14 @@ | |
} | |
} | |
- `, { | |
- field: null, | |
- }); | |
+ `, | |
+ { | |
+ field: null | |
+ } | |
+ ); | |
}); | |
- it('should work on basic inline fragments', () => { | |
- storeRoundtrip(gql` | |
+ it("should work on basic inline fragments", () => { | |
+ storeRoundtrip( | |
+ gql` | |
query { | |
field { | |
@@ -197,15 +213,18 @@ | |
} | |
} | |
- `, { | |
- field: { | |
- __typename: 'Obj', | |
- stuff: 'Result', | |
- }, | |
- }); | |
+ `, | |
+ { | |
+ field: { | |
+ __typename: "Obj", | |
+ stuff: "Result" | |
+ } | |
+ } | |
+ ); | |
}); | |
- it('should resolve on union types with inline fragments without typenames with warning', () => { | |
+ it("should resolve on union types with inline fragments without typenames with warning", () => { | |
return withWarning(() => { | |
- storeRoundtrip(gql` | |
+ storeRoundtrip( | |
+ gql` | |
query { | |
all_people { | |
@@ -218,16 +237,18 @@ | |
} | |
} | |
- }`, { | |
- all_people: [ | |
- { | |
- name: 'Luke Skywalker', | |
- side: 'bright', | |
- }, | |
- { | |
- name: 'R2D2', | |
- model: 'astromech', | |
- }, | |
- ], | |
- }); | |
+ }`, | |
+ { | |
+ all_people: [ | |
+ { | |
+ name: "Luke Skywalker", | |
+ side: "bright" | |
+ }, | |
+ { | |
+ name: "R2D2", | |
+ model: "astromech" | |
+ } | |
+ ] | |
+ } | |
+ ); | |
}, /using fragments/); | |
}); | |
@@ -235,8 +256,9 @@ | |
// XXX this test is weird because it assumes the server returned an incorrect result | |
// However, the user may have written this result with client.writeQuery. | |
- it('should throw an error on two of the same inline fragment types', (done) => { | |
+ it("should throw an error on two of the same inline fragment types", done => { | |
withError(() => { | |
assert.throws(() => { | |
- storeRoundtrip(gql` | |
+ storeRoundtrip( | |
+ gql` | |
query { | |
all_people { | |
@@ -250,21 +272,24 @@ | |
} | |
} | |
- }`, { | |
- all_people: [ | |
- { | |
- __typename: 'Jedi', | |
- name: 'Luke Skywalker', | |
- side: 'bright', | |
- }, | |
- ], | |
- }); | |
- }, /Can\'t find field rank on object/); | |
+ }`, | |
+ { | |
+ all_people: [ | |
+ { | |
+ __typename: "Jedi", | |
+ name: "Luke Skywalker", | |
+ side: "bright" | |
+ } | |
+ ] | |
+ } | |
+ ); | |
+ }, /can\'t find field rank on object/); | |
done(); | |
- }, /IntrospectionFragmentMatcher/); | |
+ }, /introspectionfragmentmatcher/); | |
}); | |
- it('should resolve fields it can on interface with non matching inline fragments', (done) => { | |
+ it("should resolve fields it can on interface with non matching inline fragments", done => { | |
withError(() => { | |
- storeRoundtrip(gql` | |
+ storeRoundtrip( | |
+ gql` | |
query { | |
dark_forces { | |
@@ -275,24 +300,27 @@ | |
} | |
} | |
- }`, { | |
- dark_forces: [ | |
- { | |
- __typename: 'Droid', | |
- name: '8t88', | |
- model: '88', | |
- }, | |
- { | |
- __typename: 'Darth', | |
- name: 'Anakin Skywalker', | |
- }, | |
- ], | |
- }); | |
+ }`, | |
+ { | |
+ dark_forces: [ | |
+ { | |
+ __typename: "Droid", | |
+ name: "8t88", | |
+ model: "88" | |
+ }, | |
+ { | |
+ __typename: "Darth", | |
+ name: "Anakin Skywalker" | |
+ } | |
+ ] | |
+ } | |
+ ); | |
done(); | |
- }, /IntrospectionFragmentMatcher/); | |
+ }, /introspectionfragmentmatcher/); | |
}); | |
- it('should resolve on union types with spread fragments', (done) => { | |
+ it("should resolve on union types with spread fragments", done => { | |
withError(() => { | |
- storeRoundtrip(gql` | |
+ storeRoundtrip( | |
+ gql` | |
fragment jediFragment on Jedi { | |
side | |
@@ -310,25 +338,28 @@ | |
...droidFragment | |
} | |
- }`, { | |
- all_people: [ | |
- { | |
- __typename: 'Jedi', | |
- name: 'Luke Skywalker', | |
- side: 'bright', | |
- }, | |
- { | |
- __typename: 'Droid', | |
- name: 'R2D2', | |
- model: 'astromech', | |
- }, | |
- ], | |
- }); | |
+ }`, | |
+ { | |
+ all_people: [ | |
+ { | |
+ __typename: "Jedi", | |
+ name: "Luke Skywalker", | |
+ side: "bright" | |
+ }, | |
+ { | |
+ __typename: "Droid", | |
+ name: "R2D2", | |
+ model: "astromech" | |
+ } | |
+ ] | |
+ } | |
+ ); | |
done(); | |
- }, /IntrospectionFragmentMatcher/); | |
+ }, /introspectionfragmentmatcher/); | |
}); | |
- it('should work with a fragment on the actual interface or union', (done) => { | |
+ it("should work with a fragment on the actual interface or union", done => { | |
withError(() => { | |
- storeRoundtrip(gql` | |
+ storeRoundtrip( | |
+ gql` | |
fragment jediFragment on Character { | |
side | |
@@ -346,25 +377,29 @@ | |
...droidFragment | |
} | |
- }`, { | |
- all_people: [ | |
- { | |
- __typename: 'Jedi', | |
- name: 'Luke Skywalker', | |
- side: 'bright', | |
- }, | |
- { | |
- __typename: 'Droid', | |
- name: 'R2D2', | |
- model: 'astromech', | |
- }, | |
- ], | |
- }); | |
+ }`, | |
+ { | |
+ all_people: [ | |
+ { | |
+ __typename: "Jedi", | |
+ name: "Luke Skywalker", | |
+ side: "bright" | |
+ }, | |
+ { | |
+ __typename: "Droid", | |
+ name: "R2D2", | |
+ model: "astromech" | |
+ } | |
+ ] | |
+ } | |
+ ); | |
done(); | |
- }, /IntrospectionFragmentMatcher/); | |
+ }, /introspectionfragmentmatcher/); | |
}); | |
- it('should throw on error on two of the same spread fragment types', () => { | |
- assert.throws(() => | |
- storeRoundtrip(gql` | |
+ it("should throw on error on two of the same spread fragment types", () => { | |
+ assert.throws( | |
+ () => | |
+ storeRoundtrip( | |
+ gql` | |
fragment jediSide on Jedi { | |
side | |
@@ -380,18 +415,22 @@ | |
...jediRank | |
} | |
- }`, { | |
- all_people: [ | |
+ }`, | |
{ | |
- __typename: 'Jedi', | |
- name: 'Luke Skywalker', | |
- side: 'bright', | |
- }, | |
- ], | |
- }) | |
- , /Can\'t find field rank on object/); | |
+ all_people: [ | |
+ { | |
+ __typename: "Jedi", | |
+ name: "Luke Skywalker", | |
+ side: "bright" | |
+ } | |
+ ] | |
+ } | |
+ ), | |
+ /can\'t find field rank on object/ | |
+ ); | |
}); | |
- it('should resolve on @include and @skip with inline fragments', () => { | |
- storeRoundtrip(gql` | |
+ it("should resolve on @include and @skip with inline fragments", () => { | |
+ storeRoundtrip( | |
+ gql` | |
query { | |
person { | |
@@ -405,15 +444,18 @@ | |
} | |
} | |
- }`, { | |
- person: { | |
- __typename: 'Jedi', | |
- name: 'Luke Skywalker', | |
- side: 'bright', | |
- }, | |
- }); | |
+ }`, | |
+ { | |
+ person: { | |
+ __typename: "Jedi", | |
+ name: "Luke Skywalker", | |
+ side: "bright" | |
+ } | |
+ } | |
+ ); | |
}); | |
- it('should resolve on @include and @skip with spread fragments', () => { | |
- storeRoundtrip(gql` | |
+ it("should resolve on @include and @skip with spread fragments", () => { | |
+ storeRoundtrip( | |
+ gql` | |
fragment jediFragment on Jedi { | |
side | |
@@ -431,11 +473,13 @@ | |
...droidFragment @skip(if: true) | |
} | |
- }`, { | |
- person: { | |
- __typename: 'Jedi', | |
- name: 'Luke Skywalker', | |
- side: 'bright', | |
- }, | |
- }); | |
+ }`, | |
+ { | |
+ person: { | |
+ __typename: "Jedi", | |
+ name: "Luke Skywalker", | |
+ side: "bright" | |
+ } | |
+ } | |
+ ); | |
}); | |
}); | |
@@ -448,5 +492,5 @@ | |
query, | |
variables, | |
- fragmentMap, | |
+ fragmentMap | |
}); | |
@@ -455,5 +499,5 @@ | |
query, | |
variables, | |
- fragmentMatcherFunction, | |
+ fragmentMatcherFunction | |
}); | |
./test/scheduler.ts | |
./test/scheduler.ts: { index: 8616, | |
lineNumber: 336, | |
column: 4, | |
message: 'Expression expected.' } | |
./test/store.ts | |
./test/subscribeToMore.ts | |
./test/tests.ts | |
./test/util/observableToPromise.ts | |
./test/util/subscribeAndCount.ts | |
./test/util/wrap.ts | |
./test/warnOnce.ts | |
./test/writeToStore.ts | |
ast(input) !== ast(prettier(input)) | |
Index: | |
=================================================================== | |
--- | |
+++ | |
@@ -10513,5 +10513,5 @@ | |
"value": null, | |
"regex": { | |
- "pattern": "No fragment" | |
+ "pattern": "no fragment" | |
} | |
} | |
@@ -11625,5 +11625,5 @@ | |
"value": null, | |
"regex": { | |
- "pattern": "Missing field description" | |
+ "pattern": "missing field description" | |
} | |
} | |
@@ -12298,5 +12298,5 @@ | |
"value": null, | |
"regex": { | |
- "pattern": "Missing field date" | |
+ "pattern": "missing field date" | |
} | |
} | |
Index: | |
=================================================================== | |
--- | |
+++ | |
@@ -1,4 +1,4 @@ | |
-import { assert } from 'chai'; | |
-import { cloneDeep, assign, omit } from 'lodash'; | |
+import { assert } from "chai"; | |
+import { cloneDeep, assign, omit } from "lodash"; | |
import { | |
@@ -7,39 +7,35 @@ | |
DefinitionNode, | |
OperationDefinitionNode, | |
- ASTNode, | |
-} from 'graphql'; | |
+ ASTNode | |
+} from "graphql"; | |
-import gql from 'graphql-tag'; | |
+import gql from "graphql-tag"; | |
-import { withWarning } from './util/wrap'; | |
+import { withWarning } from "./util/wrap"; | |
import { | |
writeQueryToStore, | |
writeResultToStore, | |
- writeSelectionSetToStore, | |
-} from '../src/data/writeToStore'; | |
+ writeSelectionSetToStore | |
+} from "../src/data/writeToStore"; | |
-import { | |
- storeKeyNameFromField, | |
-} from '../src/data/storeUtils'; | |
+import { storeKeyNameFromField } from "../src/data/storeUtils"; | |
-import { | |
- NormalizedCache, | |
-} from '../src/data/storeUtils'; | |
+import { NormalizedCache } from "../src/data/storeUtils"; | |
import { | |
HeuristicFragmentMatcher, | |
- IntrospectionFragmentMatcher, | |
-} from '../src/data/fragmentMatcher'; | |
+ IntrospectionFragmentMatcher | |
+} from "../src/data/fragmentMatcher"; | |
import { | |
getFragmentDefinitions, | |
- createFragmentMap, | |
-} from '../src/queries/getFromAST'; | |
+ createFragmentMap | |
+} from "../src/queries/getFromAST"; | |
-const getIdField = ({id}: {id: string}) => id; | |
+const getIdField = ({ id }: { id: string }) => id; | |
-describe('writing to the store', () => { | |
- it('properly normalizes a trivial item', () => { | |
+describe("writing to the store", () => { | |
+ it("properly normalizes a trivial item", () => { | |
const query = gql` | |
{ | |
@@ -52,19 +48,22 @@ | |
const result: any = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
- nullField: null, | |
+ nullField: null | |
}; | |
- assert.deepEqual(writeQueryToStore({ | |
- query, | |
- result: cloneDeep(result), | |
- }), { | |
- 'ROOT_QUERY': result, | |
- }); | |
+ assert.deepEqual( | |
+ writeQueryToStore({ | |
+ query, | |
+ result: cloneDeep(result) | |
+ }), | |
+ { | |
+ ROOT_QUERY: result | |
+ } | |
+ ); | |
}); | |
- it('properly normalizes an aliased field', () => { | |
+ it("properly normalizes an aliased field", () => { | |
const query = gql` | |
{ | |
@@ -77,26 +76,26 @@ | |
const result: any = { | |
- id: 'abcd', | |
- aliasedField: 'This is a string!', | |
+ id: "abcd", | |
+ aliasedField: "This is a string!", | |
numberField: 5, | |
- nullField: null, | |
+ nullField: null | |
}; | |
const normalized = writeQueryToStore({ | |
result, | |
- query, | |
+ query | |
}); | |
assert.deepEqual(normalized, { | |
- 'ROOT_QUERY': { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ ROOT_QUERY: { | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
- nullField: null, | |
- }, | |
+ nullField: null | |
+ } | |
}); | |
}); | |
- it('properly normalizes a aliased fields with arguments', () => { | |
+ it("properly normalizes a aliased fields with arguments", () => { | |
const query = gql` | |
{ | |
@@ -110,28 +109,28 @@ | |
const result: any = { | |
- id: 'abcd', | |
- aliasedField1: 'The arg was 1!', | |
- aliasedField2: 'The arg was 2!', | |
+ id: "abcd", | |
+ aliasedField1: "The arg was 1!", | |
+ aliasedField2: "The arg was 2!", | |
numberField: 5, | |
- nullField: null, | |
+ nullField: null | |
}; | |
const normalized = writeQueryToStore({ | |
result, | |
- query, | |
+ query | |
}); | |
assert.deepEqual(normalized, { | |
- 'ROOT_QUERY': { | |
- id: 'abcd', | |
- 'stringField({"arg":1})': 'The arg was 1!', | |
- 'stringField({"arg":2})': 'The arg was 2!', | |
+ ROOT_QUERY: { | |
+ id: "abcd", | |
+ 'stringField({"arg":1})': "The arg was 1!", | |
+ 'stringField({"arg":2})': "The arg was 2!", | |
numberField: 5, | |
- nullField: null, | |
- }, | |
+ nullField: null | |
+ } | |
}); | |
}); | |
- it('properly normalizes a query with variables', () => { | |
+ it("properly normalizes a query with variables", () => { | |
const query = gql` | |
{ | |
@@ -146,12 +145,12 @@ | |
intArg: 5, | |
floatArg: 3.14, | |
- stringArg: 'This is a string!', | |
+ stringArg: "This is a string!" | |
}; | |
const result: any = { | |
- id: 'abcd', | |
- stringField: 'Heyo', | |
+ id: "abcd", | |
+ stringField: "Heyo", | |
numberField: 5, | |
- nullField: null, | |
+ nullField: null | |
}; | |
@@ -159,18 +158,18 @@ | |
result, | |
query, | |
- variables, | |
+ variables | |
}); | |
assert.deepEqual(normalized, { | |
- 'ROOT_QUERY': { | |
- id: 'abcd', | |
+ ROOT_QUERY: { | |
+ id: "abcd", | |
nullField: null, | |
'numberField({"intArg":5,"floatArg":3.14})': 5, | |
- 'stringField({"arg":"This is a string!"})': 'Heyo', | |
- }, | |
+ 'stringField({"arg":"This is a string!"})': "Heyo" | |
+ } | |
}); | |
}); | |
- it('properly normalizes a query with default values', () => { | |
+ it("properly normalizes a query with default values", () => { | |
const query = gql` | |
query someBigQuery($stringArg: String = "This is a default string!", $intArg: Int, $floatArg: Float){ | |
@@ -184,12 +183,12 @@ | |
const variables = { | |
intArg: 5, | |
- floatArg: 3.14, | |
+ floatArg: 3.14 | |
}; | |
const result: any = { | |
- id: 'abcd', | |
- stringField: 'Heyo', | |
+ id: "abcd", | |
+ stringField: "Heyo", | |
numberField: 5, | |
- nullField: null, | |
+ nullField: null | |
}; | |
@@ -197,18 +196,18 @@ | |
result, | |
query, | |
- variables, | |
+ variables | |
}); | |
assert.deepEqual(normalized, { | |
- 'ROOT_QUERY': { | |
- id: 'abcd', | |
+ ROOT_QUERY: { | |
+ id: "abcd", | |
nullField: null, | |
'numberField({"intArg":5,"floatArg":3.14})': 5, | |
- 'stringField({"arg":"This is a default string!"})': 'Heyo', | |
- }, | |
+ 'stringField({"arg":"This is a default string!"})': "Heyo" | |
+ } | |
}); | |
}); | |
- it('properly normalizes a nested object with an ID', () => { | |
+ it("properly normalizes a nested object with an ID", () => { | |
const query = gql` | |
{ | |
@@ -227,33 +226,36 @@ | |
const result: any = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
nullField: null, | |
nestedObj: { | |
- id: 'abcde', | |
- stringField: 'This is a string too!', | |
+ id: "abcde", | |
+ stringField: "This is a string too!", | |
numberField: 6, | |
- nullField: null, | |
- }, | |
+ nullField: null | |
+ } | |
}; | |
- assert.deepEqual(writeQueryToStore({ | |
- query, | |
- result: cloneDeep(result), | |
- dataIdFromObject: getIdField, | |
- }), { | |
- 'ROOT_QUERY': assign({}, assign({}, omit(result, 'nestedObj')), { | |
- nestedObj: { | |
- type: 'id', | |
- id: result.nestedObj.id, | |
- generated: false, | |
- }, | |
+ assert.deepEqual( | |
+ writeQueryToStore({ | |
+ query, | |
+ result: cloneDeep(result), | |
+ dataIdFromObject: getIdField | |
}), | |
- [result.nestedObj.id]: result.nestedObj, | |
- }); | |
+ { | |
+ ROOT_QUERY: assign({}, assign({}, omit(result, "nestedObj")), { | |
+ nestedObj: { | |
+ type: "id", | |
+ id: result.nestedObj.id, | |
+ generated: false | |
+ } | |
+ }), | |
+ [result.nestedObj.id]: result.nestedObj | |
+ } | |
+ ); | |
}); | |
- it('properly normalizes a nested object without an ID', () => { | |
+ it("properly normalizes a nested object without an ID", () => { | |
const query = gql` | |
{ | |
@@ -271,31 +273,34 @@ | |
const result: any = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
nullField: null, | |
nestedObj: { | |
- stringField: 'This is a string too!', | |
+ stringField: "This is a string too!", | |
numberField: 6, | |
- nullField: null, | |
- }, | |
+ nullField: null | |
+ } | |
}; | |
- assert.deepEqual(writeQueryToStore({ | |
- query, | |
- result: cloneDeep(result), | |
- }), { | |
- 'ROOT_QUERY': assign({}, assign({}, omit(result, 'nestedObj')), { | |
- nestedObj: { | |
- type: 'id', | |
- id: `$ROOT_QUERY.nestedObj`, | |
- generated: true, | |
- }, | |
+ assert.deepEqual( | |
+ writeQueryToStore({ | |
+ query, | |
+ result: cloneDeep(result) | |
}), | |
- [`$ROOT_QUERY.nestedObj`]: result.nestedObj, | |
- }); | |
+ { | |
+ ROOT_QUERY: assign({}, assign({}, omit(result, "nestedObj")), { | |
+ nestedObj: { | |
+ type: "id", | |
+ id: `$ROOT_QUERY.nestedObj`, | |
+ generated: true | |
+ } | |
+ }), | |
+ [`$ROOT_QUERY.nestedObj`]: result.nestedObj | |
+ } | |
+ ); | |
}); | |
- it('properly normalizes a nested object with arguments but without an ID', () => { | |
+ it("properly normalizes a nested object with arguments but without an ID", () => { | |
const query = gql` | |
{ | |
@@ -313,31 +318,34 @@ | |
const result: any = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
nullField: null, | |
nestedObj: { | |
- stringField: 'This is a string too!', | |
+ stringField: "This is a string too!", | |
numberField: 6, | |
- nullField: null, | |
- }, | |
+ nullField: null | |
+ } | |
}; | |
- assert.deepEqual(writeQueryToStore({ | |
- query, | |
- result: cloneDeep(result), | |
- }), { | |
- 'ROOT_QUERY': assign({}, assign({}, omit(result, 'nestedObj')), { | |
- 'nestedObj({"arg":"val"})': { | |
- type: 'id', | |
- id: `$ROOT_QUERY.nestedObj({"arg":"val"})`, | |
- generated: true, | |
- }, | |
+ assert.deepEqual( | |
+ writeQueryToStore({ | |
+ query, | |
+ result: cloneDeep(result) | |
}), | |
- [`$ROOT_QUERY.nestedObj({"arg":"val"})`]: result.nestedObj, | |
- }); | |
+ { | |
+ ROOT_QUERY: assign({}, assign({}, omit(result, "nestedObj")), { | |
+ 'nestedObj({"arg":"val"})': { | |
+ type: "id", | |
+ id: `$ROOT_QUERY.nestedObj({"arg":"val"})`, | |
+ generated: true | |
+ } | |
+ }), | |
+ [`$ROOT_QUERY.nestedObj({"arg":"val"})`]: result.nestedObj | |
+ } | |
+ ); | |
}); | |
- it('properly normalizes a nested array with IDs', () => { | |
+ it("properly normalizes a nested array with IDs", () => { | |
const query = gql` | |
{ | |
@@ -356,42 +364,45 @@ | |
const result: any = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
nullField: null, | |
nestedArray: [ | |
{ | |
- id: 'abcde', | |
- stringField: 'This is a string too!', | |
+ id: "abcde", | |
+ stringField: "This is a string too!", | |
numberField: 6, | |
- nullField: null, | |
+ nullField: null | |
}, | |
{ | |
- id: 'abcdef', | |
- stringField: 'This is a string also!', | |
+ id: "abcdef", | |
+ stringField: "This is a string also!", | |
numberField: 7, | |
- nullField: null, | |
- }, | |
- ], | |
+ nullField: null | |
+ } | |
+ ] | |
}; | |
- assert.deepEqual(writeQueryToStore({ | |
- query, | |
- result: cloneDeep(result), | |
- dataIdFromObject: getIdField, | |
- }), { | |
- 'ROOT_QUERY': assign({}, assign({}, omit(result, 'nestedArray')), { | |
- nestedArray: result.nestedArray.map((obj: any) => ({ | |
- type: 'id', | |
- id: obj.id, | |
- generated: false, | |
- })), | |
+ assert.deepEqual( | |
+ writeQueryToStore({ | |
+ query, | |
+ result: cloneDeep(result), | |
+ dataIdFromObject: getIdField | |
}), | |
- [result.nestedArray[0].id]: result.nestedArray[0], | |
- [result.nestedArray[1].id]: result.nestedArray[1], | |
- }); | |
+ { | |
+ ROOT_QUERY: assign({}, assign({}, omit(result, "nestedArray")), { | |
+ nestedArray: result.nestedArray.map((obj: any) => ({ | |
+ type: "id", | |
+ id: obj.id, | |
+ generated: false | |
+ })) | |
+ }), | |
+ [result.nestedArray[0].id]: result.nestedArray[0], | |
+ [result.nestedArray[1].id]: result.nestedArray[1] | |
+ } | |
+ ); | |
}); | |
- it('properly normalizes a nested array with IDs and a null', () => { | |
+ it("properly normalizes a nested array with IDs and a null", () => { | |
const query = gql` | |
{ | |
@@ -410,35 +421,38 @@ | |
const result: any = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
nullField: null, | |
nestedArray: [ | |
{ | |
- id: 'abcde', | |
- stringField: 'This is a string too!', | |
+ id: "abcde", | |
+ stringField: "This is a string too!", | |
numberField: 6, | |
- nullField: null, | |
+ nullField: null | |
}, | |
- null, | |
- ], | |
+ null | |
+ ] | |
}; | |
- assert.deepEqual(writeQueryToStore({ | |
- query, | |
- result: cloneDeep(result), | |
- dataIdFromObject: getIdField, | |
- }), { | |
- 'ROOT_QUERY': assign({}, assign({}, omit(result, 'nestedArray')), { | |
- nestedArray: [ | |
- { type: 'id', id: result.nestedArray[0].id, generated: false }, | |
- null, | |
- ], | |
+ assert.deepEqual( | |
+ writeQueryToStore({ | |
+ query, | |
+ result: cloneDeep(result), | |
+ dataIdFromObject: getIdField | |
}), | |
- [result.nestedArray[0].id]: result.nestedArray[0], | |
- }); | |
+ { | |
+ ROOT_QUERY: assign({}, assign({}, omit(result, "nestedArray")), { | |
+ nestedArray: [ | |
+ { type: "id", id: result.nestedArray[0].id, generated: false }, | |
+ null | |
+ ] | |
+ }), | |
+ [result.nestedArray[0].id]: result.nestedArray[0] | |
+ } | |
+ ); | |
}); | |
- it('properly normalizes a nested array without IDs', () => { | |
+ it("properly normalizes a nested array without IDs", () => { | |
const query = gql` | |
{ | |
@@ -456,40 +470,40 @@ | |
const result: any = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
nullField: null, | |
nestedArray: [ | |
{ | |
- stringField: 'This is a string too!', | |
+ stringField: "This is a string too!", | |
numberField: 6, | |
- nullField: null, | |
+ nullField: null | |
}, | |
{ | |
- stringField: 'This is a string also!', | |
+ stringField: "This is a string also!", | |
numberField: 7, | |
- nullField: null, | |
- }, | |
- ], | |
+ nullField: null | |
+ } | |
+ ] | |
}; | |
const normalized = writeQueryToStore({ | |
query, | |
- result: cloneDeep(result), | |
+ result: cloneDeep(result) | |
}); | |
assert.deepEqual(normalized, { | |
- 'ROOT_QUERY': assign({}, assign({}, omit(result, 'nestedArray')), { | |
+ ROOT_QUERY: assign({}, assign({}, omit(result, "nestedArray")), { | |
nestedArray: [ | |
- { type: 'id', generated: true, id: `ROOT_QUERY.nestedArray.0` }, | |
- { type: 'id', generated: true, id: `ROOT_QUERY.nestedArray.1` }, | |
- ], | |
+ { type: "id", generated: true, id: `ROOT_QUERY.nestedArray.0` }, | |
+ { type: "id", generated: true, id: `ROOT_QUERY.nestedArray.1` } | |
+ ] | |
}), | |
[`ROOT_QUERY.nestedArray.0`]: result.nestedArray[0], | |
- [`ROOT_QUERY.nestedArray.1`]: result.nestedArray[1], | |
+ [`ROOT_QUERY.nestedArray.1`]: result.nestedArray[1] | |
}); | |
}); | |
- it('properly normalizes a nested array without IDs and a null item', () => { | |
+ it("properly normalizes a nested array without IDs and a null item", () => { | |
const query = gql` | |
{ | |
@@ -507,6 +521,6 @@ | |
const result: any = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
nullField: null, | |
@@ -514,28 +528,28 @@ | |
null, | |
{ | |
- stringField: 'This is a string also!', | |
+ stringField: "This is a string also!", | |
numberField: 7, | |
- nullField: null, | |
- }, | |
- ], | |
+ nullField: null | |
+ } | |
+ ] | |
}; | |
const normalized = writeQueryToStore({ | |
query, | |
- result: cloneDeep(result), | |
+ result: cloneDeep(result) | |
}); | |
assert.deepEqual(normalized, { | |
- 'ROOT_QUERY': assign({}, assign({}, omit(result, 'nestedArray')), { | |
+ ROOT_QUERY: assign({}, assign({}, omit(result, "nestedArray")), { | |
nestedArray: [ | |
null, | |
- { type: 'id', generated: true, id: `ROOT_QUERY.nestedArray.1` }, | |
- ], | |
+ { type: "id", generated: true, id: `ROOT_QUERY.nestedArray.1` } | |
+ ] | |
}), | |
- [`ROOT_QUERY.nestedArray.1`]: result.nestedArray[1], | |
+ [`ROOT_QUERY.nestedArray.1`]: result.nestedArray[1] | |
}); | |
}); | |
- it('properly normalizes an array of non-objects', () => { | |
+ it("properly normalizes an array of non-objects", () => { | |
const query = gql` | |
{ | |
@@ -549,9 +563,9 @@ | |
const result: any = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
nullField: null, | |
- simpleArray: ['one', 'two', 'three'], | |
+ simpleArray: ["one", "two", "three"] | |
}; | |
@@ -559,22 +573,22 @@ | |
query, | |
result: cloneDeep(result), | |
- dataIdFromObject: getIdField, | |
+ dataIdFromObject: getIdField | |
}); | |
assert.deepEqual(normalized, { | |
- 'ROOT_QUERY': assign({}, assign({}, omit(result, 'simpleArray')), { | |
+ ROOT_QUERY: assign({}, assign({}, omit(result, "simpleArray")), { | |
simpleArray: { | |
- type: 'json', | |
- 'json': [ | |
+ type: "json", | |
+ json: [ | |
result.simpleArray[0], | |
result.simpleArray[1], | |
- result.simpleArray[2], | |
- ], | |
- }, | |
- }), | |
+ result.simpleArray[2] | |
+ ] | |
+ } | |
+ }) | |
}); | |
}); | |
- it('properly normalizes an array of non-objects with null', () => { | |
+ it("properly normalizes an array of non-objects with null", () => { | |
const query = gql` | |
{ | |
@@ -588,31 +602,31 @@ | |
const result: any = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
nullField: null, | |
- simpleArray: [null, 'two', 'three'], | |
+ simpleArray: [null, "two", "three"] | |
}; | |
const normalized = writeQueryToStore({ | |
query, | |
- result: cloneDeep(result), | |
+ result: cloneDeep(result) | |
}); | |
assert.deepEqual(normalized, { | |
- 'ROOT_QUERY': assign({}, assign({}, omit(result, 'simpleArray')), { | |
+ ROOT_QUERY: assign({}, assign({}, omit(result, "simpleArray")), { | |
simpleArray: { | |
- type: 'json', | |
+ type: "json", | |
json: [ | |
result.simpleArray[0], | |
result.simpleArray[1], | |
- result.simpleArray[2], | |
- ], | |
- }, | |
- }), | |
+ result.simpleArray[2] | |
+ ] | |
+ } | |
+ }) | |
}); | |
}); | |
- it('merges nodes', () => { | |
+ it("merges nodes", () => { | |
const query = gql` | |
{ | |
@@ -624,7 +638,7 @@ | |
const result: any = { | |
- id: 'abcd', | |
+ id: "abcd", | |
numberField: 5, | |
- nullField: null, | |
+ nullField: null | |
}; | |
@@ -632,5 +646,5 @@ | |
query, | |
result: cloneDeep(result), | |
- dataIdFromObject: getIdField, | |
+ dataIdFromObject: getIdField | |
}); | |
@@ -644,7 +658,7 @@ | |
const result2: any = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
- nullField: null, | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
+ nullField: null | |
}; | |
@@ -653,13 +667,13 @@ | |
query: query2, | |
result: result2, | |
- dataIdFromObject: getIdField, | |
+ dataIdFromObject: getIdField | |
}); | |
assert.deepEqual(store2, { | |
- 'ROOT_QUERY': assign({}, result, result2), | |
+ ROOT_QUERY: assign({}, result, result2) | |
}); | |
}); | |
- it('properly normalizes a nested object that returns null', () => { | |
+ it("properly normalizes a nested object that returns null", () => { | |
const query = gql` | |
{ | |
@@ -678,22 +692,25 @@ | |
const result: any = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
nullField: null, | |
- nestedObj: null, | |
+ nestedObj: null | |
}; | |
- assert.deepEqual(writeQueryToStore({ | |
- query, | |
- result: cloneDeep(result), | |
- }), { | |
- 'ROOT_QUERY': assign({}, assign({}, omit(result, 'nestedObj')), { | |
- nestedObj: null, | |
+ assert.deepEqual( | |
+ writeQueryToStore({ | |
+ query, | |
+ result: cloneDeep(result) | |
}), | |
- }); | |
+ { | |
+ ROOT_QUERY: assign({}, assign({}, omit(result, "nestedObj")), { | |
+ nestedObj: null | |
+ }) | |
+ } | |
+ ); | |
}); | |
- it('properly normalizes an object with an ID when no extension is passed', () => { | |
+ it("properly normalizes an object with an ID when no extension is passed", () => { | |
const query = gql` | |
{ | |
@@ -707,83 +724,93 @@ | |
const result: any = { | |
people_one: { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
- }, | |
+ id: "abcd", | |
+ stringField: "This is a string!" | |
+ } | |
}; | |
- assert.deepEqual(writeQueryToStore({ | |
- query, | |
- result: cloneDeep(result), | |
- }), { | |
- 'ROOT_QUERY': { | |
- 'people_one({"id":"5"})': { | |
- type: 'id', | |
- id: '$ROOT_QUERY.people_one({"id":"5"})', | |
- generated: true, | |
+ assert.deepEqual( | |
+ writeQueryToStore({ | |
+ query, | |
+ result: cloneDeep(result) | |
+ }), | |
+ { | |
+ ROOT_QUERY: { | |
+ 'people_one({"id":"5"})': { | |
+ type: "id", | |
+ id: '$ROOT_QUERY.people_one({"id":"5"})', | |
+ generated: true | |
+ } | |
}, | |
- }, | |
- '$ROOT_QUERY.people_one({"id":"5"})': { | |
- 'id': 'abcd', | |
- 'stringField': 'This is a string!', | |
- }, | |
- }); | |
+ '$ROOT_QUERY.people_one({"id":"5"})': { | |
+ id: "abcd", | |
+ stringField: "This is a string!" | |
+ } | |
+ } | |
+ ); | |
}); | |
- it('consistently serialize different types of input when passed inlined or as variable', () => { | |
+ it("consistently serialize different types of input when passed inlined or as variable", () => { | |
const testData = [ | |
{ | |
mutation: gql`mutation mut($in: Int!) { mut(inline: 5, variable: $in) { id } }`, | |
variables: { in: 5 }, | |
- expected: 'mut({"inline":5,"variable":5})', | |
+ expected: 'mut({"inline":5,"variable":5})' | |
}, | |
{ | |
mutation: gql`mutation mut($in: Float!) { mut(inline: 5.5, variable: $in) { id } }`, | |
variables: { in: 5.5 }, | |
- expected: 'mut({"inline":5.5,"variable":5.5})', | |
+ expected: 'mut({"inline":5.5,"variable":5.5})' | |
}, | |
{ | |
mutation: gql`mutation mut($in: String!) { mut(inline: "abc", variable: $in) { id } }`, | |
- variables: { in: 'abc' }, | |
- expected: 'mut({"inline":"abc","variable":"abc"})', | |
+ variables: { in: "abc" }, | |
+ expected: 'mut({"inline":"abc","variable":"abc"})' | |
}, | |
{ | |
mutation: gql`mutation mut($in: Array!) { mut(inline: [1, 2], variable: $in) { id } }`, | |
variables: { in: [1, 2] }, | |
- expected: 'mut({"inline":[1,2],"variable":[1,2]})', | |
+ expected: 'mut({"inline":[1,2],"variable":[1,2]})' | |
}, | |
{ | |
mutation: gql`mutation mut($in: Object!) { mut(inline: {a: 1}, variable: $in) { id } }`, | |
variables: { in: { a: 1 } }, | |
- expected: 'mut({"inline":{"a":1},"variable":{"a":1}})', | |
+ expected: 'mut({"inline":{"a":1},"variable":{"a":1}})' | |
}, | |
{ | |
mutation: gql`mutation mut($in: Boolean!) { mut(inline: true, variable: $in) { id } }`, | |
variables: { in: true }, | |
- expected: 'mut({"inline":true,"variable":true})', | |
- }, | |
+ expected: 'mut({"inline":true,"variable":true})' | |
+ } | |
]; | |
- function isOperationDefinition(definition: DefinitionNode): definition is OperationDefinitionNode { | |
- return definition.kind === 'OperationDefinition'; | |
+ function isOperationDefinition( | |
+ definition: DefinitionNode | |
+ ): definition is OperationDefinitionNode { | |
+ return definition.kind === "OperationDefinition"; | |
} | |
function isField(selection: SelectionNode): selection is FieldNode { | |
- return selection.kind === 'Field'; | |
+ return selection.kind === "Field"; | |
} | |
- testData.forEach((data) => { | |
- data.mutation.definitions.forEach((definition: OperationDefinitionNode) => { | |
- if (isOperationDefinition(definition)) { | |
- definition.selectionSet.selections.forEach((selection) => { | |
- if (isField(selection)) { | |
- assert.equal(storeKeyNameFromField(selection, data.variables), data.expected); | |
- } | |
- }); | |
+ testData.forEach(data => { | |
+ data.mutation.definitions.forEach( | |
+ (definition: OperationDefinitionNode) => { | |
+ if (isOperationDefinition(definition)) { | |
+ definition.selectionSet.selections.forEach(selection => { | |
+ if (isField(selection)) { | |
+ assert.equal( | |
+ storeKeyNameFromField(selection, data.variables), | |
+ data.expected | |
+ ); | |
+ } | |
+ }); | |
+ } | |
} | |
- }); | |
+ ); | |
}); | |
}); | |
- it('properly normalizes a mutation with object or array parameters and variables', () => { | |
+ it("properly normalizes a mutation with object or array parameters and variables", () => { | |
const mutation = gql` | |
mutation some_mutation( | |
@@ -813,9 +840,9 @@ | |
const result: any = { | |
some_mutation: { | |
- id: 'id', | |
+ id: "id" | |
}, | |
some_mutation_with_variables: { | |
- id: 'id', | |
- }, | |
+ id: "id" | |
+ } | |
}; | |
@@ -823,58 +850,63 @@ | |
nil: null, | |
in: { | |
- id: '5', | |
- arr: [1, { a: 'b' }], | |
- obj: { a: 'b' }, | |
+ id: "5", | |
+ arr: [1, { a: "b" }], | |
+ obj: { a: "b" }, | |
num: 5.5, | |
nil: null, | |
- bo: true, | |
- }, | |
+ bo: true | |
+ } | |
}; | |
- function isOperationDefinition(value: ASTNode): value is OperationDefinitionNode { | |
- return value.kind === 'OperationDefinition'; | |
+ function isOperationDefinition( | |
+ value: ASTNode | |
+ ): value is OperationDefinitionNode { | |
+ return value.kind === "OperationDefinition"; | |
} | |
mutation.definitions.map((def: OperationDefinitionNode) => { | |
if (isOperationDefinition(def)) { | |
- assert.deepEqual(writeSelectionSetToStore({ | |
- dataId: '5', | |
- selectionSet: def.selectionSet, | |
- result: cloneDeep(result), | |
- context: { | |
- store: {}, | |
- variables, | |
- dataIdFromObject: () => '5', | |
- }, | |
- }), { | |
- '5': { | |
- 'some_mutation({"input":{"id":"5","arr":[1,{"a":"b"}],"obj":{"a":"b"},"num":5.5,"nil":null,"bo":true}})': { | |
- type: 'id', | |
- id: '5', | |
- generated: false, | |
- }, | |
- 'some_mutation_with_variables({"input":{"id":"5","arr":[1,{"a":"b"}],"obj":{"a":"b"},"num":5.5,"nil":null,"bo":true}})': { | |
- type: 'id', | |
- id: '5', | |
- generated: false, | |
- }, | |
- 'id': 'id', | |
- }, | |
- }); | |
+ assert.deepEqual( | |
+ writeSelectionSetToStore({ | |
+ dataId: "5", | |
+ selectionSet: def.selectionSet, | |
+ result: cloneDeep(result), | |
+ context: { | |
+ store: {}, | |
+ variables, | |
+ dataIdFromObject: () => "5" | |
+ } | |
+ }), | |
+ { | |
+ "5": { | |
+ 'some_mutation({"input":{"id":"5","arr":[1,{"a":"b"}],"obj":{"a":"b"},"num":5.5,"nil":null,"bo":true}})': { | |
+ type: "id", | |
+ id: "5", | |
+ generated: false | |
+ }, | |
+ 'some_mutation_with_variables({"input":{"id":"5","arr":[1,{"a":"b"}],"obj":{"a":"b"},"num":5.5,"nil":null,"bo":true}})': { | |
+ type: "id", | |
+ id: "5", | |
+ generated: false | |
+ }, | |
+ id: "id" | |
+ } | |
+ } | |
+ ); | |
} else { | |
- throw 'No operation definition found'; | |
+ throw "No operation definition found"; | |
} | |
}); | |
}); | |
- describe('type escaping', () => { | |
+ describe("type escaping", () => { | |
const dataIdFromObject = (object: any) => { | |
if (object.__typename && object.id) { | |
- return object.__typename + '__' + object.id; | |
+ return object.__typename + "__" + object.id; | |
} | |
return undefined; | |
}; | |
- it('should correctly escape generated ids', () => { | |
+ it("should correctly escape generated ids", () => { | |
const query = gql` | |
query { | |
@@ -886,25 +918,28 @@ | |
const data = { | |
author: { | |
- firstName: 'John', | |
- lastName: 'Smith', | |
- }, | |
+ firstName: "John", | |
+ lastName: "Smith" | |
+ } | |
}; | |
const expStore = { | |
ROOT_QUERY: { | |
author: { | |
- type: 'id', | |
- id: '$ROOT_QUERY.author', | |
- generated: true, | |
- }, | |
+ type: "id", | |
+ id: "$ROOT_QUERY.author", | |
+ generated: true | |
+ } | |
}, | |
- '$ROOT_QUERY.author': data.author, | |
+ "$ROOT_QUERY.author": data.author | |
}; | |
- assert.deepEqual(writeQueryToStore({ | |
- result: data, | |
- query, | |
- }), expStore); | |
+ assert.deepEqual( | |
+ writeQueryToStore({ | |
+ result: data, | |
+ query | |
+ }), | |
+ expStore | |
+ ); | |
}); | |
- it('should correctly escape real ids', () => { | |
+ it("should correctly escape real ids", () => { | |
const query = gql` | |
query { | |
@@ -917,31 +952,34 @@ | |
const data = { | |
author: { | |
- firstName: 'John', | |
- id: '129', | |
- __typename: 'Author', | |
- }, | |
+ firstName: "John", | |
+ id: "129", | |
+ __typename: "Author" | |
+ } | |
}; | |
const expStore = { | |
ROOT_QUERY: { | |
author: { | |
- type: 'id', | |
+ type: "id", | |
id: dataIdFromObject(data.author), | |
- generated: false, | |
- }, | |
+ generated: false | |
+ } | |
}, | |
[dataIdFromObject(data.author)!]: { | |
firstName: data.author.firstName, | |
id: data.author.id, | |
- __typename: data.author.__typename, | |
- }, | |
+ __typename: data.author.__typename | |
+ } | |
}; | |
- assert.deepEqual(writeQueryToStore({ | |
- result: data, | |
- query, | |
- dataIdFromObject, | |
- }), expStore); | |
+ assert.deepEqual( | |
+ writeQueryToStore({ | |
+ result: data, | |
+ query, | |
+ dataIdFromObject | |
+ }), | |
+ expStore | |
+ ); | |
}); | |
- it('should correctly escape json blobs', () => { | |
+ it("should correctly escape json blobs", () => { | |
const query = gql` | |
query { | |
@@ -955,17 +993,17 @@ | |
author: { | |
info: { | |
- name: 'John', | |
+ name: "John" | |
}, | |
- id: '129', | |
- __typename: 'Author', | |
- }, | |
+ id: "129", | |
+ __typename: "Author" | |
+ } | |
}; | |
const expStore = { | |
ROOT_QUERY: { | |
author: { | |
- type: 'id', | |
+ type: "id", | |
id: dataIdFromObject(data.author), | |
- generated: false, | |
- }, | |
+ generated: false | |
+ } | |
}, | |
[dataIdFromObject(data.author)!]: { | |
@@ -973,35 +1011,38 @@ | |
id: data.author.id, | |
info: { | |
- type: 'json', | |
- json: data.author.info, | |
- }, | |
- }, | |
+ type: "json", | |
+ json: data.author.info | |
+ } | |
+ } | |
}; | |
- assert.deepEqual(writeQueryToStore({ | |
- result: data, | |
- query, | |
- dataIdFromObject, | |
- }), expStore); | |
+ assert.deepEqual( | |
+ writeQueryToStore({ | |
+ result: data, | |
+ query, | |
+ dataIdFromObject | |
+ }), | |
+ expStore | |
+ ); | |
}); | |
}); | |
- it('should merge objects when overwriting a generated id with a real id', () => { | |
+ it("should merge objects when overwriting a generated id with a real id", () => { | |
const dataWithoutId = { | |
author: { | |
- firstName: 'John', | |
- lastName: 'Smith', | |
- }, | |
+ firstName: "John", | |
+ lastName: "Smith" | |
+ } | |
}; | |
const dataWithId = { | |
author: { | |
- firstName: 'John', | |
- id: '129', | |
- __typename: 'Author', | |
- }, | |
+ firstName: "John", | |
+ id: "129", | |
+ __typename: "Author" | |
+ } | |
}; | |
const dataIdFromObject = (object: any) => { | |
if (object.__typename && object.id) { | |
- return object.__typename + '__' + object.id; | |
+ return object.__typename + "__" + object.id; | |
} | |
return undefined; | |
@@ -1023,35 +1064,35 @@ | |
}`; | |
const expStoreWithoutId = { | |
- '$ROOT_QUERY.author': { | |
- firstName: 'John', | |
- lastName: 'Smith', | |
+ "$ROOT_QUERY.author": { | |
+ firstName: "John", | |
+ lastName: "Smith" | |
}, | |
ROOT_QUERY: { | |
- 'author': { | |
- type: 'id', | |
- id: '$ROOT_QUERY.author', | |
- generated: true, | |
- }, | |
- }, | |
+ author: { | |
+ type: "id", | |
+ id: "$ROOT_QUERY.author", | |
+ generated: true | |
+ } | |
+ } | |
}; | |
const expStoreWithId = { | |
- 'Author__129': { | |
- firstName: 'John', | |
- lastName: 'Smith', | |
- id: '129', | |
- __typename: 'Author', | |
+ Author__129: { | |
+ firstName: "John", | |
+ lastName: "Smith", | |
+ id: "129", | |
+ __typename: "Author" | |
}, | |
ROOT_QUERY: { | |
author: { | |
- type: 'id', | |
- id: 'Author__129', | |
- generated: false, | |
- }, | |
- }, | |
+ type: "id", | |
+ id: "Author__129", | |
+ generated: false | |
+ } | |
+ } | |
}; | |
const storeWithoutId = writeQueryToStore({ | |
result: dataWithoutId, | |
query: queryWithoutId, | |
- dataIdFromObject, | |
+ dataIdFromObject | |
}); | |
assert.deepEqual(storeWithoutId, expStoreWithoutId); | |
@@ -1060,10 +1101,10 @@ | |
query: queryWithId, | |
store: storeWithoutId, | |
- dataIdFromObject, | |
+ dataIdFromObject | |
}); | |
assert.deepEqual(storeWithId, expStoreWithId); | |
}); | |
- it('does not swallow errors other than field errors', () => { | |
+ it("does not swallow errors other than field errors", () => { | |
const query = gql` | |
query { | |
@@ -1072,15 +1113,15 @@ | |
}`; | |
const result: any = { | |
- fortuneCookie: 'Star Wars unit tests are boring', | |
+ fortuneCookie: "Star Wars unit tests are boring" | |
}; | |
assert.throws(() => { | |
writeQueryToStore({ | |
result, | |
- query, | |
+ query | |
}); | |
- }, /No fragment/); | |
+ }, /no fragment/); | |
}); | |
- it('does not change object references if the value is the same', () => { | |
+ it("does not change object references if the value is the same", () => { | |
const query = gql` | |
{ | |
@@ -1093,12 +1134,12 @@ | |
const result: any = { | |
- id: 'abcd', | |
- stringField: 'This is a string!', | |
+ id: "abcd", | |
+ stringField: "This is a string!", | |
numberField: 5, | |
- nullField: null, | |
+ nullField: null | |
}; | |
const store = writeQueryToStore({ | |
query, | |
- result: cloneDeep(result), | |
+ result: cloneDeep(result) | |
}); | |
@@ -1106,13 +1147,13 @@ | |
query, | |
result: cloneDeep(result), | |
- store: assign({}, store) as NormalizedCache, | |
+ store: assign({}, store) as NormalizedCache | |
}); | |
- Object.keys(store).forEach((field) => { | |
- assert.equal(store[field], newStore[field], 'references are the same'); | |
+ Object.keys(store).forEach(field => { | |
+ assert.equal(store[field], newStore[field], "references are the same"); | |
}); | |
}); | |
- describe('writeResultToStore shape checking', () => { | |
+ describe("writeResultToStore shape checking", () => { | |
const query = gql` | |
query { | |
@@ -1126,9 +1167,11 @@ | |
const initialResult = { | |
- todos: [{ | |
- id: '1', | |
- name: 'Todo 1', | |
- description: 'Description 1', | |
- }], | |
+ todos: [ | |
+ { | |
+ id: "1", | |
+ name: "Todo 1", | |
+ description: "Description 1" | |
+ } | |
+ ] | |
}; | |
@@ -1136,32 +1179,29 @@ | |
query, | |
result: cloneDeep(initialResult), | |
- dataIdFromObject: getIdField, | |
+ dataIdFromObject: getIdField | |
}); | |
- it('should write the result data without validating its shape when a fragment matcher is not provided', () => { | |
+ it("should write the result data without validating its shape when a fragment matcher is not provided", () => { | |
const newData = { | |
- id: '2', | |
- name: 'Todo 2', | |
+ id: "2", | |
+ name: "Todo 2" | |
}; | |
const result = { | |
- todos: [ | |
- ...initialResult.todos, | |
- newData, | |
- ], | |
+ todos: [...initialResult.todos, newData] | |
}; | |
const newStore = writeResultToStore({ | |
- dataId: 'ROOT_QUERY', | |
+ dataId: "ROOT_QUERY", | |
result, | |
document: query, | |
dataIdFromObject: getIdField, | |
- store: initialStore, | |
+ store: initialStore | |
}); | |
- assert.deepEqual(newStore['1'], initialStore['1']); | |
- assert.deepEqual(newStore['2'], newData); | |
+ assert.deepEqual(newStore["1"], initialStore["1"]); | |
+ assert.deepEqual(newStore["2"], newData); | |
}); | |
- it('should warn when it receives the wrong data with non-union fragments (using an heuristic matcher)', () => { | |
+ it("should warn when it receives the wrong data with non-union fragments (using an heuristic matcher)", () => { | |
const fragmentMatcherFunction = new HeuristicFragmentMatcher().match; | |
@@ -1170,24 +1210,23 @@ | |
...initialResult.todos, | |
{ | |
- id: '2', | |
- name: 'Todo 2', | |
- }, | |
- ], | |
+ id: "2", | |
+ name: "Todo 2" | |
+ } | |
+ ] | |
}; | |
return withWarning(() => { | |
const newStore = writeResultToStore({ | |
- dataId: 'ROOT_QUERY', | |
+ dataId: "ROOT_QUERY", | |
result, | |
document: query, | |
store: initialStore, | |
dataIdFromObject: getIdField, | |
- fragmentMatcherFunction, | |
+ fragmentMatcherFunction | |
}); | |
- }, /Missing field description/); | |
+ }, /missing field description/); | |
}); | |
- | |
- it('should warn when it receives the wrong data inside a fragment (using an introspection matcher)', () => { | |
+ it("should warn when it receives the wrong data inside a fragment (using an introspection matcher)", () => { | |
const fragmentMatcherFunction = new IntrospectionFragmentMatcher({ | |
introspectionQueryResultData: { | |
@@ -1195,14 +1234,14 @@ | |
types: [ | |
{ | |
- kind: 'UNION', | |
- name: 'Todo', | |
+ kind: "UNION", | |
+ name: "Todo", | |
possibleTypes: [ | |
- { name: 'ShoppingCartItem' }, | |
- { name: 'TaskItem' }, | |
- ], | |
- }, | |
- ], | |
- }, | |
- }, | |
+ { name: "ShoppingCartItem" }, | |
+ { name: "TaskItem" } | |
+ ] | |
+ } | |
+ ] | |
+ } | |
+ } | |
}).match; | |
@@ -1233,11 +1272,11 @@ | |
todos: [ | |
{ | |
- id: '1', | |
- name: 'Todo 1', | |
- description: 'Description 1', | |
+ id: "1", | |
+ name: "Todo 1", | |
+ description: "Description 1", | |
price: 100, | |
- __typename: 'ShoppingCartItem', | |
- }, | |
- ], | |
+ __typename: "ShoppingCartItem" | |
+ } | |
+ ] | |
}; | |
@@ -1247,5 +1286,5 @@ | |
result: cloneDeep(initialResultWithInterface), | |
dataIdFromObject: getIdField, | |
- fragmentMap: createFragmentMap(fragments), | |
+ fragmentMap: createFragmentMap(fragments) | |
}); | |
@@ -1253,45 +1292,45 @@ | |
todos: [ | |
{ | |
- id: '1', | |
- name: 'Todo 1', | |
- description: 'Description 1', | |
+ id: "1", | |
+ name: "Todo 1", | |
+ description: "Description 1", | |
price: 100, | |
- __typename: 'ShoppingCartItem', | |
+ __typename: "ShoppingCartItem" | |
}, | |
{ | |
- id: '2', | |
- name: 'Todo 2', | |
- description: 'Description 2', | |
- __typename: 'TaskItem', | |
- }, | |
- ], | |
+ id: "2", | |
+ name: "Todo 2", | |
+ description: "Description 2", | |
+ __typename: "TaskItem" | |
+ } | |
+ ] | |
}; | |
return withWarning(() => { | |
const newStore = writeResultToStore({ | |
- dataId: 'ROOT_QUERY', | |
+ dataId: "ROOT_QUERY", | |
result, | |
document: queryWithInterface, | |
store, | |
dataIdFromObject: getIdField, | |
- fragmentMatcherFunction, | |
+ fragmentMatcherFunction | |
}); | |
- }, /Missing field date/); | |
+ }, /missing field date/); | |
}); | |
- it('should not warn if a field is null', () => { | |
+ it("should not warn if a field is null", () => { | |
const result = { | |
- todos: null, | |
+ todos: null | |
}; | |
const newStore = writeResultToStore({ | |
- dataId: 'ROOT_QUERY', | |
+ dataId: "ROOT_QUERY", | |
result, | |
document: query, | |
dataIdFromObject: getIdField, | |
- store: initialStore, | |
+ store: initialStore | |
}); | |
- assert.deepEqual(newStore['ROOT_QUERY'], { todos: null }); | |
+ assert.deepEqual(newStore["ROOT_QUERY"], { todos: null }); | |
}); | |
}); | |
./typings.d.ts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment