...
 
Commits (4)
......@@ -10,6 +10,7 @@
all=warn
[options]
esproposal.optional_chaining=enable
module.ignore_non_literal_requires=true
# Used to suppress errors caused by Flow limitations.
......
......@@ -50,7 +50,7 @@ import type {GraphQLSchema} from 'graphql';
import type {
PluginInitializer,
PluginInterface,
} from '../language/RelayLanguagePluginInterface';
} from 'relay-compiler/lib/RelayLanguagePluginInterface';
function persistQuery(text: string): Promise<string> {
const match = text.match(/^\s*query\s+(\w+Query)\b/);
......
......@@ -71,10 +71,7 @@ const api = {
environment,
fetchQuery: fetchQuery.bind(null, environment),
readQuery(query, variables) {
const {
createOperationSelector,
getRequest,
} = environment.unstable_internal;
const {createOperationSelector, getRequest} = environment.unstable_internal;
const operation = createOperationSelector(getRequest(query), variables);
const snapshot = environment.lookup(
operation.fragment,
......
......@@ -2,17 +2,13 @@
* @flow
*/
import React from 'react';
import * as React from 'react';
import inBrowser from '../../common/inBrowser';
if (inBrowser) {
require('./Metadata.css');
}
export default function Metadata({children}) {
return (
<div className="metadata">
{children}
</div>
);
export default function Metadata({children}: {children: React.Node}) {
return <div className="metadata">{children}</div>;
}
......@@ -18,7 +18,7 @@ class Page extends React.Component<{data: PageData}> {
// may want to URL encode here too? page.url
<article>
<h1>
<Link to={page.url}>{page.title}</Link>
<Link to={page.url}>{page.title ?? 'Untitled'}</Link>
</h1>
<When data={page} />
<div>
......
......@@ -22,7 +22,7 @@ class PagePreview extends React.Component<{data: PagePreviewData}> {
</td>
<td>
<Link title={description} to={url}>
{title}
{title ?? 'Untitled'}
</Link>
</td>
<td>
......
......@@ -19,7 +19,7 @@ class Post extends React.Component<{data: PostData}> {
// post.url encode?
<article>
<h1>
<Link to={post.url}>{post.title}</Link>
<Link to={post.url}>{post.title ?? 'Untitled'}</Link>
</h1>
<Metadata>
<When data={post} />
......
......@@ -22,7 +22,7 @@ class PostPreview extends React.Component<{data: PostPreviewData}> {
</td>
<td>
<Link title={description} to={url}>
{title}
{title ?? 'Untitled'}
</Link>
</td>
<td>
......
......@@ -169,15 +169,19 @@ class Search extends React.Component<Props, State> {
<PluralText count={search.count} text="item" /> found
</p>
<ContentListing>
{edges &&
edges.map((edge, i) => {
if (edge) {
const {cursor, node} = edge;
if (node) {
return <ContentPreview cursor={cursor} key={i} data={node} />;
{edges
? edges.map((edge, i) => {
if (edge) {
const {cursor, node} = edge;
if (node) {
return (
<ContentPreview cursor={cursor} key={i} data={node} />
);
}
}
}
})}
return null;
})
: null}
</ContentListing>
{search.pageInfo.hasNextPage ? (
<LoadMoreButton
......
......@@ -18,7 +18,7 @@ class Snippet extends React.Component<{data: SnippetData}> {
// encode url?
<article>
<h1>
<Link to={snippet.url}>{snippet.title}</Link>
<Link to={snippet.url}>{snippet.title ?? 'Untitled'}</Link>
</h1>
<When data={snippet} />
<div>
......
......@@ -22,7 +22,7 @@ class SnippetPreview extends React.Component<{data: SnippetPreviewData}> {
</td>
<td>
<Link title={description} to={url}>
{title}
{title ?? 'Untitled'}
</Link>
</td>
<td>
......
......@@ -76,13 +76,15 @@ class Tag extends React.Component<Props, State> {
<PluralText count={count} text="item" /> tagged with <em>{name}</em>
</p>
<ContentListing>
{edges &&
edges.map((edge, i) => {
if (edge) {
const {cursor, node} = edge;
return <ContentPreview cursor={cursor} key={i} data={node} />;
}
})}
{edges
? edges.map((edge, i) => {
if (edge) {
const {cursor, node} = edge;
return <ContentPreview cursor={cursor} key={i} data={node} />;
}
return null;
})
: null}
</ContentListing>
{taggables.pageInfo.hasNextPage ? (
<LoadMoreButton
......
......@@ -15,7 +15,7 @@ type Props = {
type State = TimeInfo;
export default class Time extends React.Component<Props, State> {
_updateTimer: mixed;
_updateTimer: ?TimeoutID;
_clearTimer = () => {
if (this._updateTimer) {
......
......@@ -3,6 +3,9 @@
*/
export default class ExternalRedirectError extends Error {
target: string;
code: number;
constructor(message: string, target: string, code: number) {
super(message);
this.target = target;
......@@ -21,7 +24,10 @@ function descriptionForCode(code: number): string {
}
}
export function makeExternalRedirect(target: string, code: number): ExternalRedirectError {
export function makeExternalRedirect(
target: string,
code: number,
): ExternalRedirectError {
const message = `HTTP/1.1 ${code} ${descriptionForCode(
code,
)} - Location: ${target}`;
......
......@@ -3,6 +3,8 @@
*/
export default class InternalRedirectError extends Error {
target: string;
constructor(message: string, target: string) {
super(message);
this.target = target;
......
......@@ -2,15 +2,20 @@
* @flow strict-local
*/
import * as React from 'react';
export default class NotFoundError extends Error {
// TODO: improve on any annotation
constructor(message: string, component: any) {
component: React.Node;
constructor(message: string, component: React.Node) {
super(message);
this.component = component;
}
}
// TODO: fix this too
export function makeNotFound(message: string, component: any): NotFoundError {
export function makeNotFound(
message: string,
component: React.Node,
): NotFoundError {
return new NotFoundError(message, component);
}
......@@ -3,6 +3,9 @@
*/
export default class RenderTextError extends Error {
text: string;
type: string;
constructor(text: string, type: string) {
super('RenderTextError');
this.text = text;
......
......@@ -39,10 +39,7 @@ export default function buildRoute(query, config) {
createOperationSelector,
getRequest,
} = environment.unstable_internal;
const operation = createOperationSelector(
getRequest(query),
variables,
);
const operation = createOperationSelector(getRequest(query), variables);
environment.retain(operation.root);
}
......
......@@ -77,15 +77,13 @@ export default buildRoute(
}
return <Article data={node} />;
} else {
throw makeNotFoundError(
throw makeNotFound(
`No article found with id: ${id}`,
(
<p>
Try inspecting <Link to="/wiki">the wiki index</Link> and{' '}
<Link to="/tags">the tags listing</Link>, or using{' '}
<Link to="/search">the site search</Link>.
</p>
),
<p>
Try inspecting <Link to="/wiki">the wiki index</Link> and{' '}
<Link to="/tags">the tags listing</Link>, or using{' '}
<Link to="/search">the site search</Link>.
</p>,
);
}
},
......
......@@ -29,13 +29,11 @@ export default buildRoute(
} else {
throw makeNotFoundError(
`No page found with id: ${id}`,
(
<p>
Try inspecting <Link to="/tags/pages">the pages index</Link> and{' '}
<Link to="/tags">the tags listing</Link>, or using{' '}
<Link to="/search">the site search</Link>.
</p>
),
<p>
Try inspecting <Link to="/tags/pages">the pages index</Link> and{' '}
<Link to="/tags">the tags listing</Link>, or using{' '}
<Link to="/search">the site search</Link>.
</p>,
);
}
},
......
......@@ -29,13 +29,11 @@ export default buildRoute(
} else {
throw makeNotFound(
`No post found with id: ${id}`,
(
<p>
Try inspecting <Link to="/blog">the blog index</Link> and{' '}
<Link to="/tags">the tags listing</Link>, or using{' '}
<Link to="/search">the site search</Link>.
</p>
),
<p>
Try inspecting <Link to="/blog">the blog index</Link> and{' '}
<Link to="/tags">the tags listing</Link>, or using{' '}
<Link to="/search">the site search</Link>.
</p>,
);
}
},
......
......@@ -29,13 +29,11 @@ export default buildRoute(
} else {
throw makeNotFound(
`No snippet found with id: ${id}`,
(
<p>
Try inspecting <Link to="/snippets">the snippets index</Link> and{' '}
<Link to="/tags">the tags listing</Link>, or using{' '}
<Link to="/search">the site search</Link>.
</p>
),
<p>
Try inspecting <Link to="/snippets">the snippets index</Link> and{' '}
<Link to="/tags">the tags listing</Link>, or using{' '}
<Link to="/search">the site search</Link>.
</p>,
);
}
},
......
......@@ -53,13 +53,11 @@ export default buildRoute(
}
throw makeNotFound(
`Snippet "${id}" source not found for format ${format}`,
(
<p>
Try inspecting <Link to="/snippets">the snippets index</Link> and{' '}
<Link to="/tags">the tags listing</Link>, or using{' '}
<Link to="/search">the site search</Link>.
</p>
),
<p>
Try inspecting <Link to="/snippets">the snippets index</Link> and{' '}
<Link to="/tags">the tags listing</Link>, or using{' '}
<Link to="/search">the site search</Link>.
</p>,
);
},
},
......
......@@ -4,9 +4,9 @@
const DEFAULT_CAPACITY = 128;
export default class LRUCache {
export default class LRUCache<TKey> {
_capacity: number;
_storage: Map<*, *>;
_storage: Map<TKey, *>;
constructor(capacity: number = DEFAULT_CAPACITY) {
if (capacity <= 0) {
......@@ -16,11 +16,11 @@ export default class LRUCache {
this._storage = new Map();
}
has(key: mixed): boolean {
has(key: TKey): boolean {
return this._storage.has(key);
}
get(key: mixed): mixed {
get(key: TKey): mixed {
// Bump item in LRU list by removing and re-adding it.
if (this._storage.has(key)) {
const value = this._storage.get(key);
......@@ -30,7 +30,7 @@ export default class LRUCache {
}
}
set(key: mixed, value: mixed): LRUCache {
set(key: TKey, value: mixed): LRUCache<TKey> {
// If necessary to stay under capacity, remove LRU items.
if (this._storage.size >= this._capacity) {
let countToRemove = this._storage.size - this._capacity;
......
......@@ -7,6 +7,8 @@ import {spawn} from 'child_process';
import type {Invocation} from './run';
export class RunError extends Error {
code: number;
constructor(message: string, code: number) {
super(`RunError: ${message}`);
this.code = code;
......
......@@ -4,6 +4,7 @@
import {LAST_INDEXED_HASH} from './constants';
import {graphql} from 'graphql';
import invariant from '../common/invariant';
import stableStringify from '../common/stableStringify';
import LRUCache from './LRUCache';
import getLoaders from './getLoaders';
......@@ -14,7 +15,7 @@ import schema from './schema';
function getCache(hash: string) {
return {
hash,
storage: new LRUCache(),
storage: new LRUCache<string>(),
};
}
......@@ -34,6 +35,7 @@ export default (async function runQuery(id: string, variables: ?Object) {
id,
variables,
});
invariant(key, 'Expected non-void key');
if (cache.storage.has(key)) {
return cache.storage.get(key);
} else {
......
import {GraphQLInt, GraphQLNonNull, GraphQLObjectType, GraphQLString} from 'graphql';
import {
GraphQLInt,
GraphQLNonNull,
GraphQLObjectType,
GraphQLString,
} from 'graphql';
import {globalIdField} from 'graphql-relay';
import getHistoryURLForContentPath from '../../getHistoryURLForContentPath';
import Post from '../../models/Post';
......
......@@ -7,5 +7,6 @@ declare module 'relay-runtime' {
// - https://github.com/facebook/relay/issues/1689
// - https://github.com/facebook/relay/issues/1758
declare type ConcreteFragment = any;
declare type ConcreteBatch = any;
declare type ConcreteRequest = any;
declare type FragmentReference = any;
}
......@@ -313,7 +313,7 @@
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-syntax-json-strings" "^7.2.0"
"@babel/plugin-proposal-nullish-coalescing-operator@7.2.0":
"@babel/plugin-proposal-nullish-coalescing-operator@*":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-nullish-coalescing-operator/-/plugin-proposal-nullish-coalescing-operator-7.2.0.tgz#c3fda766187b2f2162657354407247a758ee9cf9"
integrity sha512-QXj/YjFuFJd68oDvoc1e8aqLr2wz7Kofzvp6Ekd/o7MWZl+nZ0/cpStxND+hlZ7DpRWAp7OmuyT2areZ2V3YUA==
......@@ -337,7 +337,7 @@
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-syntax-optional-catch-binding" "^7.2.0"
"@babel/plugin-proposal-optional-chaining@7.2.0":
"@babel/plugin-proposal-optional-chaining@*":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.2.0.tgz#ae454f4c21c6c2ce8cb2397dc332ae8b420c5441"
integrity sha512-ea3Q6edZC/55wEBVZAEz42v528VulyO0eir+7uky/sT4XRcdkWJcFi1aPtitTlwUzGnECWJNExWww1SStt+yWw==
......