Skip to content

Commit b5ed31e

Browse files
committed
GraphQL technical preview
This is the first public commit in what has been a few months of internal development. Future development will occur in public directly in this repository.
0 parents  commit b5ed31e

File tree

106 files changed

+19458
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+19458
-0
lines changed

.flowconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[ignore]
2+
.*/lib/.*
3+
.*/coverage/.*
4+
.*/scripts/.*
5+
.*/node_modules/.*
6+
7+
[include]
8+
9+
[libs]
10+
11+
[options]

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.swp
2+
*~
3+
.*.haste_cache.*
4+
.DS_Store
5+
lib
6+
node_modules
7+
npm-debug.log
8+
coverage

CONTRIBUTING.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Contributing
2+
============
3+
4+
After cloning this repo, ensure dependencies are installed by running:
5+
6+
```sh
7+
npm install
8+
```
9+
10+
GraphQL is written in ES6 using [Babel](http://babeljs.io/), widely consumable
11+
JavaScript can be produced by running:
12+
13+
```sh
14+
npm run build
15+
```
16+
17+
Once `npm run build` has run, you may `require()` directly from node.
18+
19+
The full test suite can be evaluated by running:
20+
21+
```sh
22+
npm test
23+
```
24+
25+
While actively developing, we recommend running
26+
27+
```sh
28+
npm run watch
29+
```
30+
31+
in a terminal. This will watch the file system run lint, tests, and type
32+
checking automatically whenever you save a js file.
33+
34+
To lint the JS files and type interface checks run `npm run lint`.

LICENSE

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
BSD License
2+
3+
For GraphQL software
4+
5+
Copyright (c) 2015, Facebook, Inc. All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice, this
11+
list of conditions and the following disclaimer.
12+
13+
* Redistributions in binary form must reproduce the above copyright notice,
14+
this list of conditions and the following disclaimer in the documentation
15+
and/or other materials provided with the distribution.
16+
17+
* Neither the name Facebook nor the names of its contributors may be used to
18+
endorse or promote products derived from this software without specific
19+
prior written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
25+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

PATENTS

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Additional Grant of Patent Rights Version 2
2+
3+
"Software" means the GraphQL software distributed by Facebook, Inc.
4+
5+
Facebook, Inc. (“Facebook”) hereby grants to each recipient of the Software (“you”) a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (subject to the termination provision below) license under any Necessary Claims, to make, have made, use, sell, offer to sell, import, and otherwise transfer the Software. For avoidance of doubt, no license is granted under Facebook’s rights in any patent claims that are infringed by (i) modifications to the Software made by you or any third party or (ii) the Software in combination with any software or other technology.
6+
7+
The license granted hereunder will terminate, automatically and without notice, if you (or any of your subsidiaries, corporate affiliates or agents) initiate directly or indirectly, or take a direct financial interest in, any Patent Assertion: (i) against Facebook or any of its subsidiaries or corporate affiliates, (ii) against any party if such Patent Assertion arises in whole or in part from any software, technology, product or service of Facebook or any of its subsidiaries or corporate affiliates, or (iii) against any party relating to the Software. Notwithstanding the foregoing, if Facebook or any of its subsidiaries or corporate affiliates files a lawsuit alleging patent infringement against you in the first instance, and you respond by filing a patent infringement counterclaim in that lawsuit against that party that is unrelated to the Software, the license granted hereunder will not terminate under section (i) of this paragraph due to such counterclaim.
8+
9+
A “Necessary Claim” is a claim of a patent owned by Facebook that is necessarily infringed by the Software standing alone.
10+
11+
A “Patent Assertion” is any lawsuit or other action alleging direct, indirect, or contributory infringement or inducement to infringe any patent, including a cross-claim or counterclaim.

README.md

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# GraphQL.js
2+
3+
This is a technical preview of the JavaScript reference implementation for
4+
GraphQL, a query language created by Facebook for describing data requirements
5+
on complex application data models.
6+
7+
## Technical Preview Contents
8+
9+
This technical preview contains a [draft specification for GraphQL](https://github.com/facebook/graphql)
10+
and a reference implementation in JavaScript that implements that draft,
11+
GraphQL.js.
12+
13+
The reference implemention provides base libraries in javascript that would
14+
provide the basis for full GraphQL implementations and tools. It is not a fully
15+
standalone GraphQL server that a client developer could use to start
16+
manipulating and querying data. Most importantly it provides no mapping to a
17+
functioning, production-ready backend. The only “backend” we have targeted for
18+
this early preview are in-memory stubs in test cases.
19+
20+
We are releasing this now because after GraphQL was first discussed publically,
21+
many engineers used this information to implement the parts of the system that
22+
we discussed publically. We want to support those engineers by providing both a
23+
formal specification and a reference implementation for the system as a whole.
24+
25+
To that end the target audience is not the client developer, but those who have
26+
or are actively interested in building their own GraphQL implementations and
27+
tools. Critically we also want feedback on system and to incorporate that
28+
feedback in our final release.
29+
30+
In order to be broadly adopted GraphQL will have to target a wide
31+
variety of backends, frameworks, and languages, which will necessitate a
32+
collaborative effort across projects and organizations. This technical preview
33+
marks the beginning of that process.
34+
35+
## Getting Started
36+
37+
An overview of GraphQL in general is available in the
38+
[README](https://github.com/facebook/graphql/README) for the
39+
[Specification for GraphQL](https://github.com/facebook/graphql). That overview
40+
describes a simple set of GraphQL examples that exist as [tests](src/__tests__)
41+
in this repository. A good way to get started with this repository is to walk
42+
through that README and the corresponding tests in parallel.
43+
44+
### Using GraphQL.js
45+
46+
Install GraphQL.js from npm
47+
48+
```
49+
npm install graphql
50+
```
51+
52+
GraphQL.js provides two important capabilites: building a type schema, and
53+
serving queries against that type schema.
54+
55+
First, build a GraphQL type schema which maps to your code base.
56+
57+
```js
58+
var GraphQL = require('graphql');
59+
60+
var schema = new GraphQL.GraphQLSchema({
61+
query: new GraphQL.GraphQLObjectType({
62+
name: 'RootQueryType',
63+
fields: {
64+
hello: {
65+
type: GraphQL.GraphQLString,
66+
resolve: function() { return 'world'; }
67+
}
68+
}
69+
})
70+
});
71+
```
72+
73+
This defines a simple schema with one type and one field, that resolves
74+
to a fixed value. A more complex example is included in the top level
75+
[tests](src/__tests__) directory.
76+
77+
Then, serve the result of a query against that type schema.
78+
79+
```js
80+
var query = '{ hello }';
81+
82+
GraphQL.graphql(schema, query).then(function (result) {
83+
84+
// Prints
85+
// {
86+
// data: { hello: "world" }
87+
// }
88+
console.log(result);
89+
90+
});
91+
```
92+
93+
This runs a query fetching the one field defined. The `graphql` function will
94+
first ensure the query is syntactically and semantically valid before executing
95+
it, reporting errors otherwise.
96+
97+
```js
98+
var query = '{ boyhowdy }';
99+
100+
GraphQL.graphql(schema, query).then(function (result) {
101+
102+
// Prints
103+
// {
104+
// errors: [
105+
// { message: 'Cannot query field boyhowdy on RootQueryType',
106+
// locations: [ { line: 1, column: 3 } ] }
107+
// ]
108+
// }
109+
console.log(result);
110+
111+
});
112+
```
113+
114+
### Contributing
115+
116+
After cloning this repo, ensure dependencies are installed by running:
117+
118+
```sh
119+
npm install
120+
```
121+
122+
GraphQL is written in ES6 using [Babel](http://babeljs.io/), widely consumable
123+
JavaScript can be produced by running:
124+
125+
```sh
126+
npm run build
127+
```
128+
129+
Once `npm run build` has run, you may `require()` directly from node.
130+
131+
After developing, the full test suite can be evaluated by running:
132+
133+
```sh
134+
npm test
135+
```
136+
137+
While actively developing, we recommend running
138+
139+
```sh
140+
npm run watch
141+
```
142+
143+
in a terminal. This will watch the file system run lint, tests, and type
144+
checking automatically whenever you save a js file.
145+
146+
To lint the JS files and type interface checks run `npm run lint`.

0 commit comments

Comments
 (0)