|
7 | 7 | * @flow
|
8 | 8 | */
|
9 | 9 |
|
10 |
| -import type { INetwork } from "../../../../node_modules/relay-runtime/network/RelayNetworkTypes";import type { Variables } from "../../../../node_modules/relay-runtime/util/RelayRuntimeTypes"; |
11 |
| -import type { RequestParameters } from "../../../../node_modules/relay-runtime/util/RelayConcreteNode";/** |
| 10 | +import type { INetwork } from '../../../../node_modules/relay-runtime/network/RelayNetworkTypes'; |
| 11 | +import type { Variables } from '../../../../node_modules/relay-runtime/util/RelayRuntimeTypes'; |
| 12 | +import type { RequestParameters } from '../../../../node_modules/relay-runtime/util/RelayConcreteNode'; |
| 13 | +/** |
12 | 14 | * This file implements the Relay "network" as a server running in the browser.
|
13 | 15 | * This allows the test app to send network requests that can be observed without
|
14 | 16 | * running a separate server.
|
@@ -102,17 +104,17 @@ function createInBrowserNetwork(): INetwork {
|
102 | 104 | }
|
103 | 105 |
|
104 | 106 | friends(): {
|
105 |
| - count: number, |
106 |
| - edges: Array<{ cursor: number, node: User, ... }>, |
107 |
| - pageInfo: () => { |
108 |
| - endCursor: string, |
109 |
| - hasNextPage: boolean, |
110 |
| - hasPreviousPage: boolean, |
111 |
| - startCursor: string, |
112 |
| - ... |
113 |
| - }, |
114 |
| - ... |
115 |
| -} { |
| 107 | + count: number, |
| 108 | + edges: Array<{ cursor: number, node: User, ... }>, |
| 109 | + pageInfo: () => { |
| 110 | + endCursor: string, |
| 111 | + hasNextPage: boolean, |
| 112 | + hasPreviousPage: boolean, |
| 113 | + startCursor: string, |
| 114 | + ... |
| 115 | + }, |
| 116 | + ... |
| 117 | + } { |
116 | 118 | if (!this._friends) {
|
117 | 119 | this._friends = [];
|
118 | 120 | for (let i = 0; i < 4; i++) {
|
@@ -146,25 +148,35 @@ function createInBrowserNetwork(): INetwork {
|
146 | 148 | }
|
147 | 149 |
|
148 | 150 | const userMap = new Map<string, User>();
|
149 |
| - function createUser(id: string |void) { |
| 151 | + function createUser(id: string | void) { |
150 | 152 | const user = new User(id);
|
151 | 153 | userMap.set(user.id, user);
|
152 | 154 | return user;
|
153 | 155 | }
|
154 | 156 |
|
155 | 157 | const root = {
|
156 |
| - node: ({ id }: {id : string | void}) => { |
| 158 | + node: ({ id }: { id: string | void }) => { |
157 | 159 | if (id == null || !userMap.has(id)) {
|
158 | 160 | return createUser(id);
|
159 | 161 | }
|
160 | 162 | return userMap.get(id);
|
161 | 163 | },
|
162 | 164 | };
|
163 | 165 |
|
164 |
| - function fetchQuery(request: RequestParameters, variables: Variables): $FlowFixMe { |
| 166 | + function fetchQuery( |
| 167 | + request: RequestParameters, |
| 168 | + variables: Variables |
| 169 | + ): $FlowFixMe { |
165 | 170 | return new Promise(resolve => {
|
166 | 171 | setTimeout(() => {
|
167 |
| - resolve(graphql({schema, source: request.text, rootValue:root, variableValues: variables})); |
| 172 | + resolve( |
| 173 | + graphql({ |
| 174 | + schema, |
| 175 | + source: request.text, |
| 176 | + rootValue: root, |
| 177 | + variableValues: variables, |
| 178 | + }) |
| 179 | + ); |
168 | 180 | }, 1000 + Math.round(Math.random() * 1000));
|
169 | 181 | });
|
170 | 182 | }
|
|
0 commit comments