- server: A physical machine connected to the web
- service: A deployed program (e.g. GraphQL endpoint / REST endpoint)
- environment: The OS that a service runs in
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
| export const ttlCache = <K extends string, V = any>({ ttl, maxSize }: { ttl: number, maxSize?: number }) => { | |
| let cache: Record<K, { value: V; expiresAt: number } | undefined> = Object.create(null); | |
| return { | |
| set: (key: K, value: V) => { | |
| const keys = Object.keys(cache) as K[]; | |
| if (maxSize && keys.length === maxSize) { | |
| delete cache[keys[0]]; | |
| } |
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
| import { useState, useCallback, useRef } from 'react'; | |
| export const useSynchronousReducer = <S, A>( | |
| reducer: (s: S, a: A) => S, | |
| initialState: S | |
| ) => { | |
| const stateRef = useRef(initialState); | |
| const [state, setState] = useState<S>(stateRef.current); | |
| const dispatch = useCallback<(a: A) => S>((action) => { |
.storybook/preview.tsx
import { addDecorator, DecoratorFn } from '@storybook/react';
/** Adds react-router context */
const routerDecorator: DecoratorFn = (Story, context) => {
const router = context.parameters.router;
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
| const isIntrospectionQuery = (arg: string) => { | |
| const query = parse(arg); | |
| const opDefs = query.definitions.filter(d => d.kind == "OperationDefinition") as OperationDefinitionNode[]; | |
| // Must only have one definition | |
| if (opDefs.length > 1) { | |
| return false; | |
| } | |
| const selections = opDefs[0].selectionSet.selections; |
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
| import { ApolloProvider } from '@apollo/react-hooks'; | |
| import { ApolloClient, RequestHandler, InMemoryCache, ApolloLink, Observable } from 'apollo-boost'; | |
| import { GraphQLError } from 'graphql'; | |
| import React from 'react'; | |
| import { Users } from './Users'; | |
| export default { | |
| title: 'Pages/Users', | |
| }; |
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
| const useQuery = (query, opts) => { | |
| const source = useRef(); | |
| const [state, setState] = useState(); | |
| const makeRead = useCallback(() => { | |
| let status = "pending"; | |
| let response; | |
| let promise = new Promise((resolve) => { | |
| source.current = pipe( | |
| client.createOperation(query, opts), |