Skip to content

Commit a6d8947

Browse files
authored
Merge pull request #50 from lacker/graphqljs
Add a sidebar for the graphql.js docs
2 parents 7264d6c + b98f82e commit a6d8947

20 files changed

+92
-44
lines changed

site/_core/CodeLayout.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright (c) 2016, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
var path = require('path');
10+
var React = require('react');
11+
var Site = require('./Site');
12+
var Marked = require('./Marked');
13+
var DocsSidebar = require('./DocsSidebar');
14+
15+
var CodeLayout = React.createClass({
16+
render: function() {
17+
var page = this.props.page;
18+
var site = this.props.site;
19+
var firstURL = '/graphql-js/getting-started/';
20+
return (
21+
<Site section="docs" title={page.title}>
22+
<section className="content documentationContent">
23+
<DocsSidebar site={site} page={page} firstURL={firstURL}/>
24+
<div className="inner-content">
25+
<h1>{page.title}</h1>
26+
<Marked>{page.content}</Marked>
27+
<div className="docs-prevnext">
28+
{page.previous && <a className="docs-prev" href={path.resolve(page.url, page.previous)}>&larr; Prev</a>}
29+
{page.next && <a className="docs-next" href={path.resolve(page.url, page.next)}>Next &rarr;</a>}
30+
</div>
31+
</div>
32+
</section>
33+
</Site>
34+
);
35+
}
36+
});
37+
38+
module.exports = CodeLayout;

site/_core/DocsSidebar.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var React = require('react');
1111
var DocsSidebar = React.createClass({
1212
render: function() {
1313
return <div className="nav-docs">
14-
{getCategories(this.props.site).map((category) =>
14+
{getCategories(this.props.site, this.props.firstURL).map((category) =>
1515
<div className="nav-docs-section" key={category.name}>
1616
<h3>{category.name}</h3>
1717
<ul>
@@ -22,7 +22,7 @@ var DocsSidebar = React.createClass({
2222
style={{marginLeft: page.indent ? 20 : 0}}
2323
className={page.id === this.props.page.id ? 'active' : ''}
2424
href={page.url}>
25-
{page.title}
25+
{page.sidebarTitle || page.title}
2626
</a>
2727
</li>
2828
)}
@@ -33,7 +33,9 @@ var DocsSidebar = React.createClass({
3333
}
3434
});
3535

36-
function getCategories(site) {
36+
// If firstURL is provided, it's the URL (starting with /) of the
37+
// first page to put on the sidebar.
38+
function getCategories(site, firstURL) {
3739
var pages = site.files.docs.filter(file => file.content);
3840

3941
// Build a hashmap of url -> page
@@ -61,11 +63,14 @@ function getCategories(site) {
6163
var first = null;
6264
for (var i = 0; i < pages.length; ++i) {
6365
var page = pages[i];
64-
if (!previous[page.url]) {
66+
if (firstURL ? (firstURL === page.url) : !previous[page.url]) {
6567
first = page;
6668
break;
6769
}
6870
}
71+
if (!first) {
72+
throw new Error('first not found');
73+
}
6974

7075
var categories = [];
7176
var currentCategory = null;

site/code/index.html.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@
99
var React = require('react');
1010
var Site = require('../_core/Site');
1111
var Marked = require('../_core/Marked');
12+
var DocsSidebar = require('../_core/DocsSidebar');
1213

1314
var Code = React.createClass({
1415
render: function() {
16+
var page = this.props.page;
17+
var site = this.props.site;
18+
var firstURL = '/graphql-js/getting-started/';
1519
return (
1620
<Site section="code" title="Code">
1721

18-
<section className="content documentationContent nosidebar">
22+
<section className="content documentationContent">
23+
<DocsSidebar site={site} page={page} firstURL={firstURL}/>
1924
<div className="inner-content">
2025
<h1>Code</h1>
2126
<Marked>{`
@@ -24,8 +29,8 @@ Many different programming languages support GraphQL. This list contains some of
2429
2530
## GraphQL Server Libraries
2631
27-
- [GraphQL.js](/graphql-js/) ([github](https://github.com/graphql/graphql-js)) ([npm](https://www.npmjs.com/package/graphql)): The reference implementation of the GraphQL specification, designed for running a GraphQL server in a Node.js environment.
28-
- [express-graphql](/graphql-js/) ([github](https://github.com/graphql/express-graphql)) ([npm](https://www.npmjs.com/package/express-graphql)): The reference implementation of a GraphQL API server over an Express webserver. You can use this to run GraphQL in conjunction with a regular Express webserver, or as a standalone GraphQL server.
32+
- [GraphQL.js](/graphql-js/getting-started/) ([github](https://github.com/graphql/graphql-js/)) ([npm](https://www.npmjs.com/package/graphql)): The reference implementation of the GraphQL specification, designed for running a GraphQL server in a Node.js environment.
33+
- [express-graphql](/graphql-js/getting-started/) ([github](https://github.com/graphql/express-graphql)) ([npm](https://www.npmjs.com/package/express-graphql)): The reference implementation of a GraphQL API server over an Express webserver. You can use this to run GraphQL in conjunction with a regular Express webserver, or as a standalone GraphQL server.
2934
- [Graphene](http://graphene-python.org/) ([github](https://github.com/graphql-python/graphene)): A Python library for building GraphQL APIs. Built-in support for [Relay](https://facebook.github.io/relay/), Django, SQLAlchemy, and Google App Engine.
3035
- [graphql-ruby](https://github.com/rmosolgo/graphql-ruby): A Ruby library for building GraphQL APIs. Built-in support for Relay and Rails.
3136
- [graphql-java](https://github.com/graphql-java/graphql-java): A Java library for building GraphQL APIs.

site/docs/APIReference-Errors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Errors
3-
layout: ../_core/DocsLayout
3+
layout: ../_core/CodeLayout
44
category: API Reference
55
permalink: /docs/api-reference-errors/
66
next: /docs/api-reference-utilities/

site/docs/APIReference-Execution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Execution
3-
layout: ../_core/DocsLayout
3+
layout: ../_core/CodeLayout
44
category: API Reference
55
permalink: /docs/api-reference-execution/
66
next: /docs/api-reference-errors/

site/docs/APIReference-GraphQL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: GraphQL
3-
layout: ../_core/DocsLayout
3+
layout: ../_core/CodeLayout
44
category: API Reference
55
permalink: /docs/api-reference-graphql/
66
next: /docs/api-reference-language/

site/docs/APIReference-Language.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Language
3-
layout: ../_core/DocsLayout
3+
layout: ../_core/CodeLayout
44
category: API Reference
55
permalink: /docs/api-reference-language/
66
next: /docs/api-reference-type-system/

site/docs/APIReference-TypeSystem.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Type System
3-
layout: ../_core/DocsLayout
3+
layout: ../_core/CodeLayout
44
category: API Reference
55
permalink: /docs/api-reference-type-system/
66
next: /docs/api-reference-validation/

site/docs/APIReference-Utilities.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Utilities
3-
layout: ../_core/DocsLayout
3+
layout: ../_core/CodeLayout
44
category: API Reference
55
permalink: /docs/api-reference-utilities/
66
---
@@ -117,7 +117,7 @@ function buildClientSchema(
117117
Build a GraphQLSchema for use by client tools.
118118

119119
Given the result of a client running the introspection query, creates and
120-
returns a GraphQLSchema instance which can be then used with all graphql-js
120+
returns a GraphQLSchema instance which can be then used with all GraphQL.js
121121
tools, but cannot be used to execute a query, as introspection does not
122122
represent the "resolver", "parse" or "serialize" functions or any other
123123
server-internal mechanisms.
@@ -152,7 +152,7 @@ function buildASTSchema(
152152
153153
This takes the ast of a schema document produced by `parseSchemaIntoAST` in
154154
`graphql/language/schema` and constructs a GraphQLSchema instance which can be
155-
then used with all graphql-js tools, but cannot be used to execute a query, as
155+
then used with all GraphQL.js tools, but cannot be used to execute a query, as
156156
introspection does not represent the "resolver", "parse" or "serialize"
157157
functions or any other server-internal mechanisms.
158158

site/docs/APIReference-Validation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Validation
3-
layout: ../_core/DocsLayout
3+
layout: ../_core/CodeLayout
44
category: API Reference
55
permalink: /docs/api-reference-validation/
66
next: /docs/api-reference-execution/

0 commit comments

Comments
 (0)