├── .babelrc ├── .gitignore ├── .npmignore ├── .travis.yml ├── LICENSE ├── README.md ├── package.json ├── recipes ├── README.md ├── SSR.md ├── at-cached.md ├── at-live.md ├── cashay-schema.md ├── multi-part-queries.md ├── pagination.md ├── persisted-state.md ├── subscriber.md ├── subscriptions.md └── transports.md ├── src ├── Cashay.js ├── __tests__ │ ├── Cashay-data.js │ ├── Cashay-test.js │ ├── clientSchema.json │ ├── data │ │ ├── authors.js │ │ ├── comments.js │ │ ├── groups.js │ │ └── posts.js │ ├── parseSortPrint.js │ └── schema.js ├── createVariableDefinitions.js ├── helperClasses.js ├── index.js ├── mutate │ ├── ActiveQueries.js │ ├── __tests__ │ │ ├── createMutationFromQuery-data.js │ │ ├── createMutationFromQuery-tests.js │ │ ├── mergeMutations-data.js │ │ ├── mergeMutations-tests.js │ │ ├── namespaceMutation-data.js │ │ ├── namespaceMutation-tests.js │ │ └── removeNamespacing-tests.js │ ├── createBasicMutation.js │ ├── createMutationFromQuery.js │ ├── findTypeInQuery.js │ ├── hasMatchingVariables.js │ ├── isMutationResponseScalar.js │ ├── makeArgsFromVars.js │ ├── makeFriendlyStore.js │ ├── mergeMutations.js │ ├── namespaceMutation.js │ └── removeNamespacing.js ├── normalize │ ├── __tests__ │ │ ├── data-pagination-back.js │ │ ├── data-pagination-front.js │ │ ├── data-pagination.js │ │ ├── data-union.js │ │ ├── data.js │ │ ├── denormalizeStore-tests.js │ │ ├── mergeStores-tests.js │ │ └── normalizeResponse-tests.js │ ├── addDeps.js │ ├── denormalizeHelpers.js │ ├── denormalizeStore.js │ ├── duck.js │ ├── getCachedFieldState.js │ ├── getFieldState.js │ ├── getSubReqAST.js │ ├── mergeStores.js │ ├── normalizeResponse.js │ └── separateArgs.js ├── query │ ├── __tests__ │ │ ├── parseAndInitializeQuery-data.js │ │ └── parseAndInitializeQuery-tests.js │ ├── flushDependencies.js │ ├── parseAndInitializeQuery.js │ ├── printMinimalQuery.js │ └── queryHelpers.js ├── schema │ ├── __tests__ │ │ └── cashay-loader-tests.js │ ├── cashay-loader.js │ ├── introspectionQuery.js │ ├── transformSchema.js │ ├── updateSchema.babel.js │ └── updateSchema.js ├── subscribe │ └── processSubscriptionDoc.js ├── transports │ ├── HTTPTransport.js │ ├── Transport.js │ └── defaultHandleErrors.js └── utils.js └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015", "stage-1"] 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lib 2 | *.log 3 | node_modules 4 | .idea 5 | coverage 6 | .nyc_output 7 | actualResult.json 8 | expectedResult.json 9 | debug.js 10 | debug.babel.js 11 | 12 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .idea 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '5' 4 | - '4' 5 | after_success: 6 | - './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls' 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Matt Krick 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cashay", 3 | "version": "0.23.0", 4 | "description": "relay for the rest of us", 5 | "main": "lib/index.js", 6 | "bin": { 7 | "cashay-schema": "lib/schema/updateSchema.babel.js" 8 | }, 9 | "loader": "lib/schema/cashay-loader", 10 | "scripts": { 11 | "clean": "rimraf lib", 12 | "lint": "xo src/index.js --esnext --space --fix", 13 | "build": "babel -d lib/ src/", 14 | "watch": "babel -w -d lib/ src/", 15 | "prepublish": "npm run clean && npm run build", 16 | "test": "nyc ava ./src/**/__tests__/**/*-tests.js", 17 | "quicktest": "ava ./src/**/__tests__/**/*-tests.js", 18 | "buildTestSchema": "node ./lib/schema/updateSchema.babel.js src/__tests__/schema.js src/__tests__/clientSchema.json" 19 | }, 20 | "repository": { 21 | "type": "git", 22 | "url": "git+https://github.com/mattkrick/cashay.git" 23 | }, 24 | "keywords": [ 25 | "relay", 26 | "client", 27 | "cache", 28 | "redux" 29 | ], 30 | "author": "Matt Krick ", 31 | "license": "MIT", 32 | "bugs": { 33 | "url": "https://github.com/mattkrick/cashay/issues" 34 | }, 35 | "homepage": "https://github.com/mattkrick/cashay#readme", 36 | "devDependencies": { 37 | "ava": "0.15.2", 38 | "babel-cli": "6.9.0", 39 | "babel-preset-es2015": "^6.9.0", 40 | "babel-preset-stage-1": "^6.16.0", 41 | "babel-register": "^6.9.0", 42 | "coveralls": "^2.11.9", 43 | "nyc": "^6.4.4", 44 | "rimraf": "2.5.2", 45 | "xo": "0.15.1" 46 | }, 47 | "dependencies": { 48 | "graphql": "0.10.5", 49 | "isomorphic-fetch": "^2.2.1", 50 | "minimist": "^1.2.0", 51 | "regenerator-runtime": "^0.9.6" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /recipes/README.md: -------------------------------------------------------------------------------- 1 | # Recipes 2 | 3 | - [@live](./at-live.md) 4 | - [@cached](./at-cached.md) 5 | - [Multi-part queries](./multi-part-queries.md) 6 | - [Pagination](./pagination.md) 7 | - [Persisted state](./persisted-state.md) 8 | - [Schema (without webpack)](./cashay-schema.md) 9 | - [Server-side rendering](./SSR.md) 10 | - [Subscriptions](./subscriptions.md) 11 | - [Subscriber](./subscriber.md) 12 | - [Transports](./transports.md) 13 | -------------------------------------------------------------------------------- /recipes/SSR.md: -------------------------------------------------------------------------------- 1 | # Server-side rending 2 | 3 | Cashay supports server-side rending out of the box. 4 | 5 | First, you'll need to create a redux store: 6 | ``` 7 | const store = createStore(reducer, {}); 8 | ``` 9 | 10 | Second, you need to create the Cashay singleton: 11 | ``` 12 | import {cashay, ServerSideTransport} from 'cashay'; 13 | const cashaySchema = require('cashay!./utils/getCashaySchema.js'); 14 | cashay.create({ 15 | store, 16 | schema: cashaySchema, 17 | transport: new ServerSideTransport(...) 18 | }); 19 | ``` 20 | _Note: if you use a bundler like webpack, make sure that this file is included in the bundle. 21 | You'll want the `cashay` that you `import` here 22 | to be the same `cashay` that you use in your components. (singletons are no fun like that)_ 23 | 24 | Third, you'll want to stringify your state to send it down the wire: 25 | ``` 26 | const initialState = `window.__INITIAL_STATE__ = ${JSON.stringify(store.getState())}`; 27 | 28 | // assume you use a react jsx template for SSR 29 | 30 | 31 | ... 32 |