Skip to content

Commit 4d18333

Browse files
committed
DataLoader
DataLoader is a generic utility to be used as part of your application's data fetching layer to provide a consistent API over various key-value store backends and reduce requests to those back-ends via batching and caching. A port of the "Loader" API originally developed by @schrockn at Facebook in 2010 as a simplifying force to coalesce the sundry key-value store back-end APIs which existed at the time. At Facebook, "Loader" became one of the implementation details of the "Ent" framework, a privacy-aware data entity loading and caching layer within web server product code. This ultimately became the underpinning for Facebook's GraphQL server implementation and type definitions. DataLoader is presented in the hope that it may be useful to produce a similar GraphQL underpinning for other systems which use graphql-js along side key-value stores, or at the very least remain a publicly available example of this abstraction.
0 parents  commit 4d18333

File tree

17 files changed

+2084
-0
lines changed

17 files changed

+2084
-0
lines changed

.eslintrc

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
{
2+
"parser": "babel-eslint",
3+
4+
"plugins": [
5+
"babel"
6+
],
7+
8+
"env": {
9+
"es6": true,
10+
"node": true
11+
},
12+
13+
"ecmaFeatures": {
14+
"arrowFunctions": true,
15+
"binaryLiterals": true,
16+
"blockBindings": true,
17+
"classes": true,
18+
"defaultParams": true,
19+
"destructuring": true,
20+
"experimentalObjectRestSpread": true,
21+
"forOf": true,
22+
"generators": true,
23+
"globalReturn": true,
24+
"jsx": true,
25+
"modules": true,
26+
"objectLiteralComputedProperties": true,
27+
"objectLiteralDuplicateProperties": true,
28+
"objectLiteralShorthandMethods": true,
29+
"objectLiteralShorthandProperties": true,
30+
"octalLiterals": true,
31+
"regexUFlag": true,
32+
"regexYFlag": true,
33+
"restParams": true,
34+
"spread": true,
35+
"superInFunctions": true,
36+
"templateStrings": true,
37+
"unicodeCodePointEscapes": true
38+
},
39+
40+
"rules": {
41+
"babel/arrow-parens": [2, "as-needed"],
42+
43+
"array-bracket-spacing": [2, "always"],
44+
"arrow-spacing": 2,
45+
"block-scoped-var": 0,
46+
"brace-style": [2, "1tbs", {"allowSingleLine": true}],
47+
"callback-return": 2,
48+
"camelcase": [2, {"properties": "always"}],
49+
"comma-dangle": 0,
50+
"comma-spacing": 0,
51+
"comma-style": [2, "last"],
52+
"complexity": 0,
53+
"computed-property-spacing": [2, "never"],
54+
"consistent-return": 0,
55+
"consistent-this": 0,
56+
"curly": [2, "all"],
57+
"default-case": 0,
58+
"dot-location": [2, "property"],
59+
"dot-notation": 0,
60+
"eol-last": 2,
61+
"eqeqeq": 2,
62+
"func-names": 0,
63+
"func-style": 0,
64+
"generator-star-spacing": [0, {"before": true, "after": false}],
65+
"guard-for-in": 2,
66+
"handle-callback-err": [2, "error"],
67+
"id-length": 0,
68+
"id-match": [2, "^(?:_?[a-zA-Z0-9]*)|[_A-Z0-9]+$"],
69+
"indent": [2, 2, {"SwitchCase": 1}],
70+
"init-declarations": 0,
71+
"key-spacing": [2, {"beforeColon": false, "afterColon": true}],
72+
"linebreak-style": 2,
73+
"lines-around-comment": 0,
74+
"max-depth": 0,
75+
"max-len": [2, 80, 4],
76+
"max-nested-callbacks": 0,
77+
"max-params": 0,
78+
"max-statements": 0,
79+
"new-cap": 0,
80+
"new-parens": 2,
81+
"newline-after-var": 0,
82+
"no-alert": 2,
83+
"no-array-constructor": 2,
84+
"no-bitwise": 0,
85+
"no-caller": 2,
86+
"no-catch-shadow": 0,
87+
"no-class-assign": 2,
88+
"no-cond-assign": 2,
89+
"no-console": 1,
90+
"no-const-assign": 2,
91+
"no-constant-condition": 2,
92+
"no-continue": 0,
93+
"no-control-regex": 0,
94+
"no-debugger": 1,
95+
"no-delete-var": 2,
96+
"no-div-regex": 2,
97+
"no-dupe-args": 2,
98+
"no-dupe-keys": 2,
99+
"no-duplicate-case": 2,
100+
"no-else-return": 2,
101+
"no-empty": 2,
102+
"no-empty-character-class": 2,
103+
"no-empty-label": 2,
104+
"no-eq-null": 0,
105+
"no-eval": 2,
106+
"no-ex-assign": 2,
107+
"no-extend-native": 2,
108+
"no-extra-bind": 2,
109+
"no-extra-boolean-cast": 2,
110+
"no-extra-parens": 0,
111+
"no-extra-semi": 2,
112+
"no-fallthrough": 2,
113+
"no-floating-decimal": 2,
114+
"no-func-assign": 2,
115+
"no-implicit-coercion": 2,
116+
"no-implied-eval": 2,
117+
"no-inline-comments": 0,
118+
"no-inner-declarations": [2, "functions"],
119+
"no-invalid-regexp": 2,
120+
"no-invalid-this": 0,
121+
"no-irregular-whitespace": 2,
122+
"no-iterator": 2,
123+
"no-label-var": 2,
124+
"no-labels": 0,
125+
"no-lone-blocks": 2,
126+
"no-lonely-if": 2,
127+
"no-loop-func": 0,
128+
"no-mixed-requires": [2, true],
129+
"no-mixed-spaces-and-tabs": 2,
130+
"no-multi-spaces": 2,
131+
"no-multi-str": 2,
132+
"no-multiple-empty-lines": 0,
133+
"no-native-reassign": 0,
134+
"no-negated-in-lhs": 2,
135+
"no-nested-ternary": 0,
136+
"no-new": 2,
137+
"no-new-func": 0,
138+
"no-new-object": 2,
139+
"no-new-require": 2,
140+
"no-new-wrappers": 2,
141+
"no-obj-calls": 2,
142+
"no-octal": 2,
143+
"no-octal-escape": 2,
144+
"no-param-reassign": 2,
145+
"no-path-concat": 2,
146+
"no-plusplus": 0,
147+
"no-process-env": 0,
148+
"no-process-exit": 0,
149+
"no-proto": 2,
150+
"no-redeclare": 2,
151+
"no-regex-spaces": 2,
152+
"no-restricted-modules": 0,
153+
"no-return-assign": 2,
154+
"no-script-url": 2,
155+
"no-self-compare": 0,
156+
"no-sequences": 2,
157+
"no-shadow": 2,
158+
"no-shadow-restricted-names": 2,
159+
"no-spaced-func": 2,
160+
"no-sparse-arrays": 2,
161+
"no-sync": 2,
162+
"no-ternary": 0,
163+
"no-this-before-super": 2,
164+
"no-throw-literal": 2,
165+
"no-trailing-spaces": 2,
166+
"no-undef": 2,
167+
"no-undef-init": 2,
168+
"no-undefined": 0,
169+
"no-underscore-dangle": 0,
170+
"no-unexpected-multiline": 2,
171+
"no-unneeded-ternary": 2,
172+
"no-unreachable": 2,
173+
"no-unused-expressions": 2,
174+
"no-unused-vars": [2, {"vars": "all", "args": "after-used"}],
175+
"no-use-before-define": 0,
176+
"no-useless-call": 2,
177+
"no-var": 0,
178+
"no-void": 2,
179+
"no-warning-comments": 0,
180+
"no-with": 2,
181+
"object-curly-spacing": [0, "always"],
182+
"object-shorthand": [2, "always"],
183+
"one-var": [2, "never"],
184+
"operator-assignment": [2, "always"],
185+
"operator-linebreak": [2, "after"],
186+
"padded-blocks": 0,
187+
"prefer-const": 0,
188+
"prefer-reflect": 0,
189+
"prefer-spread": 0,
190+
"quote-props": [2, "as-needed"],
191+
"quotes": [2, "single"],
192+
"radix": 2,
193+
"require-yield": 2,
194+
"semi": [2, "always"],
195+
"semi-spacing": [2, {"before": false, "after": true}],
196+
"sort-vars": 0,
197+
"space-after-keywords": [2, "always"],
198+
"space-before-blocks": [2, "always"],
199+
"space-before-function-paren": [2, {"anonymous": "always", "named": "never"}],
200+
"space-in-parens": 0,
201+
"space-infix-ops": [2, {"int32Hint": false}],
202+
"space-return-throw-case": 2,
203+
"space-unary-ops": [2, {"words": true, "nonwords": false}],
204+
"spaced-comment": [2, "always"],
205+
"strict": 0,
206+
"use-isnan": 2,
207+
"valid-jsdoc": 0,
208+
"valid-typeof": 2,
209+
"vars-on-top": 0,
210+
"wrap-iife": 2,
211+
"wrap-regex": 0,
212+
"yoda": [2, "never", {"exceptRange": true}]
213+
}
214+
}

.flowconfig

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

.gitignore

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

.travis.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
language: node_js
2+
3+
node_js:
4+
- "stable"
5+
- "iojs"
6+
- "0.12"
7+
- "0.10"
8+
9+
before_install:
10+
- npm config set spin false --global
11+
12+
script:
13+
- npm run lint && npm run check && (if [[ "$TRAVIS_JOB_NUMBER" == *.1 ]]; then npm run cover:lcov; else npm run testonly; fi)
14+
15+
after_failure:
16+
- (cd resources; python travis_after_all.py)
17+
18+
after_success:
19+
- (cd resources; python travis_after_all.py)
20+
- export $(cat resources/.to_export_back)
21+
- if [[ "$TRAVIS_JOB_NUMBER" == *.1 ]]; then cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js; fi
22+
23+
deploy:
24+
provider: npm
25+
26+
api_key:
27+
secure: tCIGE/3CLOQlC49i/9ug42ILQjZnMOrSjyjdHkqmTVN5q9p9bljjziXQbNxYfVPYa9icICnVnI4c5psjktW+vwaz2WJAJhpWD6P3YGcpmKjjgPKKHKWOcXvq3HdIzH7DIbXyVtE0QLpV5zgbyxglD96vYScO9dvGeAhTGY/9qJaDvVkLOZ+6YpKiTwZlZcyPHlD1tbxzd4NytJgIsi7CedFdfATAmOyVsot1NRZr5q3oV0aXFjJRnhBQ3RtykGgGHtXEWYTNhAmYxcIwezYRYXLxtlkbrlwxixpKAdJr/UXHg6amplkaHtCopi+QChPQRmdndcDC6F+e2nFHut6BCi14Jnbvf7seaqWrmh0uqdopqMJFRP3OBc9lXZf3hljVKV9+iVbWNjxoUB7ezurOOEpgkXleJ5AO2o3u8oYh3OFfLYu7E1a4uSjfe4nP/zi+th+wvS4Wy2UWqErYFUMotMyStS/vllXUpK7pl+Qt59MUVHB8YzREyCVKxakQ/uvNvY+bzKf4sM8UJ/Dqnl3MaAjLG3rWZbFyzXdaJnRGdTeFK2lpz8nrfJEDzLIQX5ZC88yR30WahrRjAhLnnq0V1fYp0wLbLxs4SdN+tuMRlkzQhQEYYDYa5osgEo2C+O4D/H9F7GWHHJp9zPE+hMi5+ZwTPKHkln4/AqrABUKOk78=
28+
on:
29+
tags: true
30+
branch: master
31+
condition: "$BUILD_LEADER$BUILD_AGGREGATE_STATUS = YESothers_succeeded"

CONTRIBUTING.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Contributing to DataLoader
2+
3+
We want to make contributing to this project as easy and transparent as
4+
possible.
5+
6+
## Pull Requests
7+
8+
We actively welcome your pull requests for documentation and code.
9+
10+
1. Fork the repo and create your branch from `master`.
11+
2. If you've added code that should be tested, add tests with 100% coverage.
12+
3. If you've changed APIs, update the documentation.
13+
4. Ensure the test suite passes.
14+
5. Make sure your code lints.
15+
6. If you haven't already, complete the Contributor License Agreement ("CLA").
16+
17+
## Contributor License Agreement ("CLA")
18+
19+
In order to accept your pull request, we need you to submit a CLA. You only need
20+
to do this once to work on any of Facebook's open source projects.
21+
22+
Complete your CLA here: <https://code.facebook.com/cla>
23+
24+
## Issues
25+
26+
We use GitHub issues to track public bugs. Please ensure your description is
27+
clear and has sufficient instructions to be able to reproduce the issue.
28+
29+
Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe
30+
disclosure of security bugs. In those cases, please go through the process
31+
outlined on that page and do not file a public issue.
32+
33+
## Coding Style
34+
35+
* 2 spaces for indentation rather than tabs
36+
* 80 character line length
37+
* See .eslintrc for the gory details.
38+
39+
## License
40+
41+
By contributing to DataLoader, you agree that your contributions will be
42+
licensed under its BSD license.

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 DataLoader 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 DataLoader 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.

0 commit comments

Comments
 (0)