瀏覽代碼

Update types

Andrew Swistak 6 年之前
父節點
當前提交
23c06472bc

+ 1 - 1
app/javascript/packs/frontend/components/pages/pokemon/Create.tsx

@@ -10,7 +10,7 @@ function onSubmit(e: Event, router: Router, nickname: string, pokedexNumber: num
   createPokemon(environment, router, nickname, pokedexNumber);
 }
 
-const Create: React.FC<RouterState> = ({router}): React.ReactElement<void> => {
+const Create: React.FC<RouterState> = ({router}: RouterState): React.ReactElement<void> => {
   const [nickname, setNickname] = useState('');
   const [pokedexNumber, setPokedexNumber] = useState(1);
 

+ 8 - 7
app/javascript/packs/frontend/graphqlEnvironment.ts

@@ -8,26 +8,27 @@ import {
   // Types
   CacheConfig,
   ObservableFromValue,
+  GraphQLResponse,
+  RequestParameters,
   FetchFunction,
-  QueryPayload,
-  RequestNode,
   Variables,
 } from 'relay-runtime';
 
 // 100 cache entries, 300 seconds until cache is invalid.
-const cache = new QueryResponseCache({size: 100, ttl: 300000});
+export const cache = new QueryResponseCache({size: 100, ttl: 300000});
 
 export const fetchQuery: FetchFunction = (
-  operation: RequestNode,
+  operation: RequestParameters,
   variables: Variables,
   cacheConfig: CacheConfig
-): ObservableFromValue<QueryPayload> => {
+): ObservableFromValue<GraphQLResponse> => {
   const queryId: string = operation.name;
-  const cachedData: QueryPayload = cache.get(queryId, variables);
+  const cachedData: GraphQLResponse = cache.get(queryId, variables);
   const forceLoad: boolean = cacheConfig && cacheConfig.force;
 
   if (!forceLoad && cachedData) {
-    return cachedData;
+    // Return promise to keep returns consistent
+    return new Promise(resolve => resolve(cachedData));
   }
 
   return fetch('/api/graphql', {