├── .gitattributes ├── scripts ├── babel-relay-plugin │ ├── .gitignore │ ├── src │ │ ├── .flowconfig │ │ ├── __fixtures__ │ │ │ ├── templateString.fixture │ │ │ ├── fragmentOnBadType.fixture │ │ │ ├── queryWithoutFields.fixture │ │ │ ├── queryWithBadDirective.fixture │ │ │ ├── queryWithBadDirectiveArgs.fixture │ │ │ ├── nonExistantMutation.fixture │ │ │ ├── inlineFragmentWithoutType.fixture │ │ │ ├── mutationWithExtraArgs.fixture │ │ │ ├── mutationBadSchemaMissingArgs.fixture │ │ │ ├── mutationBadSchemaWrongArgs.fixture │ │ │ ├── nonRootNodeField.fixture │ │ │ ├── connectionWithNodesField.fixture │ │ │ ├── connectionWithoutArgs.fixture │ │ │ ├── fragment.fixture │ │ │ ├── connectionWithAfterLastArgs.fixture │ │ │ ├── metadataRequisite.fixture │ │ │ ├── connectionWithBeforeFirstArgs.fixture │ │ │ ├── introspectionQueryForSchema.fixture │ │ │ ├── fragmentWithName.fixture │ │ │ ├── introspectionQueryForType.fixture │ │ │ ├── fragmentDirectives.fixture │ │ │ ├── connectionWithoutArgsWithInlineFragment.fixture │ │ │ ├── metadataNonFindable.fixture │ │ │ ├── unionWithTypename.fixture │ │ │ ├── fragmentWithReference.fixture │ │ │ ├── fragmentWithoutCommas.fixture │ │ │ ├── connectionWithAfterLastArgsWithInlineFragment.fixture │ │ │ ├── mutationWithoutArgs.fixture │ │ │ ├── argsSubstitution.fixture │ │ │ ├── queryWithObjectArg.fixture │ │ │ ├── subscription.fixture │ │ │ ├── mutationWithName.fixture │ │ │ ├── argsInvalidValues.fixture │ │ │ ├── metadataGenerated.fixture │ │ │ ├── tagRelayQL.fixture │ │ │ ├── container.fixture │ │ │ ├── queryWithVarArgs.fixture │ │ │ ├── argsVariablesList.fixture │ │ │ ├── metadataVarArgs.fixture │ │ │ ├── fieldWithEmptyArrayArg.fixture │ │ │ ├── inlineFragment.fixture │ │ │ ├── fragmentWithModuleName.fixture │ │ │ ├── metadataConnectionLimitable.fixture │ │ │ └── mutation.fixture │ │ ├── invariant.js │ │ ├── find.js │ │ ├── GraphQLRelayDirective.js │ │ ├── GraphQL.js │ │ └── tools │ │ │ ├── generateSchemaJson.js │ │ │ └── transformGraphQL.js │ ├── README.md │ ├── lib │ │ ├── find.js │ │ ├── invariant.js │ │ ├── GraphQLRelayDirective.js │ │ ├── GraphQL.js │ │ └── tools │ │ │ ├── generateSchemaJson.js │ │ │ └── transformGraphQL.js │ ├── scripts │ │ ├── build-lib │ │ └── transform │ └── package.json └── jest │ └── updateSchema.js ├── examples ├── todo │ ├── .gitignore │ ├── public │ │ ├── base.css │ │ ├── index.css │ │ └── index.html │ ├── js │ │ └── queries │ │ │ └── ViewerQueries.js │ ├── build │ │ └── babelRelayPlugin.js │ ├── package.json │ ├── README.md │ └── scripts │ │ └── updateSchema.js ├── star-wars │ ├── .gitignore │ ├── public │ │ └── index.html │ ├── package.json │ ├── build │ │ └── babelRelayPlugin.js │ ├── js │ │ ├── routes │ │ │ └── StarWarsAppHomeRoute.js │ │ ├── components │ │ │ └── StarWarsShip.js │ │ └── app.js │ └── README.md ├── relay-treasurehunt │ ├── .gitignore │ ├── public │ │ └── index.html │ ├── package.json │ ├── build │ │ └── babelRelayPlugin.js │ ├── js │ │ ├── routes │ │ │ └── AppHomeRoute.js │ │ └── app.js │ └── README.md └── star-wars-angular │ ├── .gitignore │ ├── public │ └── index.html │ ├── build │ └── babelRelayPlugin.js │ ├── js │ └── routes │ │ └── StarWarsAppHomeRoute.js │ ├── package.json │ └── README.md ├── website ├── src │ ├── relay │ │ └── img │ │ │ ├── favicon.png │ │ │ ├── Guides-Containers-HOC-Relay.png │ │ │ └── logo.svg │ └── elements │ │ └── favicon │ │ └── favicon.ico ├── core │ ├── SiteData.js │ ├── H2.js │ ├── center.js │ ├── unindent.js │ ├── HeaderLinks.js │ └── Header.js ├── publish.sh ├── package.json ├── server │ └── buildGraphQLSpec.js ├── layout │ └── PageLayout.js └── README.md ├── src ├── container │ ├── generic │ │ ├── __mocks__ │ │ │ ├── GenericRelayContainer.js │ │ │ ├── GenericRelayRootContainer.js │ │ │ └── createQuerySetAndFragmentPointers.js │ │ └── __tests__ │ │ │ └── GenericRelayRootContainer-test.js │ ├── __mocks__ │ │ ├── RelayPropTypes.js │ │ ├── isReactComponent.js │ │ ├── isRelayContainer.js │ │ ├── RelayOSSContainerProxy.js │ │ └── getRelayQueries.js │ ├── isRelayContainer.js │ ├── isReactComponent.js │ └── __tests__ │ │ ├── isRelayContainer-test.js │ │ └── isReactComponent-test.js ├── __mocks__ │ ├── Relay.js │ └── RelayPublic.js ├── tools │ ├── __mocks__ │ │ ├── configureForRelayOSS.js │ │ ├── RelayError.js │ │ ├── RelayDeprecated.js │ │ ├── RelayTaskScheduler.js │ │ ├── RelayMetricsRecorder.js │ │ ├── isCompatibleRelayFragmentType.js │ │ └── RelayProfiler.js │ ├── RelayInternals.js │ ├── isCompatibleRelayFragmentType.js │ └── RelayError.js ├── query │ ├── __mocks__ │ │ ├── RelayQL.js │ │ ├── buildRQL.js │ │ ├── RelayQuery.js │ │ ├── fromGraphQL.js │ │ ├── toGraphQL.js │ │ ├── QueryBuilder.js │ │ ├── callsFromGraphQL.js │ │ ├── callsToGraphQL.js │ │ ├── createRelayQuery.js │ │ ├── fromGraphQLQuery.js │ │ ├── stableStringify.js │ │ ├── RelayQueryVisitor.js │ │ ├── RelayRouteFragment.js │ │ ├── forEachRootCallArg.js │ │ ├── RelayQueryTransform.js │ │ ├── RelayFragmentReference.js │ │ ├── RelayRefQueryDescriptor.js │ │ ├── serializeRelayQueryCall.js │ │ ├── getConcreteFragmentHash.js │ │ └── RelayQueryPath.js │ ├── createRelayQuery.js │ ├── RelayRefQueryDescriptor.js │ ├── callsToGraphQL.js │ ├── getConcreteFragmentHash.js │ ├── RelayRouteFragment.js │ └── __tests__ │ │ └── createRelayQuery-test.js ├── store │ ├── __mocks__ │ │ ├── RelayStore.js │ │ ├── RelayQueryWriter.js │ │ ├── RelayRecordState.js │ │ ├── RelayRecordStore.js │ │ ├── RelayStoreData.js │ │ ├── RelayChangeTracker.js │ │ ├── RelayDiskCacheReader.js │ │ ├── RelayGarbageCollector.js │ │ ├── RelayMutationTracker.js │ │ ├── RelayRecordStatusMap.js │ │ ├── filterExclusiveKeys.js │ │ ├── RelayQueryResultObservable.js │ │ ├── validateRelayReadQuery.js │ │ ├── readRelayQueryData.js │ │ ├── RelayRecord.js │ │ ├── RelayMockCacheManager.js │ │ └── RelayPendingQueryTracker.js │ ├── RelayStore.js │ ├── RelayRecordState.js │ ├── filterExclusiveKeys.js │ └── __tests__ │ │ └── RelayRecord-test.js ├── route │ ├── __mocks__ │ │ ├── RelayMetaRoute.js │ │ └── RelayRoute.js │ ├── RelayMetaRoute.js │ └── __tests__ │ │ └── RelayMetaRoute-test.js ├── traversal │ ├── __mocks__ │ │ ├── sortTypeFirst.js │ │ ├── filterRelayQuery.js │ │ ├── flattenRelayQuery.js │ │ ├── printRelayOSSQuery.js │ │ ├── flattenSplitRelayQueries.js │ │ ├── writeRelayUpdatePayload.js │ │ ├── containsRelayQueryRootCall.js │ │ ├── transformRelayQueryPayload.js │ │ ├── diffRelayQuery.js │ │ ├── subtractRelayQuery.js │ │ ├── checkRelayQueryData.js │ │ ├── findRelayQueryLeaves.js │ │ ├── intersectRelayQuery.js │ │ ├── writeRelayQueryPayload.js │ │ ├── inferRelayFieldsFromData.js │ │ └── splitDeferredRelayQueries.js │ ├── sortTypeFirst.js │ ├── __tests__ │ │ └── sortTypeFirst-test.js │ ├── filterRelayQuery.js │ ├── flattenSplitRelayQueries.js │ └── writeRelayQueryPayload.js ├── mutation │ ├── __mocks__ │ │ ├── RelayMutationType.js │ │ └── RelayMutationQueue.js │ └── RelayMutationType.js ├── network │ └── __mocks__ │ │ ├── RelayNetworkLayer.js │ │ ├── RelayQueryRequest.js │ │ ├── RelayMutationRequest.js │ │ └── fetchRelayQuery.js ├── __forks__ │ ├── traversal │ │ ├── __mocks__ │ │ │ └── printRelayQuery.js │ │ └── printRelayQuery.js │ ├── container │ │ ├── __mocks__ │ │ │ ├── RelayContainerProxy.js │ │ │ └── prepareRelayContainerProps.js │ │ ├── RelayContainerProxy.js │ │ └── prepareRelayContainerProps.js │ ├── interface │ │ ├── __mocks__ │ │ │ ├── RelayNodeInterface.js │ │ │ └── RelayConnectionInterface.js │ │ ├── RelayNodeInterface.js │ │ └── RelayConnectionInterface.js │ └── Relay.js ├── interface │ └── __mocks__ │ │ ├── RelayOSSNodeInterface.js │ │ └── RelayOSSConnectionInterface.js ├── legacy │ ├── store │ │ ├── __mocks__ │ │ │ ├── generateForceIndex.js │ │ │ ├── generateClientEdgeID.js │ │ │ ├── GraphQLMutatorConstants.js │ │ │ ├── recycleNodesInto.js │ │ │ ├── generateRQLFieldAlias.js │ │ │ ├── generateClientID.js │ │ │ ├── GraphQLFragmentPointer.js │ │ │ ├── GraphQLStoreRangeUtils.js │ │ │ └── GraphQLStoreChangeEmitter.js │ │ ├── DliteFetchModeConstants.js │ │ ├── generateForceIndex.js │ │ ├── generateClientEdgeID.js │ │ ├── generateClientID.js │ │ ├── generateRQLFieldAlias.js │ │ └── __tests__ │ │ │ └── generateRQLFieldAlias-test.js │ └── mutation │ │ └── __mocks__ │ │ └── GraphQLMutatorConstants.js ├── network-layer │ └── default │ │ └── __mocks__ │ │ └── RelayDefaultNetworkLayer.js ├── .flowconfig └── query-config │ └── __mocks__ │ └── RelayQueryConfig.js ├── .travis.yml ├── .gitignore ├── .eslintignore ├── website-prototyping-tools ├── playground.html ├── logo.svg ├── babelRelayPlaygroundPlugin.js ├── evalSchema.js └── package.json ├── .eslintrc └── docs ├── GraphQL-FurtherReading.md ├── QuickStart-Videos.md └── APIReference-PropTypes.md /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | -------------------------------------------------------------------------------- /examples/todo/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | data/schema.graphql 3 | -------------------------------------------------------------------------------- /examples/star-wars/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | data/schema.graphql 3 | -------------------------------------------------------------------------------- /examples/todo/public/base.css: -------------------------------------------------------------------------------- 1 | ../node_modules/todomvc-common/base.css -------------------------------------------------------------------------------- /examples/todo/public/index.css: -------------------------------------------------------------------------------- 1 | ../node_modules/todomvc-app-css/index.css -------------------------------------------------------------------------------- /examples/relay-treasurehunt/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | data/schema.graphql 3 | -------------------------------------------------------------------------------- /examples/star-wars-angular/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | data/schema.graphql 3 | -------------------------------------------------------------------------------- /website/src/relay/img/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andimarek/generic-relay/HEAD/website/src/relay/img/favicon.png -------------------------------------------------------------------------------- /website/src/elements/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andimarek/generic-relay/HEAD/website/src/elements/favicon/favicon.ico -------------------------------------------------------------------------------- /src/container/generic/__mocks__/GenericRelayContainer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = require.requireActual('GenericRelayContainer'); 4 | -------------------------------------------------------------------------------- /src/container/generic/__mocks__/GenericRelayRootContainer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = require.requireActual('GenericRelayRootContainer'); 4 | -------------------------------------------------------------------------------- /website/src/relay/img/Guides-Containers-HOC-Relay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andimarek/generic-relay/HEAD/website/src/relay/img/Guides-Containers-HOC-Relay.png -------------------------------------------------------------------------------- /src/container/generic/__mocks__/createQuerySetAndFragmentPointers.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = require.requireActual('createQuerySetAndFragmentPointers'); 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: node_js 3 | node_js: 4 | - '4' 5 | env: 6 | - TEST_DIR=. 7 | - TEST_DIR=scripts/babel-relay-plugin 8 | script: cd $TEST_DIR && npm install && npm test 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .nvmrc 2 | node_modules 3 | npm-debug.log 4 | /dist/ 5 | /lib/ 6 | /website/build 7 | /website/src/relay/docs 8 | /website/src/relay/graphql 9 | /website/src/relay/prototyping 10 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | .*/__fixtures__/.* 3 | .*/__tests__/.* 4 | 5 | [include] 6 | ../node_modules/ 7 | 8 | [libs] 9 | ../interfaces 10 | 11 | [options] 12 | 13 | [version] 14 | 0.20.1 15 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/templateString.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = `Just a template string.`; 4 | 5 | Output: 6 | var Relay = require('react-relay'); 7 | var x = 'Just a template string.'; 8 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | docs/ 3 | **/node_modules/ 4 | examples/**/updateSchema.js 5 | lib/ 6 | scripts/ 7 | # TODO: Enable ESLint for website. 8 | website/ 9 | website-prototyping-tools/HelloApp.js 10 | website-prototyping-tools/node_modules 11 | *.md 12 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/fragmentOnBadType.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL`fragment on NotAType { id }`; 4 | 5 | Output: 6 | var Relay = require('react-relay'); 7 | var x = (function () { 8 | throw new Error('GraphQL validation/transform error ``Unknown type "NotAType".`` in file `fragmentOnBadType.fixture`.'); 9 | })(); 10 | -------------------------------------------------------------------------------- /website-prototyping-tools/playground.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {%= o.htmlWebpackPlugin.options.title %} 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | --- 2 | parser: babel-eslint 3 | 4 | extends: 5 | - ./node_modules/fbjs-scripts/eslint/.eslintrc 6 | 7 | plugins: 8 | - react 9 | 10 | rules: 11 | react/jsx-uses-react: 2 12 | 13 | globals: 14 | $Enum: true 15 | $FixMe: true 16 | $FlowFixMe: true 17 | $FlowIssue: true 18 | Iterator: true 19 | IteratorResult: true 20 | ReactClass: true 21 | ReactElement: true 22 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/queryWithoutFields.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL`query { viewer }`; 4 | 5 | Output: 6 | var Relay = require('react-relay'); 7 | var x = (function () { 8 | return { 9 | fieldName: 'viewer', 10 | kind: 'Query', 11 | metadata: {}, 12 | name: 'QueryWithoutFields', 13 | type: 'Viewer' 14 | }; 15 | })(); 16 | -------------------------------------------------------------------------------- /src/__mocks__/Relay.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require('RelayPublic'); 13 | -------------------------------------------------------------------------------- /src/tools/__mocks__/configureForRelayOSS.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | global.__RELAYOSS__ = true; 13 | -------------------------------------------------------------------------------- /src/__mocks__/RelayPublic.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayPublic'); 13 | -------------------------------------------------------------------------------- /src/query/__mocks__/RelayQL.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayQL'); 13 | -------------------------------------------------------------------------------- /src/query/__mocks__/buildRQL.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('buildRQL'); 13 | -------------------------------------------------------------------------------- /src/query/__mocks__/RelayQuery.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayQuery'); 13 | -------------------------------------------------------------------------------- /src/query/__mocks__/fromGraphQL.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('fromGraphQL'); 13 | -------------------------------------------------------------------------------- /src/query/__mocks__/toGraphQL.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('toGraphQL'); 13 | -------------------------------------------------------------------------------- /src/store/__mocks__/RelayStore.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayStore'); 13 | -------------------------------------------------------------------------------- /src/tools/__mocks__/RelayError.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayError'); 13 | -------------------------------------------------------------------------------- /src/query/__mocks__/QueryBuilder.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('QueryBuilder'); 13 | -------------------------------------------------------------------------------- /website/core/SiteData.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule SiteData 10 | */ 11 | 12 | module.exports = { 13 | version: '0.6.1' 14 | }; 15 | -------------------------------------------------------------------------------- /src/container/__mocks__/RelayPropTypes.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayPropTypes'); 13 | -------------------------------------------------------------------------------- /src/query/__mocks__/callsFromGraphQL.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('callsFromGraphQL'); 13 | -------------------------------------------------------------------------------- /src/query/__mocks__/callsToGraphQL.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('callsToGraphQL'); 13 | -------------------------------------------------------------------------------- /src/query/__mocks__/createRelayQuery.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('createRelayQuery'); 13 | -------------------------------------------------------------------------------- /src/query/__mocks__/fromGraphQLQuery.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('fromGraphQLQuery'); 13 | -------------------------------------------------------------------------------- /src/query/__mocks__/stableStringify.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('stableStringify'); 13 | -------------------------------------------------------------------------------- /src/route/__mocks__/RelayMetaRoute.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayMetaRoute'); 13 | -------------------------------------------------------------------------------- /src/store/__mocks__/RelayQueryWriter.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayQueryWriter'); 13 | -------------------------------------------------------------------------------- /src/store/__mocks__/RelayRecordState.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayRecordState'); 13 | -------------------------------------------------------------------------------- /src/store/__mocks__/RelayRecordStore.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayRecordStore'); 13 | -------------------------------------------------------------------------------- /src/store/__mocks__/RelayStoreData.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayStoreData'); 13 | -------------------------------------------------------------------------------- /src/tools/__mocks__/RelayDeprecated.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayDeprecated'); 13 | -------------------------------------------------------------------------------- /src/traversal/__mocks__/sortTypeFirst.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('sortTypeFirst'); 13 | -------------------------------------------------------------------------------- /src/container/__mocks__/isReactComponent.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('isReactComponent'); 13 | -------------------------------------------------------------------------------- /src/container/__mocks__/isRelayContainer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('isRelayContainer'); 13 | -------------------------------------------------------------------------------- /src/mutation/__mocks__/RelayMutationType.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayMutationType'); 13 | -------------------------------------------------------------------------------- /src/network/__mocks__/RelayNetworkLayer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayNetworkLayer'); 13 | -------------------------------------------------------------------------------- /src/network/__mocks__/RelayQueryRequest.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayQueryRequest'); 13 | -------------------------------------------------------------------------------- /src/query/__mocks__/RelayQueryVisitor.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayQueryVisitor'); 13 | -------------------------------------------------------------------------------- /src/query/__mocks__/RelayRouteFragment.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayRouteFragment'); 13 | -------------------------------------------------------------------------------- /src/query/__mocks__/forEachRootCallArg.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('forEachRootCallArg'); 13 | -------------------------------------------------------------------------------- /src/store/__mocks__/RelayChangeTracker.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayChangeTracker'); 13 | -------------------------------------------------------------------------------- /src/tools/__mocks__/RelayTaskScheduler.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayTaskScheduler'); 13 | -------------------------------------------------------------------------------- /src/traversal/__mocks__/filterRelayQuery.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('filterRelayQuery'); 13 | -------------------------------------------------------------------------------- /src/mutation/__mocks__/RelayMutationQueue.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayMutationQueue'); 13 | -------------------------------------------------------------------------------- /src/network/__mocks__/RelayMutationRequest.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayMutationRequest'); 13 | -------------------------------------------------------------------------------- /src/query/__mocks__/RelayQueryTransform.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayQueryTransform'); 13 | -------------------------------------------------------------------------------- /src/store/__mocks__/RelayDiskCacheReader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayDiskCacheReader'); 13 | -------------------------------------------------------------------------------- /src/store/__mocks__/RelayGarbageCollector.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayGarbageCollector'); 13 | -------------------------------------------------------------------------------- /src/store/__mocks__/RelayMutationTracker.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayMutationTracker'); 13 | -------------------------------------------------------------------------------- /src/store/__mocks__/RelayRecordStatusMap.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayRecordStatusMap'); 13 | -------------------------------------------------------------------------------- /src/store/__mocks__/filterExclusiveKeys.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('filterExclusiveKeys'); 13 | -------------------------------------------------------------------------------- /src/tools/__mocks__/RelayMetricsRecorder.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayMetricsRecorder'); 13 | -------------------------------------------------------------------------------- /src/traversal/__mocks__/flattenRelayQuery.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('flattenRelayQuery'); 13 | -------------------------------------------------------------------------------- /src/traversal/__mocks__/printRelayOSSQuery.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('printRelayOSSQuery'); 13 | -------------------------------------------------------------------------------- /src/__forks__/traversal/__mocks__/printRelayQuery.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('printRelayQuery'); 13 | -------------------------------------------------------------------------------- /src/interface/__mocks__/RelayOSSNodeInterface.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayOSSNodeInterface'); 13 | -------------------------------------------------------------------------------- /src/query/__mocks__/RelayFragmentReference.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayFragmentReference'); 13 | -------------------------------------------------------------------------------- /src/query/__mocks__/RelayRefQueryDescriptor.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayRefQueryDescriptor'); 13 | -------------------------------------------------------------------------------- /src/__forks__/container/__mocks__/RelayContainerProxy.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayContainerProxy'); 13 | -------------------------------------------------------------------------------- /src/__forks__/interface/__mocks__/RelayNodeInterface.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayNodeInterface'); 13 | -------------------------------------------------------------------------------- /src/container/__mocks__/RelayOSSContainerProxy.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayOSSContainerProxy'); 13 | -------------------------------------------------------------------------------- /src/legacy/store/__mocks__/generateForceIndex.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | */ 10 | 11 | 'use strict'; 12 | 13 | module.exports = require.requireActual('generateForceIndex'); 14 | -------------------------------------------------------------------------------- /src/query/__mocks__/serializeRelayQueryCall.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('serializeRelayQueryCall'); 13 | -------------------------------------------------------------------------------- /src/store/__mocks__/RelayQueryResultObservable.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayQueryResultObservable'); 13 | -------------------------------------------------------------------------------- /src/traversal/__mocks__/flattenSplitRelayQueries.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('flattenSplitRelayQueries'); 13 | -------------------------------------------------------------------------------- /src/traversal/__mocks__/writeRelayUpdatePayload.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('writeRelayUpdatePayload'); 13 | -------------------------------------------------------------------------------- /src/legacy/mutation/__mocks__/GraphQLMutatorConstants.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('GraphQLMutatorConstants'); 13 | -------------------------------------------------------------------------------- /src/legacy/store/__mocks__/generateClientEdgeID.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | */ 10 | 11 | 'use strict'; 12 | 13 | module.exports = require.requireActual('generateClientEdgeID'); 14 | -------------------------------------------------------------------------------- /src/query/__mocks__/getConcreteFragmentHash.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | */ 10 | 11 | 'use strict'; 12 | 13 | module.exports = require.requireActual('getConcreteFragmentHash'); 14 | -------------------------------------------------------------------------------- /src/traversal/__mocks__/containsRelayQueryRootCall.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('containsRelayQueryRootCall'); 13 | -------------------------------------------------------------------------------- /src/traversal/__mocks__/transformRelayQueryPayload.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('transformRelayQueryPayload'); 13 | -------------------------------------------------------------------------------- /src/__forks__/interface/__mocks__/RelayConnectionInterface.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayConnectionInterface'); 13 | -------------------------------------------------------------------------------- /src/interface/__mocks__/RelayOSSConnectionInterface.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayOSSConnectionInterface'); 13 | -------------------------------------------------------------------------------- /src/legacy/store/__mocks__/GraphQLMutatorConstants.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | */ 10 | 11 | 'use strict'; 12 | 13 | module.exports = require.requireActual('GraphQLMutatorConstants'); 14 | -------------------------------------------------------------------------------- /src/tools/__mocks__/isCompatibleRelayFragmentType.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('isCompatibleRelayFragmentType'); 13 | -------------------------------------------------------------------------------- /src/__forks__/container/__mocks__/prepareRelayContainerProps.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('prepareRelayContainerProps'); 13 | -------------------------------------------------------------------------------- /src/network-layer/default/__mocks__/RelayDefaultNetworkLayer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = require.requireActual('RelayDefaultNetworkLayer'); 13 | -------------------------------------------------------------------------------- /src/__forks__/traversal/printRelayQuery.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule printRelayQuery 10 | */ 11 | 12 | 'use strict'; 13 | 14 | module.exports = require('printRelayOSSQuery'); 15 | -------------------------------------------------------------------------------- /src/legacy/store/__mocks__/recycleNodesInto.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | jest.dontMock('recycleNodesInto'); 13 | 14 | module.exports = require('recycleNodesInto'); 15 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/queryWithBadDirective.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL` 4 | query { 5 | node(id: 123) @bad(if: $foo) { 6 | id 7 | } 8 | } 9 | `; 10 | 11 | Output: 12 | var Relay = require('react-relay'); 13 | var x = (function () { 14 | throw new Error('GraphQL validation/transform error ``You supplied a directive named `bad`, but no such directive exists.`` in file `queryWithBadDirective.fixture`.'); 15 | })(); 16 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/queryWithBadDirectiveArgs.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL` 4 | query { 5 | node(id: 123) @if(bad: $foo) { 6 | id 7 | } 8 | } 9 | `; 10 | 11 | Output: 12 | var Relay = require('react-relay'); 13 | var x = (function () { 14 | throw new Error('GraphQL validation/transform error ``You supplied a directive named `if`, but no such directive exists.`` in file `queryWithBadDirectiveArgs.fixture`.'); 15 | })(); 16 | -------------------------------------------------------------------------------- /src/__forks__/interface/RelayNodeInterface.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule RelayNodeInterface 10 | */ 11 | 12 | 'use strict'; 13 | 14 | module.exports = require('RelayOSSNodeInterface'); 15 | -------------------------------------------------------------------------------- /website/publish.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | # Start in website/ even if run from root directory 6 | cd "$(dirname "$0")" 7 | 8 | cd ../../relay-gh-pages 9 | # git checkout -- . 10 | # git clean -dfx 11 | # git fetch 12 | # git rebase 13 | rm -Rf * 14 | cd ../relay/website 15 | node server/generate.js 16 | cp -R build/relay/* ../../relay-gh-pages/ 17 | rm -Rf build/ 18 | cd ../../relay-gh-pages 19 | # git add --all 20 | # git commit -m "update website" 21 | # git push 22 | # cd ../relay/website 23 | -------------------------------------------------------------------------------- /src/__forks__/container/RelayContainerProxy.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule RelayContainerProxy 10 | */ 11 | 12 | 'use strict'; 13 | 14 | module.exports = require('RelayOSSContainerProxy'); 15 | -------------------------------------------------------------------------------- /src/traversal/__mocks__/diffRelayQuery.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = jest.genMockFunction().mockImplementation( 13 | require.requireActual('diffRelayQuery') 14 | ); 15 | -------------------------------------------------------------------------------- /src/traversal/__mocks__/subtractRelayQuery.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = jest.genMockFunction().mockImplementation( 13 | require.requireActual('subtractRelayQuery') 14 | ); 15 | -------------------------------------------------------------------------------- /src/__forks__/interface/RelayConnectionInterface.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule RelayConnectionInterface 10 | */ 11 | 12 | 'use strict'; 13 | 14 | module.exports = require('RelayOSSConnectionInterface'); 15 | -------------------------------------------------------------------------------- /src/store/__mocks__/validateRelayReadQuery.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | var validateRelayReadQuery = require.requireActual('validateRelayReadQuery'); 13 | module.exports = validateRelayReadQuery; 14 | -------------------------------------------------------------------------------- /src/traversal/__mocks__/checkRelayQueryData.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = jest.genMockFunction().mockImplementation( 13 | require.requireActual('checkRelayQueryData') 14 | ); 15 | -------------------------------------------------------------------------------- /src/traversal/__mocks__/findRelayQueryLeaves.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = jest.genMockFunction().mockImplementation( 13 | require.requireActual('findRelayQueryLeaves') 14 | ); 15 | -------------------------------------------------------------------------------- /src/traversal/__mocks__/intersectRelayQuery.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = jest.genMockFunction().mockImplementation( 13 | require.requireActual('intersectRelayQuery') 14 | ); 15 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/README.md: -------------------------------------------------------------------------------- 1 | # babel-relay-plugin 2 | 3 | ## Installation 4 | 5 | ```sh 6 | cd relay/scripts/babel-relay-plugin 7 | npm install 8 | ``` 9 | 10 | ## Tests 11 | 12 | ```sh 13 | npm test 14 | ``` 15 | 16 | ## Usage 17 | 18 | ```js 19 | var plugin = getBabelRelayPlugin(parsedSchemaJSON.data); 20 | 21 | babel.transform(source, { 22 | plugins: [plugin], 23 | ... 24 | }); 25 | ``` 26 | 27 | ## License 28 | 29 | Relay is [BSD licensed](./LICENSE). We also provide an additional [patent grant](./PATENTS). 30 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/nonExistantMutation.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL` 4 | mutation { 5 | fakeMutation(input: $input) { 6 | actor { 7 | profilePicture, 8 | }, 9 | }, 10 | } 11 | `; 12 | 13 | Output: 14 | var Relay = require('react-relay'); 15 | var x = (function () { 16 | throw new Error('GraphQL validation/transform error ``Cannot query field "fakeMutation" on "Mutation".`` in file `nonExistantMutation.fixture`.'); 17 | })(); 18 | -------------------------------------------------------------------------------- /src/__forks__/container/prepareRelayContainerProps.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule prepareRelayContainerProps 10 | */ 11 | 12 | 'use strict'; 13 | 14 | module.exports = require('prepareRelayOSSContainerProps'); 15 | -------------------------------------------------------------------------------- /src/legacy/store/__mocks__/generateRQLFieldAlias.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = jest.genMockFunction().mockImplementation( 13 | require.requireActual('generateRQLFieldAlias') 14 | ); 15 | -------------------------------------------------------------------------------- /src/traversal/__mocks__/writeRelayQueryPayload.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = jest.genMockFunction().mockImplementation( 13 | require.requireActual('writeRelayQueryPayload') 14 | ); 15 | -------------------------------------------------------------------------------- /src/traversal/__mocks__/inferRelayFieldsFromData.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = jest.genMockFunction().mockImplementation( 13 | require.requireActual('inferRelayFieldsFromData') 14 | ); 15 | -------------------------------------------------------------------------------- /src/traversal/__mocks__/splitDeferredRelayQueries.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | module.exports = jest.genMockFunction().mockImplementation( 13 | require.requireActual('splitDeferredRelayQueries') 14 | ); 15 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/inlineFragmentWithoutType.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | /* 4 | TODO: Upgrade to graphql@0.4.7 and uncomment this. 5 | 6 | var x = Relay.QL` 7 | fragment on Node { 8 | ... { 9 | id, 10 | }, 11 | } 12 | `; 13 | */ 14 | 15 | Output: 16 | var Relay = require('react-relay'); 17 | /* 18 | TODO: Upgrade to graphql@0.4.7 and uncomment this. 19 | 20 | var x = Relay.QL` 21 | fragment on Node { 22 | ... { 23 | id, 24 | }, 25 | } 26 | `; 27 | */ 28 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/mutationWithExtraArgs.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL` 4 | mutation MutationNameHere { 5 | actorSubscribe(input: $input, extra: $extra) { 6 | ${reference}, 7 | }, 8 | } 9 | `; 10 | 11 | Output: 12 | var Relay = require('react-relay'); 13 | var x = (function () { 14 | throw new Error('GraphQL validation/transform error ``Unknown argument "extra" on field "actorSubscribe" of type "Mutation".`` in file `mutationWithExtraArgs.fixture`.'); 15 | })(); 16 | -------------------------------------------------------------------------------- /src/container/__mocks__/getRelayQueries.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | var getRelayQueries = require.requireActual('getRelayQueries'); 13 | 14 | module.exports = jest.genMockFunction().mockImplementation(getRelayQueries); 15 | -------------------------------------------------------------------------------- /src/store/__mocks__/readRelayQueryData.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | var readRelayQueryData = require.requireActual('readRelayQueryData'); 13 | module.exports = jest.genMockFunction().mockImplementation(readRelayQueryData); 14 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/mutationBadSchemaMissingArgs.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL` 4 | mutation { 5 | mutationMissingArg, 6 | } 7 | `; 8 | 9 | Output: 10 | var Relay = require('react-relay'); 11 | var x = (function () { 12 | throw new Error('GraphQL validation/transform error ``Your schema defines a mutation field `mutationMissingArg` that takes 0 arguments, but mutation fields must have exactly one argument named `input`.`` in file `mutationBadSchemaMissingArgs.fixture`.'); 13 | })(); 14 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/mutationBadSchemaWrongArgs.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL` 4 | mutation { 5 | mutationWrongArgs, 6 | } 7 | `; 8 | 9 | Output: 10 | var Relay = require('react-relay'); 11 | var x = (function () { 12 | throw new Error('GraphQL validation/transform error ``Your schema defines a mutation field `mutationWrongArgs` that takes an argument named `foo`, but mutation fields must have exactly one argument named `input`.`` in file `mutationBadSchemaWrongArgs.fixture`.'); 13 | })(); 14 | -------------------------------------------------------------------------------- /src/legacy/store/__mocks__/generateClientID.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | var count = 1; 13 | 14 | var generateClientID = jest.genMockFunction().mockImplementation( 15 | () => { return 'client:' + count++; } 16 | ); 17 | 18 | module.exports = generateClientID; 19 | -------------------------------------------------------------------------------- /src/query/__mocks__/RelayQueryPath.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | var RelayQueryPath = require.requireActual('RelayQueryPath'); 13 | 14 | RelayQueryPath.fromJSON = jest.genMockFunction().mockImplementation( 15 | RelayQueryPath.fromJSON 16 | ); 17 | 18 | module.exports = RelayQueryPath; 19 | -------------------------------------------------------------------------------- /src/store/RelayStore.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule RelayStore 10 | * @flow 11 | * @typechecks 12 | */ 13 | 14 | 'use strict'; 15 | 16 | const RelayContext = require('RelayContext'); 17 | const RelayStoreData = require('RelayStoreData'); 18 | 19 | module.exports = new RelayContext(RelayStoreData.getDefaultInstance()); 20 | -------------------------------------------------------------------------------- /website/core/H2.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule H2 10 | */ 11 | 12 | var React = require('React'); 13 | var Header = require('Header'); 14 | 15 | var H2 = React.createClass({ 16 | render: function() { 17 | return
{this.props.children}
18 | } 19 | }); 20 | 21 | module.exports = H2; 22 | -------------------------------------------------------------------------------- /examples/star-wars/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Relay • Star Wars 7 | 8 | 9 |
10 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /website/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "repository": "facebook/relay", 3 | "license": "BSD-3-Clause", 4 | "scripts": { 5 | "start": "node server/server.js" 6 | }, 7 | "dependencies": { 8 | "compression": "1.2.2", 9 | "connect": "3.3.3", 10 | "errorhandler": "1.3.0", 11 | "fs-extra": "0.23.1", 12 | "glob": "*", 13 | "mkdirp": "*", 14 | "morgan": "1.5.0", 15 | "object-assign": "^2.0.0", 16 | "optimist": "0.6.0", 17 | "react": "~0.12.0", 18 | "react-page-middleware": "git://github.com/facebook/react-page-middleware.git", 19 | "request": "*", 20 | "serve-static": "1.7.1", 21 | "spec-md": "0.3.7" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/relay-treasurehunt/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Relay • Treasure Hunt 7 | 8 | 9 |
10 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/legacy/store/__mocks__/GraphQLFragmentPointer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | var GraphQLFragmentPointer = require.requireActual('GraphQLFragmentPointer'); 13 | 14 | GraphQLFragmentPointer.createForRoot = 15 | jest.genMockFunction().mockImplementation( 16 | GraphQLFragmentPointer.createForRoot 17 | ); 18 | 19 | module.exports = GraphQLFragmentPointer; 20 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/nonRootNodeField.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('Relay'); 3 | var fragment = Relay.QL` 4 | fragment on InvalidType { 5 | node(id: 123) { 6 | ... on User { 7 | name 8 | } 9 | } 10 | } 11 | `; 12 | 13 | Output: 14 | var Relay = require('Relay'); 15 | var fragment = (function () { 16 | throw new Error('GraphQL validation/transform error ``You defined a `node(id: Int)` field on type `InvalidType`, but Relay requires the `node` field to be defined on the root type. See the Object Identification Guide: \nhttp://facebook.github.io/relay/docs/graphql-object-identification.html`` in file `nonRootNodeField.fixture`.'); 17 | })(); 18 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/lib/find.js: -------------------------------------------------------------------------------- 1 | // @generated 2 | /** 3 | * Copyright 2013-2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | * 10 | * 11 | * @fullSyntaxTransform 12 | */ 13 | 14 | 'use strict'; 15 | 16 | function find(array, predicate, context) { 17 | for (var ii = 0; ii < array.length; ii++) { 18 | if (predicate.call(context, array[ii], ii, array)) { 19 | return array[ii]; 20 | } 21 | } 22 | return undefined; 23 | } 24 | 25 | module.exports = find; -------------------------------------------------------------------------------- /src/store/__mocks__/RelayRecord.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | const RelayRecord = require.requireActual('RelayRecord'); 13 | 14 | Object.keys(RelayRecord).forEach(name => { 15 | const method = RelayRecord[name]; 16 | if (typeof method === 'function') { 17 | RelayRecord[name] = jest.genMockFunction().mockImplementation(method); 18 | } 19 | }); 20 | 21 | module.exports = RelayRecord; 22 | -------------------------------------------------------------------------------- /src/legacy/store/DliteFetchModeConstants.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule DliteFetchModeConstants 10 | * @typechecks 11 | */ 12 | 13 | 'use strict'; 14 | 15 | const keyMirror = require('keyMirror'); 16 | 17 | var DliteFetchModeConstants = keyMirror({ 18 | FETCH_MODE_CLIENT: null, 19 | FETCH_MODE_PRELOAD: null, 20 | FETCH_MODE_REFETCH: null, 21 | }); 22 | 23 | module.exports = DliteFetchModeConstants; 24 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/connectionWithNodesField.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL` 4 | query { 5 | node(id: 123) { 6 | ... on User { 7 | friends(first: 3) { 8 | nodes { 9 | id, 10 | }, 11 | }, 12 | }, 13 | }, 14 | } 15 | `; 16 | 17 | Output: 18 | var Relay = require('react-relay'); 19 | var x = (function () { 20 | throw new Error('GraphQL validation/transform error ``You supplied a field named `nodes` on a connection named `friends`, but pagination is not supported on connections without using `edges`. Use `friends{edges{node{...}}}` instead.`` in file `connectionWithNodesField.fixture`.'); 21 | })(); 22 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/invariant.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @flow 10 | * @fullSyntaxTransform 11 | */ 12 | 13 | 'use strict'; 14 | 15 | const util = require('util'); 16 | 17 | function invariant( 18 | condition: mixed, 19 | format: string, 20 | ...args: Array 21 | ): void { 22 | if (!condition) { 23 | throw new Error(util.format(format, ...args)); 24 | } 25 | } 26 | 27 | module.exports = invariant; 28 | -------------------------------------------------------------------------------- /src/mutation/RelayMutationType.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule RelayMutationType 10 | * @typechecks 11 | * @flow 12 | */ 13 | 14 | 'use strict'; 15 | 16 | var RelayMutationType = { 17 | FIELDS_CHANGE: 'FIELDS_CHANGE', 18 | NODE_DELETE: 'NODE_DELETE', 19 | RANGE_ADD: 'RANGE_ADD', 20 | RANGE_DELETE: 'RANGE_DELETE', 21 | REQUIRED_CHILDREN: 'REQUIRED_CHILDREN', 22 | }; 23 | 24 | module.exports = RelayMutationType; 25 | -------------------------------------------------------------------------------- /examples/star-wars-angular/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Relay • Star Wars 7 | 8 | 9 |
10 |
11 | 12 |
13 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/connectionWithoutArgs.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL` 4 | query { 5 | node(id: 123) { 6 | ... on User { 7 | friends { 8 | edges { 9 | node { 10 | id, 11 | }, 12 | }, 13 | }, 14 | }, 15 | }, 16 | } 17 | `; 18 | 19 | Output: 20 | var Relay = require('react-relay'); 21 | var x = (function () { 22 | throw new Error('GraphQL validation/transform error ``You supplied the `edges` field on a connection named `friends`, but you did not supply an argument necessary to do so. Use either the `find`, `first`, or `last` argument.`` in file `connectionWithoutArgs.fixture`.'); 23 | })(); 24 | -------------------------------------------------------------------------------- /src/container/isRelayContainer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule isRelayContainer 10 | * @flow 11 | * @typechecks 12 | */ 13 | 14 | 'use strict'; 15 | 16 | function isRelayContainer(component: any): boolean { 17 | return !!( 18 | component && 19 | component.getFragmentNames && 20 | component.getFragment && 21 | component.hasFragment && 22 | component.hasVariable 23 | ); 24 | } 25 | 26 | module.exports = isRelayContainer; 27 | -------------------------------------------------------------------------------- /examples/todo/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Relay • TodoMVC 7 | 8 | 9 | 10 | 11 |
12 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/traversal/sortTypeFirst.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule sortTypeFirst 10 | * @typechecks 11 | * @flow 12 | */ 13 | 14 | 'use strict'; 15 | 16 | var TYPE = '__type__'; 17 | 18 | function sortTypeFirst(a: string, b: string): number { 19 | if (a === b) { 20 | return 0; 21 | } 22 | if (a === TYPE) { 23 | return -1; 24 | } 25 | if (b === TYPE) { 26 | return 1; 27 | } 28 | return 0; 29 | } 30 | 31 | module.exports = sortTypeFirst; 32 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/fragment.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL`fragment on Node { id }`; 4 | 5 | Output: 6 | var Relay = require('react-relay'); 7 | var x = (function () { 8 | return { 9 | children: [{ 10 | fieldName: 'id', 11 | kind: 'Field', 12 | metadata: { 13 | isRequisite: true 14 | }, 15 | type: 'String' 16 | }, { 17 | fieldName: '__typename', 18 | kind: 'Field', 19 | metadata: { 20 | isGenerated: true, 21 | isRequisite: true 22 | }, 23 | type: 'String' 24 | }], 25 | kind: 'Fragment', 26 | metadata: { 27 | isAbstract: true 28 | }, 29 | name: 'Fragment', 30 | type: 'Node' 31 | }; 32 | })(); 33 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/connectionWithAfterLastArgs.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL` 4 | query { 5 | node(id: 123) { 6 | ... on User { 7 | friends(last: 3, after: "foo") { 8 | edges { 9 | node { 10 | id, 11 | }, 12 | }, 13 | }, 14 | }, 15 | }, 16 | } 17 | `; 18 | 19 | Output: 20 | var Relay = require('react-relay'); 21 | var x = (function () { 22 | throw new Error('GraphQL validation/transform error ``Connection arguments `friends(after: , last: )` are not supported. Use `(last: )`, `(before: , last: )`, or `(after: , first: )`.`` in file `connectionWithAfterLastArgs.fixture`.'); 23 | })(); 24 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/metadataRequisite.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL`fragment on Node { id }`; 4 | 5 | Output: 6 | var Relay = require('react-relay'); 7 | var x = (function () { 8 | return { 9 | children: [{ 10 | fieldName: 'id', 11 | kind: 'Field', 12 | metadata: { 13 | isRequisite: true 14 | }, 15 | type: 'String' 16 | }, { 17 | fieldName: '__typename', 18 | kind: 'Field', 19 | metadata: { 20 | isGenerated: true, 21 | isRequisite: true 22 | }, 23 | type: 'String' 24 | }], 25 | kind: 'Fragment', 26 | metadata: { 27 | isAbstract: true 28 | }, 29 | name: 'MetadataRequisite', 30 | type: 'Node' 31 | }; 32 | })(); 33 | -------------------------------------------------------------------------------- /website/core/center.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule center 10 | */ 11 | 12 | var React = require('React'); 13 | 14 | var assign = require('object-assign') 15 | 16 | var center = React.createClass({ 17 | render: function() { 18 | var {style, ...props} = this.props; 19 | style = assign({}, style, {textAlign: 'center'}); 20 | 21 | return ( 22 |
{this.props.children}
23 | ); 24 | } 25 | }); 26 | 27 | module.exports = center; 28 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/connectionWithBeforeFirstArgs.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL` 4 | query { 5 | node(id: 123) { 6 | ... on User { 7 | friends(first: 3, before: "foo") { 8 | edges { 9 | node { 10 | id, 11 | }, 12 | }, 13 | }, 14 | }, 15 | }, 16 | } 17 | `; 18 | 19 | Output: 20 | var Relay = require('react-relay'); 21 | var x = (function () { 22 | throw new Error('GraphQL validation/transform error ``Connection arguments `friends(before: , first: )` are not supported. Use `(first: )`, `(after: , first: )`, or `(before: , last: )`.`` in file `connectionWithBeforeFirstArgs.fixture`.'); 23 | })(); 24 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/introspectionQueryForSchema.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var foo = Relay.QL` 3 | query IntrospectionQueryForSchema { 4 | __schema { 5 | types { 6 | name, 7 | }, 8 | }, 9 | } 10 | `; 11 | 12 | Output: 13 | var foo = (function () { 14 | return { 15 | children: [{ 16 | children: [{ 17 | fieldName: "name", 18 | kind: "Field", 19 | metadata: {}, 20 | type: "String" 21 | }], 22 | fieldName: "types", 23 | kind: "Field", 24 | metadata: { 25 | isPlural: true 26 | }, 27 | type: "__Type" 28 | }], 29 | fieldName: "__schema", 30 | kind: "Query", 31 | metadata: {}, 32 | name: "IntrospectionQueryForSchema", 33 | type: "__Schema" 34 | }; 35 | })(); 36 | -------------------------------------------------------------------------------- /src/legacy/store/generateForceIndex.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule generateForceIndex 10 | * @flow 11 | * @typechecks 12 | */ 13 | 14 | 'use strict'; 15 | 16 | var _index = 1; 17 | 18 | /** 19 | * Generate a new force index used to write GraphQL data in the store. A new 20 | * force index can be used to overwrite previous ranges. 21 | * 22 | * @internal 23 | */ 24 | function generateForceIndex(): number { 25 | return _index++; 26 | } 27 | 28 | module.exports = generateForceIndex; 29 | -------------------------------------------------------------------------------- /examples/todo/js/queries/ViewerQueries.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file provided by Facebook is for non-commercial testing and evaluation 3 | * purposes only. Facebook reserves all rights not expressly granted. 4 | * 5 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 6 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 7 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 8 | * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 9 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 10 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 11 | */ 12 | 13 | import Relay from 'react-relay'; 14 | 15 | export default { 16 | viewer: () => Relay.QL`query { viewer }`, 17 | }; 18 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/fragmentWithName.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL`fragment FragmentNameHere on Node { id }`; 4 | 5 | Output: 6 | var Relay = require('react-relay'); 7 | var x = (function () { 8 | return { 9 | children: [{ 10 | fieldName: 'id', 11 | kind: 'Field', 12 | metadata: { 13 | isRequisite: true 14 | }, 15 | type: 'String' 16 | }, { 17 | fieldName: '__typename', 18 | kind: 'Field', 19 | metadata: { 20 | isGenerated: true, 21 | isRequisite: true 22 | }, 23 | type: 'String' 24 | }], 25 | kind: 'Fragment', 26 | metadata: { 27 | isAbstract: true 28 | }, 29 | name: 'FragmentNameHere', 30 | type: 'Node' 31 | }; 32 | })(); 33 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/find.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @flow 10 | * @fullSyntaxTransform 11 | */ 12 | 13 | 'use strict'; 14 | 15 | function find( 16 | array: Array, 17 | predicate: (element: T, index: number, array: Array) => boolean, 18 | context: any 19 | ): ?T { 20 | for (var ii = 0; ii < array.length; ii++) { 21 | if (predicate.call(context, array[ii], ii, array)) { 22 | return array[ii]; 23 | } 24 | } 25 | return undefined; 26 | } 27 | 28 | module.exports = find; 29 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/introspectionQueryForType.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var foo = Relay.QL` 3 | query IntrospectionQueryForType { 4 | __type(name: "Root") { 5 | name, 6 | }, 7 | } 8 | `; 9 | 10 | Output: 11 | var foo = (function () { 12 | return { 13 | calls: [{ 14 | kind: "Call", 15 | metadata: {}, 16 | name: "name", 17 | value: { 18 | kind: "CallValue", 19 | callValue: "Root" 20 | } 21 | }], 22 | children: [{ 23 | fieldName: "name", 24 | kind: "Field", 25 | metadata: {}, 26 | type: "String" 27 | }], 28 | fieldName: "__type", 29 | kind: "Query", 30 | metadata: { 31 | identifyingArgName: "name" 32 | }, 33 | name: "IntrospectionQueryForType", 34 | type: "__Type" 35 | }; 36 | })(); 37 | -------------------------------------------------------------------------------- /src/.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | .*/__tests__/.* 3 | .*/node_modules/graphql/.* 4 | .*/react/node_modules/.* 5 | .*/react-static-container/node_modules/.* 6 | 7 | [include] 8 | ../node_modules/fbjs/flow/include 9 | ../node_modules/fbjs/node_modules/promise 10 | 11 | [libs] 12 | ../node_modules/fbjs/flow/lib 13 | 14 | [options] 15 | module.system=haste 16 | munge_underscores=true 17 | 18 | suppress_type=$FlowIssue 19 | suppress_type=$FlowFixMe 20 | suppress_type=$FixMe 21 | 22 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(2[0-0]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*\\)?)\\) 23 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(2[0-0]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*\\)?)\\)? #[0-9]+ 24 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 25 | 26 | [version] 27 | 0.20.1 28 | -------------------------------------------------------------------------------- /src/legacy/store/generateClientEdgeID.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule generateClientEdgeID 10 | * @flow 11 | * @typechecks 12 | */ 13 | 14 | 'use strict'; 15 | 16 | /** 17 | * Generate an edge client id for edges on connections based on the range it 18 | * belongs to and the node it contains. 19 | * 20 | * @internal 21 | */ 22 | function generateClientEdgeID(rangeID: string, nodeID: string): string { 23 | return 'client:' + rangeID + ':' + nodeID; 24 | } 25 | 26 | module.exports = generateClientEdgeID; 27 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/fragmentDirectives.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL`fragment on Node @relay(plural: true) { id }`; 4 | 5 | Output: 6 | var Relay = require('react-relay'); 7 | var x = (function () { 8 | return { 9 | children: [{ 10 | fieldName: 'id', 11 | kind: 'Field', 12 | metadata: { 13 | isRequisite: true 14 | }, 15 | type: 'String' 16 | }, { 17 | fieldName: '__typename', 18 | kind: 'Field', 19 | metadata: { 20 | isGenerated: true, 21 | isRequisite: true 22 | }, 23 | type: 'String' 24 | }], 25 | kind: 'Fragment', 26 | metadata: { 27 | plural: true, 28 | isAbstract: true 29 | }, 30 | name: 'FragmentDirectives', 31 | type: 'Node' 32 | }; 33 | })(); 34 | -------------------------------------------------------------------------------- /examples/star-wars/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "start": "babel-node ./server.js", 5 | "update-schema": "babel-node ./scripts/updateSchema.js", 6 | "preinstall": "cd ../.. && npm install --ignore-scripts && cd scripts/babel-relay-plugin && npm install --ignore-scripts" 7 | }, 8 | "dependencies": { 9 | "babel": "5.8.23", 10 | "babel-core": "^5.8.25", 11 | "babel-loader": "5.3.2", 12 | "babel-relay-plugin": "file:../../scripts/babel-relay-plugin/", 13 | "classnames": "^2.1.3", 14 | "express": "^4.13.1", 15 | "express-graphql": "^0.4.0", 16 | "graphql": "0.4.13", 17 | "graphql-relay": "^0.3.3", 18 | "react": "^0.14.0", 19 | "react-dom": "^0.14.0", 20 | "react-relay": "file:../../", 21 | "webpack": "^1.10.5", 22 | "webpack-dev-server": "^1.10.1" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/connectionWithoutArgsWithInlineFragment.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL` 4 | query { 5 | node(id: 123) { 6 | ... on User { 7 | friends { 8 | ... on UserConnection { 9 | edges { 10 | node { 11 | id, 12 | }, 13 | }, 14 | }, 15 | }, 16 | }, 17 | }, 18 | } 19 | `; 20 | 21 | Output: 22 | var Relay = require('react-relay'); 23 | var x = (function () { 24 | throw new Error('GraphQL validation/transform error ``You supplied the `edges` field on a connection named `friends`, but you did not supply an argument necessary to do so. Use either the `find`, `first`, or `last` argument.`` in file `connectionWithoutArgsWithInlineFragment.fixture`.'); 25 | })(); 26 | -------------------------------------------------------------------------------- /examples/todo/build/babelRelayPlugin.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file provided by Facebook is for non-commercial testing and evaluation 3 | * purposes only. Facebook reserves all rights not expressly granted. 4 | * 5 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 6 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 7 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 8 | * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 9 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 10 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 11 | */ 12 | 13 | var getBabelRelayPlugin = require('babel-relay-plugin'); 14 | var schema = require('../data/schema.json'); 15 | 16 | module.exports = getBabelRelayPlugin(schema.data); 17 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/lib/invariant.js: -------------------------------------------------------------------------------- 1 | // @generated 2 | /** 3 | * Copyright 2013-2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | * 10 | * 11 | * @fullSyntaxTransform 12 | */ 13 | 14 | 'use strict'; 15 | 16 | var util = require('util'); 17 | 18 | function invariant(condition, format) { 19 | if (!condition) { 20 | for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { 21 | args[_key - 2] = arguments[_key]; 22 | } 23 | 24 | throw new Error(util.format.apply(util, [format].concat(args))); 25 | } 26 | } 27 | 28 | module.exports = invariant; -------------------------------------------------------------------------------- /src/container/isReactComponent.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule isReactComponent 10 | * @typechecks 11 | * @flow 12 | */ 13 | 14 | 'use strict'; 15 | 16 | /** 17 | * @internal 18 | * 19 | * Helper for checking if this is a React Component 20 | * created with React.Component or React.createClass(). 21 | */ 22 | function isReactComponent(component: mixed): boolean { 23 | return !!( 24 | component && 25 | component.prototype && 26 | component.prototype.isReactComponent 27 | ); 28 | } 29 | 30 | module.exports = isReactComponent; 31 | -------------------------------------------------------------------------------- /examples/relay-treasurehunt/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "start": "babel-node ./server.js", 5 | "update-schema": "babel-node ./scripts/updateSchema.js", 6 | "preinstall": "cd ../.. && npm install --ignore-scripts && cd scripts/babel-relay-plugin && npm install --ignore-scripts" 7 | }, 8 | "dependencies": { 9 | "babel": "5.8.23", 10 | "babel-core": "^5.8.25", 11 | "babel-loader": "5.3.2", 12 | "babel-relay-plugin": "file:../../scripts/babel-relay-plugin/", 13 | "classnames": "^2.1.3", 14 | "express": "^4.13.1", 15 | "express-graphql": "^0.4.0", 16 | "graphql": "0.4.13", 17 | "graphql-relay": "^0.3.3", 18 | "react": "^0.14.0", 19 | "react-dom": "^0.14.0", 20 | "react-relay": "file:../../", 21 | "webpack": "^1.10.5", 22 | "webpack-dev-server": "^1.10.1" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /examples/star-wars/build/babelRelayPlugin.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file provided by Facebook is for non-commercial testing and evaluation 3 | * purposes only. Facebook reserves all rights not expressly granted. 4 | * 5 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 6 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 7 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 8 | * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 9 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 10 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 11 | */ 12 | 13 | var getBabelRelayPlugin = require('babel-relay-plugin'); 14 | var schema = require('../data/schema.json'); 15 | 16 | module.exports = getBabelRelayPlugin(schema.data); 17 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/metadataNonFindable.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL` 4 | query { 5 | viewer { 6 | pendingPosts { 7 | count, 8 | }, 9 | }, 10 | } 11 | `; 12 | 13 | Output: 14 | var Relay = require('react-relay'); 15 | var x = (function () { 16 | return { 17 | children: [{ 18 | children: [{ 19 | fieldName: 'count', 20 | kind: 'Field', 21 | metadata: {}, 22 | type: 'Int' 23 | }], 24 | fieldName: 'pendingPosts', 25 | kind: 'Field', 26 | metadata: { 27 | isConnection: true 28 | }, 29 | type: 'PendingPostsConnection' 30 | }], 31 | fieldName: 'viewer', 32 | kind: 'Query', 33 | metadata: {}, 34 | name: 'MetadataNonFindable', 35 | type: 'Viewer' 36 | }; 37 | })(); 38 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/unionWithTypename.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var foo = Relay.QL` 3 | query UnionWithTypename { 4 | media(id: 123) { 5 | __typename, 6 | }, 7 | } 8 | `; 9 | 10 | Output: 11 | var foo = (function () { 12 | return { 13 | calls: [{ 14 | kind: "Call", 15 | metadata: {}, 16 | name: "id", 17 | value: { 18 | kind: "CallValue", 19 | callValue: 123 20 | } 21 | }], 22 | children: [{ 23 | fieldName: "__typename", 24 | kind: "Field", 25 | metadata: { 26 | isRequisite: true 27 | }, 28 | type: "String" 29 | }], 30 | fieldName: "media", 31 | kind: "Query", 32 | metadata: { 33 | isAbstract: true, 34 | identifyingArgName: "id" 35 | }, 36 | name: "UnionWithTypename", 37 | type: "Media" 38 | }; 39 | })(); 40 | -------------------------------------------------------------------------------- /src/route/__mocks__/RelayRoute.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @typechecks 10 | */ 11 | 12 | 'use strict'; 13 | 14 | var RelayRoute = require.requireActual('RelayRoute'); 15 | 16 | RelayRoute.genMock = jest.genMockFunction().mockImplementation(() => { 17 | class MockRoute extends RelayRoute {} 18 | MockRoute.routeName = 'MockRoute'; 19 | MockRoute.path = '/jest'; 20 | return MockRoute; 21 | }); 22 | 23 | RelayRoute.genMockInstance = jest.genMockFunction().mockImplementation( 24 | () => new (RelayRoute.genMock())() 25 | ); 26 | 27 | module.exports = RelayRoute; 28 | -------------------------------------------------------------------------------- /examples/relay-treasurehunt/build/babelRelayPlugin.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file provided by Facebook is for non-commercial testing and evaluation 3 | * purposes only. Facebook reserves all rights not expressly granted. 4 | * 5 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 6 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 7 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 8 | * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 9 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 10 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 11 | */ 12 | 13 | var getBabelRelayPlugin = require('babel-relay-plugin'); 14 | var schema = require('../data/schema.json'); 15 | 16 | module.exports = getBabelRelayPlugin(schema.data); 17 | -------------------------------------------------------------------------------- /examples/star-wars-angular/build/babelRelayPlugin.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file provided by Facebook is for non-commercial testing and evaluation 3 | * purposes only. Facebook reserves all rights not expressly granted. 4 | * 5 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 6 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 7 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 8 | * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 9 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 10 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 11 | */ 12 | 13 | var getBabelRelayPlugin = require('babel-relay-plugin'); 14 | var schema = require('../data/schema.json'); 15 | 16 | module.exports = getBabelRelayPlugin(schema.data); 17 | -------------------------------------------------------------------------------- /src/legacy/store/__mocks__/GraphQLStoreRangeUtils.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | */ 10 | 11 | 'use strict'; 12 | 13 | const GraphQLStoreRangeUtils = require.requireActual('GraphQLStoreRangeUtils'); 14 | 15 | Object.keys(GraphQLStoreRangeUtils.prototype).forEach(name => { 16 | const property = GraphQLStoreRangeUtils.prototype[name]; 17 | if (typeof property === 'function') { 18 | GraphQLStoreRangeUtils.prototype[name] = 19 | jest.genMockFunction().mockImplementation(property); 20 | } 21 | }); 22 | 23 | module.exports = require.requireActual('GraphQLStoreRangeUtils'); 24 | -------------------------------------------------------------------------------- /website/core/unindent.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule unindent 10 | */ 11 | 12 | // Remove the indentation introduced by JSX 13 | function unindent(code) { 14 | var lines = code.split('\n'); 15 | if (lines[0] === '') { 16 | lines.shift(); 17 | } 18 | if (lines.length <= 1) { 19 | return code; 20 | } 21 | 22 | var indent = lines[0].match(/^\s*/)[0]; 23 | for (var i = 0; i < lines.length; ++i) { 24 | lines[i] = lines[i].replace(new RegExp('^' + indent), ''); 25 | } 26 | return lines.join('\n'); 27 | } 28 | 29 | module.exports = unindent; 30 | -------------------------------------------------------------------------------- /website/src/relay/img/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/fragmentWithReference.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL`fragment on Node { ${reference} }`; 4 | 5 | Output: 6 | var Relay = require('react-relay'); 7 | var x = (function (RQL_0) { 8 | return { 9 | children: [{ 10 | fieldName: 'id', 11 | kind: 'Field', 12 | metadata: { 13 | isGenerated: true, 14 | isRequisite: true 15 | }, 16 | type: 'String' 17 | }, { 18 | fieldName: '__typename', 19 | kind: 'Field', 20 | metadata: { 21 | isGenerated: true, 22 | isRequisite: true 23 | }, 24 | type: 'String' 25 | }, Relay.QL.__frag(RQL_0)], 26 | kind: 'Fragment', 27 | metadata: { 28 | isAbstract: true 29 | }, 30 | name: 'FragmentWithReference', 31 | type: 'Node' 32 | }; 33 | })(reference); 34 | -------------------------------------------------------------------------------- /website-prototyping-tools/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/fragmentWithoutCommas.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL` 4 | fragment on Node { 5 | ${reference} 6 | id 7 | } 8 | `; 9 | 10 | Output: 11 | var Relay = require('react-relay'); 12 | var x = (function (RQL_0) { 13 | return { 14 | children: [{ 15 | fieldName: 'id', 16 | kind: 'Field', 17 | metadata: { 18 | isRequisite: true 19 | }, 20 | type: 'String' 21 | }, { 22 | fieldName: '__typename', 23 | kind: 'Field', 24 | metadata: { 25 | isGenerated: true, 26 | isRequisite: true 27 | }, 28 | type: 'String' 29 | }, Relay.QL.__frag(RQL_0)], 30 | kind: 'Fragment', 31 | metadata: { 32 | isAbstract: true 33 | }, 34 | name: 'FragmentWithoutCommas', 35 | type: 'Node' 36 | }; 37 | })(reference); 38 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/connectionWithAfterLastArgsWithInlineFragment.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL` 4 | query { 5 | node(id: 123) { 6 | ... on User { 7 | friends(last: 3, after: "foo") { 8 | ... on UserConnection { 9 | edges { 10 | node { 11 | id, 12 | }, 13 | }, 14 | }, 15 | }, 16 | }, 17 | }, 18 | } 19 | `; 20 | 21 | Output: 22 | var Relay = require('react-relay'); 23 | var x = (function () { 24 | throw new Error('GraphQL validation/transform error ``Connection arguments `friends(after: , last: )` are not supported. Use `(last: )`, `(before: , last: )`, or `(after: , first: )`.`` in file `connectionWithAfterLastArgsWithInlineFragment.fixture`.'); 25 | })(); 26 | -------------------------------------------------------------------------------- /src/query-config/__mocks__/RelayQueryConfig.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @typechecks 10 | */ 11 | 12 | 'use strict'; 13 | 14 | var RelayQueryConfig = require.requireActual('RelayQueryConfig'); 15 | 16 | RelayQueryConfig.genMock = jest.genMockFunction().mockImplementation(() => { 17 | class MockQueryConfig extends RelayQueryConfig {} 18 | MockQueryConfig.routeName = 'MockQueryConfig'; 19 | return MockQueryConfig; 20 | }); 21 | 22 | RelayQueryConfig.genMockInstance = jest.genMockFunction().mockImplementation( 23 | () => new (RelayQueryConfig.genMock())() 24 | ); 25 | 26 | module.exports = RelayQueryConfig; 27 | -------------------------------------------------------------------------------- /examples/relay-treasurehunt/js/routes/AppHomeRoute.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file provided by Facebook is for non-commercial testing and evaluation 3 | * purposes only. Facebook reserves all rights not expressly granted. 4 | * 5 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 6 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 7 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 8 | * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 9 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 10 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 11 | */ 12 | 13 | import Relay from 'react-relay'; 14 | 15 | export default class extends Relay.Route { 16 | static queries = { 17 | game: () => Relay.QL`query { game }`, 18 | }; 19 | static routeName = 'AppHomeRoute'; 20 | } 21 | -------------------------------------------------------------------------------- /src/legacy/store/generateClientID.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule generateClientID 10 | * @typechecks 11 | */ 12 | 13 | 'use strict'; 14 | 15 | const crc32 = require('crc32'); 16 | const performanceNow = require('performanceNow'); 17 | 18 | var _clientID = 1; 19 | var _prefix = 'client:' + crc32('' + performanceNow()); 20 | 21 | /** 22 | * Generate a unique clientID for GraphQL data objects that do not already have 23 | * an ID or their ID = null 24 | * 25 | * @internal 26 | */ 27 | function generateClientID() { 28 | return _prefix + _clientID++; 29 | } 30 | 31 | module.exports = generateClientID; 32 | -------------------------------------------------------------------------------- /src/legacy/store/__mocks__/GraphQLStoreChangeEmitter.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | var GraphQLStoreChangeEmitter = jest.genMockFromModule('GraphQLStoreChangeEmitter'); 13 | 14 | GraphQLStoreChangeEmitter.mockImplementation(function() { 15 | this.addListenerForIDs.mock.remove = []; 16 | this.addListenerForIDs.mockImplementation(() => { 17 | var returnValue = {remove: jest.genMockFunction()}; 18 | this.addListenerForIDs.mock.remove.push( 19 | returnValue.remove 20 | ); 21 | return returnValue; 22 | }); 23 | 24 | return this; 25 | }); 26 | 27 | module.exports = GraphQLStoreChangeEmitter; 28 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/mutationWithoutArgs.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL` 4 | mutation { 5 | actorSubscribe, 6 | } 7 | `; 8 | 9 | Output: 10 | var Relay = require('react-relay'); 11 | var x = (function () { 12 | return { 13 | calls: [{ 14 | kind: 'Call', 15 | metadata: {}, 16 | name: 'actorSubscribe', 17 | value: { 18 | kind: 'CallVariable', 19 | callVariableName: 'input' 20 | } 21 | }], 22 | children: [{ 23 | fieldName: 'clientMutationId', 24 | kind: 'Field', 25 | metadata: { 26 | isGenerated: true, 27 | isRequisite: true 28 | }, 29 | type: 'String' 30 | }], 31 | kind: 'Mutation', 32 | metadata: { 33 | inputType: 'ActorSubscribeInput' 34 | }, 35 | name: 'MutationWithoutArgs', 36 | responseType: 'ActorSubscribeResponsePayload' 37 | }; 38 | })(); 39 | -------------------------------------------------------------------------------- /src/__forks__/Relay.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule Relay 10 | * @typechecks 11 | * @flow 12 | */ 13 | 14 | 'use strict'; 15 | 16 | var RelayDefaultNetworkLayer = require('RelayDefaultNetworkLayer'); 17 | var RelayPublic = require('RelayPublic'); 18 | 19 | // By default, assume that GraphQL is served at `/graphql` on the same domain. 20 | // $FlowFixMe(>=0.16.0) 21 | RelayPublic.injectNetworkLayer(new RelayDefaultNetworkLayer('/graphql')); 22 | 23 | module.exports = { 24 | ...RelayPublic, 25 | // Expose the default network layer to allow convenient re-configuration. 26 | DefaultNetworkLayer: RelayDefaultNetworkLayer, 27 | }; 28 | -------------------------------------------------------------------------------- /website/server/buildGraphQLSpec.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | var exec = require('child_process').execFileSync; 11 | var fs = require('fs-extra'); 12 | var glob = require('glob'); 13 | 14 | module.exports = function(targetDir) { 15 | fs.copySync('node_modules/spec-md/css', targetDir + '/relay/graphql'); 16 | glob.sync('graphql/*.md').forEach(function(file) { 17 | var html = exec('./node_modules/.bin/spec-md', [file]); 18 | var outFilename = ( 19 | targetDir + '/relay/graphql/' + 20 | path.basename(file, '.md').toLowerCase() + 21 | '.htm' 22 | ); 23 | fs.writeFileSync(outFilename, html.toString()); 24 | }); 25 | } 26 | -------------------------------------------------------------------------------- /examples/star-wars/js/routes/StarWarsAppHomeRoute.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file provided by Facebook is for non-commercial testing and evaluation 3 | * purposes only. Facebook reserves all rights not expressly granted. 4 | * 5 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 6 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 7 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 8 | * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 9 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 10 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 11 | */ 12 | 13 | import Relay from 'react-relay'; 14 | 15 | export default class extends Relay.Route { 16 | static queries = { 17 | factions: () => Relay.QL`query { factions(names: $factionNames) }`, 18 | }; 19 | static routeName = 'StarWarsAppHomeRoute'; 20 | } 21 | -------------------------------------------------------------------------------- /examples/star-wars-angular/js/routes/StarWarsAppHomeRoute.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file provided by Facebook is for non-commercial testing and evaluation 3 | * purposes only. Facebook reserves all rights not expressly granted. 4 | * 5 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 6 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 7 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 8 | * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 9 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 10 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 11 | */ 12 | 13 | import Relay from 'generic-relay'; 14 | 15 | export default class extends Relay.Route { 16 | static queries = { 17 | factions: () => Relay.QL`query { factions(names: $factionNames) }`, 18 | }; 19 | static routeName = 'StarWarsAppHomeRoute'; 20 | } 21 | -------------------------------------------------------------------------------- /examples/star-wars-angular/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "start": "babel-node ./server.js", 5 | "update-schema": "babel-node ./scripts/updateSchema.js", 6 | "preinstall": "cd ../.. && npm install --ignore-scripts && cd scripts/babel-relay-plugin && npm install --ignore-scripts" 7 | }, 8 | "dependencies": { 9 | "angular": "^1.4.8", 10 | "babel": "5.8.23", 11 | "babel-core": "^5.8.25", 12 | "babel-eslint": "^4.1.6", 13 | "babel-loader": "5.3.2", 14 | "babel-relay-plugin": "file:../../scripts/babel-relay-plugin/", 15 | "classnames": "^2.1.3", 16 | "eslint-plugin-react": "^3.15.0", 17 | "express": "^4.13.1", 18 | "express-graphql": "^0.4.0", 19 | "generic-relay": "file:../../", 20 | "graphql": "0.4.13", 21 | "graphql-relay": "^0.3.3", 22 | "react": "^0.14.0", 23 | "react-dom": "^0.14.0", 24 | "webpack": "^1.10.5", 25 | "webpack-dev-server": "^1.10.1" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/argsSubstitution.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var foo = Relay.QL` 3 | query Args { 4 | node(id: ${userID}) { 5 | id, 6 | }, 7 | } 8 | `; 9 | 10 | Output: 11 | var foo = (function (RQL_0) { 12 | return { 13 | calls: [{ 14 | kind: "Call", 15 | metadata: {}, 16 | name: "id", 17 | value: Relay.QL.__var(RQL_0) 18 | }], 19 | children: [{ 20 | fieldName: "id", 21 | kind: "Field", 22 | metadata: { 23 | isRequisite: true 24 | }, 25 | type: "String" 26 | }, { 27 | fieldName: "__typename", 28 | kind: "Field", 29 | metadata: { 30 | isGenerated: true, 31 | isRequisite: true 32 | }, 33 | type: "String" 34 | }], 35 | fieldName: "node", 36 | kind: "Query", 37 | metadata: { 38 | isAbstract: true, 39 | identifyingArgName: "id" 40 | }, 41 | name: "Args", 42 | type: "Node" 43 | }; 44 | })(userID); 45 | -------------------------------------------------------------------------------- /website-prototyping-tools/babelRelayPlaygroundPlugin.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | export default function({Plugin, types: t}) { 11 | return new Plugin('babel-relay-playground', { 12 | visitor: { 13 | CallExpression(node) { 14 | var callee = this.get('callee'); 15 | if ( 16 | callee.matchesPattern('React.render') || 17 | callee.matchesPattern('ReactDOM.render') 18 | ) { 19 | // We found a ReactDOM.render(...) type call. 20 | // Pluck the ReactElement from the call, and export it instead. 21 | return t.exportDefaultDeclaration(node.arguments[0]); 22 | } 23 | }, 24 | }, 25 | }); 26 | } 27 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/queryWithObjectArg.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('Relay'); 3 | var q = Relay.QL` 4 | query { 5 | search(query: $query) { 6 | title, 7 | }, 8 | } 9 | `; 10 | 11 | Output: 12 | var Relay = require('Relay'); 13 | var q = (function () { 14 | return { 15 | calls: [{ 16 | kind: 'Call', 17 | metadata: { 18 | type: '[SearchInput!]' 19 | }, 20 | name: 'query', 21 | value: { 22 | kind: 'CallVariable', 23 | callVariableName: 'query' 24 | } 25 | }], 26 | children: [{ 27 | fieldName: 'title', 28 | kind: 'Field', 29 | metadata: {}, 30 | type: 'String' 31 | }], 32 | fieldName: 'search', 33 | kind: 'Query', 34 | metadata: { 35 | isPlural: true, 36 | identifyingArgName: 'query', 37 | identifyingArgType: '[SearchInput!]' 38 | }, 39 | name: 'QueryWithObjectArg', 40 | type: 'SearchResult' 41 | }; 42 | })(); 43 | -------------------------------------------------------------------------------- /src/traversal/__tests__/sortTypeFirst-test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @emails oncall+relay 10 | */ 11 | 12 | 'use strict'; 13 | 14 | const sortTypeFirst = require('sortTypeFirst'); 15 | 16 | describe('sortTypeFirst', () => { 17 | it('considers `__type__` to be the smallest', () => { 18 | expect(sortTypeFirst('__type__', '_')).toBe(-1); 19 | expect(sortTypeFirst('_', '__type__')).toBe(1); 20 | expect(sortTypeFirst('__type__', '__type__')).toBe(0); 21 | }); 22 | 23 | it('does not compare non-`__type__` strings', () => { 24 | expect(sortTypeFirst('a', 'b')).toBe(0); 25 | expect(sortTypeFirst('b', 'a')).toBe(0); 26 | expect(sortTypeFirst('a', 'a')).toBe(0); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /website/layout/PageLayout.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule PageLayout 10 | */ 11 | 12 | var React = require('React'); 13 | var Site = require('Site'); 14 | var Marked = require('Marked'); 15 | 16 | var support = React.createClass({ 17 | render: function() { 18 | var metadata = this.props.metadata; 19 | var content = this.props.children; 20 | return ( 21 | 22 |
23 |
24 | {content} 25 |
26 |
27 |
28 | ); 29 | } 30 | }); 31 | 32 | module.exports = support; 33 | -------------------------------------------------------------------------------- /examples/todo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "start": "babel-node ./server.js", 5 | "update-schema": "babel-node ./scripts/updateSchema.js", 6 | "preinstall": "cd ../.. && npm install --ignore-scripts && cd scripts/babel-relay-plugin && npm install --ignore-scripts" 7 | }, 8 | "dependencies": { 9 | "babel": "5.8.23", 10 | "babel-core": "^5.8.25", 11 | "babel-loader": "5.3.2", 12 | "babel-relay-plugin": "file:../../scripts/babel-relay-plugin/", 13 | "classnames": "^2.1.5", 14 | "express": "^4.13.3", 15 | "express-graphql": "^0.4.0", 16 | "graphql": "0.4.13", 17 | "graphql-relay": "^0.3.3", 18 | "history": "1.13.0", 19 | "react": "^0.14.0", 20 | "react-dom": "^0.14.0", 21 | "react-relay": "file:../../", 22 | "react-router": "^1.0.0", 23 | "react-router-relay": "^0.8.0", 24 | "todomvc-app-css": "^2.0.3", 25 | "todomvc-common": "^1.0.2", 26 | "webpack": "^1.12.2", 27 | "webpack-dev-server": "^1.12.0" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/subscription.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL` 4 | subscription { 5 | likeStory(input: $input) { 6 | ${reference}, 7 | }, 8 | } 9 | `; 10 | 11 | Output: 12 | var Relay = require('react-relay'); 13 | var x = (function (RQL_0) { 14 | return { 15 | calls: [{ 16 | kind: 'Call', 17 | metadata: {}, 18 | name: 'likeStory', 19 | value: { 20 | kind: 'CallVariable', 21 | callVariableName: 'input' 22 | } 23 | }], 24 | children: [{ 25 | fieldName: 'clientSubscriptionId', 26 | kind: 'Field', 27 | metadata: { 28 | isGenerated: true, 29 | isRequisite: true 30 | }, 31 | type: 'String' 32 | }, Relay.QL.__frag(RQL_0)], 33 | kind: 'Subscription', 34 | metadata: { 35 | inputType: 'LikeStorySubscriptionInput' 36 | }, 37 | name: 'Subscription', 38 | responseType: 'LikeStorySubscriptionPayload' 39 | }; 40 | })(reference); 41 | -------------------------------------------------------------------------------- /website-prototyping-tools/evalSchema.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | /* eslint-disable no-unused-vars, no-eval */ 11 | 12 | import babel from 'babel-core/browser'; 13 | 14 | var GraphQL = require('graphql'); 15 | var GraphQLRelay = require('graphql-relay'); 16 | 17 | export default function(source) { 18 | // Make these modules available to the schema author through a require shim. 19 | function require(path) { 20 | switch (path) { 21 | case 'graphql': return GraphQL; 22 | case 'graphql-relay': return GraphQLRelay; 23 | 24 | default: throw new Error(`Cannot find module "${path}"`); 25 | } 26 | } 27 | var {code} = babel.transform(source, {code: true, ast: false}); 28 | return eval(code); 29 | } 30 | -------------------------------------------------------------------------------- /src/route/RelayMetaRoute.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule RelayMetaRoute 10 | * @flow 11 | * @typechecks 12 | */ 13 | 14 | 'use strict'; 15 | 16 | /** 17 | * Meta route based on the real route; provides access to the route name in 18 | * queries. 19 | */ 20 | class RelayMetaRoute { 21 | name: string; 22 | 23 | constructor(name: string) { 24 | Object.defineProperty(this, 'name', { 25 | enumerable: true, 26 | value: name, 27 | writable: false, 28 | }); 29 | } 30 | 31 | static get(name: string) { 32 | return cache[name] || (cache[name] = new RelayMetaRoute(name)); 33 | } 34 | 35 | } 36 | 37 | var cache: {[key: string]: RelayMetaRoute} = {}; 38 | 39 | module.exports = RelayMetaRoute; 40 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/mutationWithName.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL` 4 | mutation MutationNameHere { 5 | actorSubscribe(input: $input) { 6 | ${reference}, 7 | }, 8 | } 9 | `; 10 | 11 | Output: 12 | var Relay = require('react-relay'); 13 | var x = (function (RQL_0) { 14 | return { 15 | calls: [{ 16 | kind: 'Call', 17 | metadata: {}, 18 | name: 'actorSubscribe', 19 | value: { 20 | kind: 'CallVariable', 21 | callVariableName: 'input' 22 | } 23 | }], 24 | children: [{ 25 | fieldName: 'clientMutationId', 26 | kind: 'Field', 27 | metadata: { 28 | isGenerated: true, 29 | isRequisite: true 30 | }, 31 | type: 'String' 32 | }, Relay.QL.__frag(RQL_0)], 33 | kind: 'Mutation', 34 | metadata: { 35 | inputType: 'ActorSubscribeInput' 36 | }, 37 | name: 'MutationNameHere', 38 | responseType: 'ActorSubscribeResponsePayload' 39 | }; 40 | })(reference); 41 | -------------------------------------------------------------------------------- /docs/GraphQL-FurtherReading.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: graphql-further-reading 3 | title: Further Reading 4 | layout: docs 5 | category: GraphQL 6 | permalink: docs/graphql-further-reading.html 7 | indent: true 8 | next: api-reference-relay 9 | --- 10 | 11 | This concludes the overview of the GraphQL Relay Specifications. For the 12 | detailed requirements of a Relay-compliant GraphQL server, a more formal 13 | description of the [Relay cursor connection](../graphql/connections.htm) model, 14 | the [Relay global object identification](../graphql/objectidentification.htm) 15 | model, and the [Relay input object mutation](../graphql/mutations.htm) are all 16 | available. 17 | 18 | To see code implementing the specification, the 19 | [GraphQL.js Relay library](https://github.com/graphql/graphql-relay-js) provides 20 | helper functions for creating nodes, connections, and mutations; that 21 | repository's [`__tests__`](https://github.com/graphql/graphql-relay-js/tree/master/src/__tests__) 22 | folder contains an implementation of the above example as integration tests for 23 | the repository. 24 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/scripts/build-lib: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var babel = require('babel'); 4 | var fs = require('fs'); 5 | var glob = require('glob'); 6 | var mkdirp = require('mkdirp'); 7 | var path = require('path'); 8 | var rimraf = require('rimraf'); 9 | 10 | var root = path.resolve(__dirname, '..'); 11 | var lib = path.join(root, 'lib'); 12 | var src = path.join(root, 'src'); 13 | 14 | // Blow away prior build artifacts. 15 | rimraf.sync(lib); 16 | 17 | // Get the files to transform 18 | var files = glob.sync('**/*.js', { 19 | cwd: src, 20 | ignore: '**/__tests__/*'} 21 | ); 22 | files.forEach((file) => { 23 | // Make sure file is fully resolved 24 | var srcFile = path.resolve(src, file); 25 | var libFile = path.resolve(lib, file); 26 | 27 | // Make sure the full path the destination file exists so we can write to it 28 | mkdirp.sync(path.dirname(libFile)); 29 | var code = babel.transformFileSync(srcFile).code; 30 | 31 | // Prepend @generated annotation 32 | code = '// @generated\n' + code; 33 | fs.writeFile(libFile, code, 'utf8'); 34 | }); 35 | -------------------------------------------------------------------------------- /examples/relay-treasurehunt/js/app.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file provided by Facebook is for non-commercial testing and evaluation 3 | * purposes only. Facebook reserves all rights not expressly granted. 4 | * 5 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 6 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 7 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 8 | * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 9 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 10 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 11 | */ 12 | 13 | import 'babel/polyfill'; 14 | import App from './components/App'; 15 | import AppHomeRoute from './routes/AppHomeRoute'; 16 | import React from 'react'; 17 | import ReactDOM from 'react-dom'; 18 | import Relay from 'react-relay'; 19 | 20 | ReactDOM.render( 21 | , 25 | document.getElementById('root') 26 | ); 27 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/lib/GraphQLRelayDirective.js: -------------------------------------------------------------------------------- 1 | // @generated 2 | /** 3 | * Copyright 2013-2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | * 10 | * 11 | * @fullSyntaxTransform 12 | */ 13 | 14 | 'use strict'; 15 | 16 | var types = require('./GraphQL').type; 17 | 18 | module.exports = { 19 | name: 'relay', 20 | description: 'The @relay directive on fragments.', 21 | args: [{ 22 | name: 'pattern', 23 | description: 'Marks a fragment as intended for pattern matching (as ' + 'opposed to fetching).', 24 | type: types.GraphQLBoolean, 25 | defaultValue: null 26 | }, { 27 | name: 'plural', 28 | description: 'Marks a fragment as being backed by a GraphQLList', 29 | type: types.GraphQLBoolean, 30 | defaultValue: null 31 | }], 32 | onOperation: false, 33 | onFragment: true, 34 | onField: false 35 | }; -------------------------------------------------------------------------------- /src/query/createRelayQuery.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule createRelayQuery 10 | * @typechecks 11 | * @flow 12 | */ 13 | 14 | 'use strict'; 15 | 16 | const RelayMetaRoute = require('RelayMetaRoute'); 17 | const RelayQuery = require('RelayQuery'); 18 | 19 | const invariant = require('invariant'); 20 | 21 | function createRelayQuery( 22 | node: Object, 23 | variables: {[key: string]: mixed} 24 | ): RelayQuery.Root { 25 | invariant( 26 | typeof variables === 'object' && 27 | variables != null && 28 | !Array.isArray(variables), 29 | 'Relay.Query: Expected `variables` to be an object.' 30 | ); 31 | return RelayQuery.Root.create( 32 | node, 33 | RelayMetaRoute.get('$createRelayQuery'), 34 | variables 35 | ); 36 | } 37 | 38 | module.exports = createRelayQuery; 39 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/argsInvalidValues.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var foo = Relay.QL` 3 | query Args { 4 | node(id: 123) { 5 | ... on User { 6 | friends( 7 | first: "10", 8 | orderby: Name, 9 | find: cursor1, 10 | isViewerFriend: "true", 11 | gender: "MALE", 12 | ) { 13 | edges { 14 | node { 15 | id, 16 | }, 17 | }, 18 | }, 19 | }, 20 | }, 21 | } 22 | `; 23 | 24 | Output: 25 | var foo = (function () { 26 | throw new Error("GraphQL validation/transform error ``Argument \"first\" has invalid value \"10\".\nExpected type \"Int\", found \"10\". Argument \"orderby\" has invalid value Name.\nExpected type \"String\", found Name. Argument \"find\" has invalid value cursor1.\nExpected type \"String\", found cursor1. Argument \"isViewerFriend\" has invalid value \"true\".\nExpected type \"Boolean\", found \"true\". Argument \"gender\" has invalid value \"MALE\".\nExpected type \"Gender\", found \"MALE\".`` in file `argsInvalidValues.fixture`."); 27 | })(); 28 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/metadataGenerated.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL` 4 | query { 5 | node(id: 123) 6 | } 7 | `; 8 | 9 | Output: 10 | var Relay = require('react-relay'); 11 | var x = (function () { 12 | return { 13 | calls: [{ 14 | kind: 'Call', 15 | metadata: {}, 16 | name: 'id', 17 | value: { 18 | kind: 'CallValue', 19 | callValue: 123 20 | } 21 | }], 22 | children: [{ 23 | fieldName: 'id', 24 | kind: 'Field', 25 | metadata: { 26 | isGenerated: true, 27 | isRequisite: true 28 | }, 29 | type: 'String' 30 | }, { 31 | fieldName: '__typename', 32 | kind: 'Field', 33 | metadata: { 34 | isGenerated: true, 35 | isRequisite: true 36 | }, 37 | type: 'String' 38 | }], 39 | fieldName: 'node', 40 | kind: 'Query', 41 | metadata: { 42 | isAbstract: true, 43 | identifyingArgName: 'id' 44 | }, 45 | name: 'MetadataGenerated', 46 | type: 'Node' 47 | }; 48 | })(); 49 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/tagRelayQL.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var RelayQL = require('react-relay/RelayQL'); 3 | var x = RelayQL` 4 | query { 5 | node(id: 123) { 6 | id, 7 | }, 8 | } 9 | `; 10 | 11 | Output: 12 | var RelayQL = require('react-relay/RelayQL'); 13 | var x = (function () { 14 | return { 15 | calls: [{ 16 | kind: 'Call', 17 | metadata: {}, 18 | name: 'id', 19 | value: { 20 | kind: 'CallValue', 21 | callValue: 123 22 | } 23 | }], 24 | children: [{ 25 | fieldName: 'id', 26 | kind: 'Field', 27 | metadata: { 28 | isRequisite: true 29 | }, 30 | type: 'String' 31 | }, { 32 | fieldName: '__typename', 33 | kind: 'Field', 34 | metadata: { 35 | isGenerated: true, 36 | isRequisite: true 37 | }, 38 | type: 'String' 39 | }], 40 | fieldName: 'node', 41 | kind: 'Query', 42 | metadata: { 43 | isAbstract: true, 44 | identifyingArgName: 'id' 45 | }, 46 | name: 'TagRelayQL', 47 | type: 'Node' 48 | }; 49 | })(); 50 | -------------------------------------------------------------------------------- /src/tools/RelayInternals.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule RelayInternals 10 | * @flow 11 | */ 12 | 13 | 'use strict'; 14 | 15 | const RelayNetworkLayer = require('RelayNetworkLayer'); 16 | const RelayStoreData = require('RelayStoreData'); 17 | 18 | const flattenRelayQuery = require('flattenRelayQuery'); 19 | const printRelayQuery = require('printRelayQuery'); 20 | 21 | /** 22 | * This module contains internal Relay modules that we expose for development 23 | * tools. They should be considered private APIs. 24 | * 25 | * @internal 26 | */ 27 | var RelayInternals = { 28 | NetworkLayer: RelayNetworkLayer, 29 | DefaultStoreData: RelayStoreData.getDefaultInstance(), 30 | flattenRelayQuery: flattenRelayQuery, 31 | printRelayQuery: printRelayQuery, 32 | }; 33 | 34 | module.exports = RelayInternals; 35 | -------------------------------------------------------------------------------- /examples/star-wars/js/components/StarWarsShip.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file provided by Facebook is for non-commercial testing and evaluation 3 | * purposes only. Facebook reserves all rights not expressly granted. 4 | * 5 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 6 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 7 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 8 | * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 9 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 10 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 11 | */ 12 | 13 | import React from 'react'; 14 | import Relay from 'react-relay'; 15 | 16 | class StarWarsShip extends React.Component { 17 | render() { 18 | var {ship} = this.props; 19 | return
{ship.name}
; 20 | } 21 | } 22 | 23 | export default Relay.createContainer(StarWarsShip, { 24 | fragments: { 25 | ship: () => Relay.QL` 26 | fragment on Ship { 27 | name 28 | } 29 | `, 30 | }, 31 | }); 32 | -------------------------------------------------------------------------------- /src/store/RelayRecordState.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule RelayRecordState 10 | * @flow 11 | * @typechecks 12 | */ 13 | 14 | 'use strict'; 15 | 16 | export type RecordState = $Enum; 17 | 18 | var RelayRecordState = { 19 | /** 20 | * Record exists (either fetched from the server or produced by a local, 21 | * optimistic update). 22 | */ 23 | EXISTENT: 'EXISTENT', 24 | 25 | /** 26 | * Record is known not to exist (either as the result of a mutation, or 27 | * because the server returned `null` when queried for the record). 28 | */ 29 | NONEXISTENT: 'NONEXISTENT', 30 | 31 | /** 32 | * Record State is unknown because it has not yet been fetched from the 33 | * server. 34 | */ 35 | UNKNOWN: 'UNKNOWN', 36 | }; 37 | 38 | module.exports = RelayRecordState; 39 | -------------------------------------------------------------------------------- /src/store/__mocks__/RelayMockCacheManager.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | var RelayMockCacheManager = { 13 | genCacheManager: function() { 14 | var mutationWriter = genMockWriter(); 15 | var queryWriter = genMockWriter(); 16 | return { 17 | mocks: { 18 | mutationWriter, 19 | queryWriter, 20 | }, 21 | getMutationWriter: 22 | jest.genMockFunction().mockReturnValue(mutationWriter), 23 | getQueryWriter: 24 | jest.genMockFunction().mockReturnValue(queryWriter), 25 | }; 26 | }, 27 | }; 28 | 29 | function genMockWriter() { 30 | return { 31 | writeField: jest.genMockFunction(), 32 | writeNode: jest.genMockFunction(), 33 | writeRootCall: jest.genMockFunction(), 34 | }; 35 | } 36 | 37 | module.exports = RelayMockCacheManager; 38 | -------------------------------------------------------------------------------- /src/store/filterExclusiveKeys.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule filterExclusiveKeys 10 | * @typechecks 11 | * @flow 12 | */ 13 | 14 | 'use strict'; 15 | 16 | var hasOwnProperty = Object.prototype.hasOwnProperty; 17 | 18 | /** 19 | * Returns two arrays of keys that contain each object's exclusive keys. 20 | */ 21 | function filterExclusiveKeys( 22 | a: ?Object, 23 | b: ?Object 24 | ): [Array, Array] { 25 | var keysA = a ? Object.keys(a) : []; 26 | var keysB = b ? Object.keys(b) : []; 27 | 28 | if (keysA.length === 0 || 29 | keysB.length === 0) { 30 | return [keysA, keysB]; 31 | } 32 | return [ 33 | keysA.filter(key => !hasOwnProperty.call(b, key)), 34 | keysB.filter(key => !hasOwnProperty.call(a, key)), 35 | ]; 36 | } 37 | 38 | module.exports = filterExclusiveKeys; 39 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/container.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | Relay.createContainer(Component, { 4 | queries: { 5 | viewer: () => Relay.QL`fragment on Viewer { actor { id } }` 6 | } 7 | }); 8 | 9 | Output: 10 | var Relay = require('react-relay'); 11 | Relay.createContainer(Component, { 12 | queries: { 13 | viewer: function viewer() { 14 | return (function () { 15 | return { 16 | children: [{ 17 | children: [{ 18 | fieldName: 'id', 19 | kind: 'Field', 20 | metadata: { 21 | isRequisite: true 22 | }, 23 | type: 'String' 24 | }], 25 | fieldName: 'actor', 26 | kind: 'Field', 27 | metadata: { 28 | inferredRootCallName: 'node', 29 | inferredPrimaryKey: 'id' 30 | }, 31 | type: 'User' 32 | }], 33 | kind: 'Fragment', 34 | metadata: {}, 35 | name: 'Container', 36 | type: 'Viewer' 37 | }; 38 | })(); 39 | } 40 | } 41 | }); 42 | -------------------------------------------------------------------------------- /src/query/RelayRefQueryDescriptor.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule RelayRefQueryDescriptor 10 | * @flow 11 | * @typechecks 12 | */ 13 | 14 | 'use strict'; 15 | 16 | import type RelayQuery from 'RelayQuery'; 17 | 18 | export type NodePath = Array; 19 | 20 | /** 21 | * @internal 22 | * 23 | * Represents a node that will eventually become a "ref query". 24 | * 25 | * Includes the `nodePath` (ancestor nodes) that can be used to construct an 26 | * appropriate the JSONPath for the query. 27 | * 28 | * @see splitDeferredRelayQueries 29 | */ 30 | class RelayRefQueryDescriptor { 31 | node: RelayQuery.Node; 32 | nodePath: NodePath; 33 | 34 | constructor(node: RelayQuery.Node, nodePath: NodePath) { 35 | this.node = node; 36 | this.nodePath = nodePath; 37 | } 38 | } 39 | 40 | module.exports = RelayRefQueryDescriptor; 41 | -------------------------------------------------------------------------------- /src/traversal/filterRelayQuery.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule filterRelayQuery 10 | * @flow 11 | * @typechecks 12 | */ 13 | 14 | 'use strict'; 15 | 16 | import type RelayQuery from 'RelayQuery'; 17 | 18 | type Filter = (node: RelayQuery.Node) => boolean; 19 | 20 | /** 21 | * @internal 22 | * 23 | * `filterRelayQuery` filters query nodes for which `callback` returns false. 24 | * This is intended as a generic filter module and therefore contains no special 25 | * logic for handling requisite or generated fields. 26 | */ 27 | function filterRelayQuery( 28 | node: RelayQuery.Node, 29 | callback: Filter 30 | ): ?RelayQuery.Node { 31 | if (callback(node)) { 32 | return node.clone(node.getChildren().map( 33 | child => filterRelayQuery(child, callback) 34 | )); 35 | } 36 | return null; 37 | } 38 | 39 | module.exports = filterRelayQuery; 40 | -------------------------------------------------------------------------------- /examples/star-wars/js/app.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file provided by Facebook is for non-commercial testing and evaluation 3 | * purposes only. Facebook reserves all rights not expressly granted. 4 | * 5 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 6 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 7 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 8 | * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 9 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 10 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 11 | */ 12 | 13 | import 'babel/polyfill'; 14 | import React from 'react'; 15 | import ReactDOM from 'react-dom'; 16 | import Relay from 'react-relay'; 17 | import StarWarsApp from './components/StarWarsApp'; 18 | import StarWarsAppHomeRoute from './routes/StarWarsAppHomeRoute'; 19 | 20 | ReactDOM.render( 21 | , 27 | document.getElementById('root') 28 | ); 29 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/GraphQLRelayDirective.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @flow 10 | * @fullSyntaxTransform 11 | */ 12 | 13 | 'use strict'; 14 | 15 | const types = require('./GraphQL').type; 16 | 17 | module.exports = { 18 | name: 'relay', 19 | description: 'The @relay directive on fragments.', 20 | args: [ 21 | { 22 | name: 'pattern', 23 | description: 24 | 'Marks a fragment as intended for pattern matching (as ' + 25 | 'opposed to fetching).', 26 | type: types.GraphQLBoolean, 27 | defaultValue: (null: ?boolean), 28 | }, 29 | { 30 | name: 'plural', 31 | description: 'Marks a fragment as being backed by a GraphQLList', 32 | type: types.GraphQLBoolean, 33 | defaultValue: (null: ?boolean), 34 | }, 35 | ], 36 | onOperation: false, 37 | onFragment: true, 38 | onField: false, 39 | }; 40 | -------------------------------------------------------------------------------- /src/route/__tests__/RelayMetaRoute-test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @emails oncall+relay 10 | */ 11 | 12 | 'use strict'; 13 | 14 | const RelayMetaRoute = require('RelayMetaRoute'); 15 | 16 | describe('RelayMetaRoute', () => { 17 | beforeEach(() => { 18 | jest.resetModuleRegistry(); 19 | }); 20 | 21 | it('is immutable', () => { 22 | var route = new RelayMetaRoute('TestRoute'); 23 | expect(() => route.name = 'foo').toThrow(); 24 | }); 25 | 26 | it('returns caches objects when using `get`', () => { 27 | expect( 28 | RelayMetaRoute.get('TestRoute') 29 | ).toBe(RelayMetaRoute.get('TestRoute')); 30 | 31 | expect( 32 | RelayMetaRoute.get('TestRoute') 33 | ).not.toBe(RelayMetaRoute.get('TestRoute2')); 34 | 35 | expect( 36 | RelayMetaRoute.get('TestRoute2') 37 | ).toBe(RelayMetaRoute.get('TestRoute2')); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /docs/QuickStart-Videos.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: videos 3 | title: Videos 4 | layout: docs 5 | category: Quick Start 6 | permalink: docs/videos.html 7 | next: guides-containers 8 | --- 9 | 10 | ## [@Scale September 2015](http://www.atscaleconference.com/) 11 | 12 | 13 | 14 | ## [ReactEurope July 2015](https://www.react-europe.org/2015/2015.html) 15 | 16 | 17 | 18 | ## [JSConf US May 2015](http://2015.jsconf.us/) 19 | 20 | 21 | 22 | ## [React.js Conf January 2015](http://conf.reactjs.com/) 23 | 24 | 25 | 26 | Now that we've gone end-to-end with Relay, let's dive into more detail in the guides section. 27 | -------------------------------------------------------------------------------- /scripts/jest/updateSchema.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env babel-node --optional es7.asyncFunctions 2 | /** 3 | * Copyright 2013-2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | import fs from 'fs'; 12 | import path from 'path'; 13 | import { parse } from 'graphql/language'; 14 | import { buildASTSchema, introspectionQuery } from 'graphql/utilities'; 15 | import { graphql } from 'graphql'; 16 | 17 | try { 18 | var inFile = path.resolve(__dirname, 'testschema.graphql'); 19 | var outFile = path.resolve(__dirname, 'testschema.json'); 20 | 21 | var body = fs.readFileSync(inFile, 'utf8'); 22 | var ast = parse(body); 23 | var astSchema = buildASTSchema(ast, 'Root', 'Mutation'); 24 | graphql(astSchema, introspectionQuery).then( 25 | function(result) { 26 | var out = JSON.stringify(result, null, 2); 27 | fs.writeFileSync(outFile, out); 28 | }); 29 | } catch (error) { 30 | console.error(error); 31 | console.error(error.stack); 32 | } 33 | -------------------------------------------------------------------------------- /src/container/__tests__/isRelayContainer-test.js: -------------------------------------------------------------------------------- 1 | // /** 2 | // * Copyright 2013-2015, Facebook, Inc. 3 | // * All rights reserved. 4 | // * 5 | // * This source code is licensed under the BSD-style license found in the 6 | // * LICENSE file in the root directory of this source tree. An additional grant 7 | // * of patent rights can be found in the PATENTS file in the same directory. 8 | // * 9 | // * @emails oncall+relay 10 | // */ 11 | // 12 | // 'use strict'; 13 | // 14 | // const React = require('React'); 15 | // const Relay = require('Relay'); 16 | // 17 | // describe('isRelayContainer', function() { 18 | // var MockComponent; 19 | // var MockContainer; 20 | // 21 | // beforeEach(function() { 22 | // jest.resetModuleRegistry(); 23 | // 24 | // MockComponent = React.createClass({ 25 | // render: () =>
, 26 | // }); 27 | // 28 | // MockContainer = Relay.createContainer(MockComponent, { 29 | // fragments: {}, 30 | // }); 31 | // }); 32 | // 33 | // it('identifies Relay containers correctly', () => { 34 | // expect(Relay.isContainer(MockContainer)).toBe(true); 35 | // 36 | // expect(Relay.isContainer(MockComponent)).toBe(false); 37 | // }); 38 | // }); 39 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/queryWithVarArgs.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL` 4 | query { 5 | nodes(ids: [123,456]) { 6 | id, 7 | }, 8 | } 9 | `; 10 | 11 | Output: 12 | var Relay = require('react-relay'); 13 | var x = (function () { 14 | return { 15 | calls: [{ 16 | kind: 'Call', 17 | metadata: {}, 18 | name: 'ids', 19 | value: [{ 20 | kind: 'CallValue', 21 | callValue: 123 22 | }, { 23 | kind: 'CallValue', 24 | callValue: 456 25 | }] 26 | }], 27 | children: [{ 28 | fieldName: 'id', 29 | kind: 'Field', 30 | metadata: { 31 | isRequisite: true 32 | }, 33 | type: 'String' 34 | }, { 35 | fieldName: '__typename', 36 | kind: 'Field', 37 | metadata: { 38 | isGenerated: true, 39 | isRequisite: true 40 | }, 41 | type: 'String' 42 | }], 43 | fieldName: 'nodes', 44 | kind: 'Query', 45 | metadata: { 46 | isPlural: true, 47 | isAbstract: true, 48 | identifyingArgName: 'ids' 49 | }, 50 | name: 'QueryWithVarArgs', 51 | type: 'Node' 52 | }; 53 | })(); 54 | -------------------------------------------------------------------------------- /src/query/callsToGraphQL.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule callsToGraphQL 10 | * @flow 11 | * @typechecks 12 | */ 13 | 14 | 'use strict'; 15 | 16 | import type {ConcreteCall} from 'ConcreteQuery'; 17 | import type {Call} from 'RelayInternalTypes'; 18 | const QueryBuilder = require('QueryBuilder'); 19 | 20 | /** 21 | * @internal 22 | * 23 | * Convert from plain object `{name, value}` calls to GraphQL call nodes. 24 | */ 25 | function callsToGraphQL(calls: Array): Array { 26 | return calls.map(({name, value}) => { 27 | let concreteValue = null; 28 | if (Array.isArray(value)) { 29 | concreteValue = value.map(QueryBuilder.createCallValue); 30 | } else if (value != null) { 31 | concreteValue = QueryBuilder.createCallValue(value); 32 | } 33 | return QueryBuilder.createCall(name, concreteValue); 34 | }); 35 | } 36 | 37 | module.exports = callsToGraphQL; 38 | -------------------------------------------------------------------------------- /examples/todo/README.md: -------------------------------------------------------------------------------- 1 | # Relay TodoMVC 2 | 3 | ## Installation 4 | 5 | ``` 6 | npm install 7 | ``` 8 | 9 | ## Running 10 | 11 | Start a local server: 12 | 13 | ``` 14 | npm start 15 | ``` 16 | 17 | ## Developing 18 | 19 | Any changes you make to files in the `js/` directory will cause the server to 20 | automatically rebuild the app and refresh your browser. 21 | 22 | If at any time you make changes to `data/schema.js`, stop the server, 23 | regenerate `data/schema.json`, and restart the server: 24 | 25 | ``` 26 | npm run update-schema 27 | npm start 28 | ``` 29 | 30 | ## License 31 | 32 | This file provided by Facebook is for non-commercial testing and evaluation 33 | purposes only. Facebook reserves all rights not expressly granted. 34 | 35 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 36 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 37 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 38 | FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 39 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 40 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 41 | -------------------------------------------------------------------------------- /examples/star-wars/README.md: -------------------------------------------------------------------------------- 1 | # Relay Star Wars 2 | 3 | ## Installation 4 | 5 | ``` 6 | npm install 7 | ``` 8 | 9 | ## Running 10 | 11 | Start a local server: 12 | 13 | ``` 14 | npm start 15 | ``` 16 | 17 | ## Developing 18 | 19 | Any changes you make to files in the `js/` directory will cause the server to 20 | automatically rebuild the app and refresh your browser. 21 | 22 | If at any time you make changes to `data/schema.js`, stop the server, 23 | regenerate `data/schema.json`, and restart the server: 24 | 25 | ``` 26 | npm run update-schema 27 | npm start 28 | ``` 29 | 30 | ## License 31 | 32 | This file provided by Facebook is for non-commercial testing and evaluation 33 | purposes only. Facebook reserves all rights not expressly granted. 34 | 35 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 36 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 37 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 38 | FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 39 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 40 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 41 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/argsVariablesList.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var foo = Relay.QL` 3 | query Args { 4 | nodes(ids: [$one, $two, 3]) { 5 | id, 6 | }, 7 | } 8 | `; 9 | 10 | Output: 11 | var foo = (function () { 12 | return { 13 | calls: [{ 14 | kind: "Call", 15 | metadata: {}, 16 | name: "ids", 17 | value: [{ 18 | kind: "CallVariable", 19 | callVariableName: "one" 20 | }, { 21 | kind: "CallVariable", 22 | callVariableName: "two" 23 | }, { 24 | kind: "CallValue", 25 | callValue: 3 26 | }] 27 | }], 28 | children: [{ 29 | fieldName: "id", 30 | kind: "Field", 31 | metadata: { 32 | isRequisite: true 33 | }, 34 | type: "String" 35 | }, { 36 | fieldName: "__typename", 37 | kind: "Field", 38 | metadata: { 39 | isGenerated: true, 40 | isRequisite: true 41 | }, 42 | type: "String" 43 | }], 44 | fieldName: "nodes", 45 | kind: "Query", 46 | metadata: { 47 | isPlural: true, 48 | isAbstract: true, 49 | identifyingArgName: "ids" 50 | }, 51 | name: "Args", 52 | type: "Node" 53 | }; 54 | })(); 55 | -------------------------------------------------------------------------------- /examples/star-wars-angular/README.md: -------------------------------------------------------------------------------- 1 | # Relay Star Wars 2 | 3 | ## Installation 4 | 5 | ``` 6 | npm install 7 | ``` 8 | 9 | ## Running 10 | 11 | Start a local server: 12 | 13 | ``` 14 | npm start 15 | ``` 16 | 17 | ## Developing 18 | 19 | Any changes you make to files in the `js/` directory will cause the server to 20 | automatically rebuild the app and refresh your browser. 21 | 22 | If at any time you make changes to `data/schema.js`, stop the server, 23 | regenerate `data/schema.json`, and restart the server: 24 | 25 | ``` 26 | npm run update-schema 27 | npm start 28 | ``` 29 | 30 | ## License 31 | 32 | This file provided by Facebook is for non-commercial testing and evaluation 33 | purposes only. Facebook reserves all rights not expressly granted. 34 | 35 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 36 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 37 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 38 | FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 39 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 40 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 41 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/metadataVarArgs.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL` 4 | fragment on User { 5 | friends(orderby: $order) { 6 | count, 7 | }, 8 | } 9 | `; 10 | 11 | Output: 12 | var Relay = require('react-relay'); 13 | var x = (function () { 14 | return { 15 | children: [{ 16 | calls: [{ 17 | kind: 'Call', 18 | metadata: {}, 19 | name: 'orderby', 20 | value: { 21 | kind: 'CallVariable', 22 | callVariableName: 'order' 23 | } 24 | }], 25 | children: [{ 26 | fieldName: 'count', 27 | kind: 'Field', 28 | metadata: {}, 29 | type: 'Int' 30 | }], 31 | fieldName: 'friends', 32 | kind: 'Field', 33 | metadata: { 34 | isConnection: true, 35 | isFindable: true 36 | }, 37 | type: 'UserConnection' 38 | }, { 39 | fieldName: 'id', 40 | kind: 'Field', 41 | metadata: { 42 | isGenerated: true, 43 | isRequisite: true 44 | }, 45 | type: 'String' 46 | }], 47 | kind: 'Fragment', 48 | metadata: {}, 49 | name: 'MetadataVarArgs', 50 | type: 'User' 51 | }; 52 | })(); 53 | -------------------------------------------------------------------------------- /examples/relay-treasurehunt/README.md: -------------------------------------------------------------------------------- 1 | # Relay Treasure Hunt 2 | 3 | ## Installation 4 | 5 | ``` 6 | npm install 7 | ``` 8 | 9 | ## Running 10 | 11 | Start a local server: 12 | 13 | ``` 14 | npm start 15 | ``` 16 | 17 | ## Developing 18 | 19 | Any changes you make to files in the `js/` directory will cause the server to 20 | automatically rebuild the app and refresh your browser. 21 | 22 | If at any time you make changes to `data/schema.js`, stop the server, 23 | regenerate `data/schema.json`, and restart the server: 24 | 25 | ``` 26 | npm run update-schema 27 | npm start 28 | ``` 29 | 30 | ## License 31 | 32 | This file provided by Facebook is for non-commercial testing and evaluation 33 | purposes only. Facebook reserves all rights not expressly granted. 34 | 35 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 36 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 37 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 38 | FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 39 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 40 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 41 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/fieldWithEmptyArrayArg.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL` 4 | fragment on User { 5 | friends(isViewerFriend: false) { 6 | count, 7 | }, 8 | } 9 | `; 10 | 11 | Output: 12 | var Relay = require('react-relay'); 13 | var x = (function () { 14 | return { 15 | children: [{ 16 | calls: [{ 17 | kind: 'Call', 18 | metadata: {}, 19 | name: 'isViewerFriend', 20 | value: { 21 | kind: 'CallValue', 22 | callValue: false 23 | } 24 | }], 25 | children: [{ 26 | fieldName: 'count', 27 | kind: 'Field', 28 | metadata: {}, 29 | type: 'Int' 30 | }], 31 | fieldName: 'friends', 32 | kind: 'Field', 33 | metadata: { 34 | isConnection: true, 35 | isFindable: true 36 | }, 37 | type: 'UserConnection' 38 | }, { 39 | fieldName: 'id', 40 | kind: 'Field', 41 | metadata: { 42 | isGenerated: true, 43 | isRequisite: true 44 | }, 45 | type: 'String' 46 | }], 47 | kind: 'Fragment', 48 | metadata: {}, 49 | name: 'FieldWithEmptyArrayArg', 50 | type: 'User' 51 | }; 52 | })(); 53 | -------------------------------------------------------------------------------- /src/query/getConcreteFragmentHash.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule getConcreteFragmentHash 10 | * @typechecks 11 | * @flow 12 | */ 13 | 14 | 'use strict'; 15 | 16 | import type {ConcreteFragment} from 'ConcreteQuery'; 17 | 18 | let _nextFragmentID = 0; 19 | 20 | /** 21 | * The "concrete hash" of a fragment uniquely identifies the instance of the 22 | * concrete node. This method should be used with `RelayQueryFragment#isCloned` 23 | * if you may be dealing with fragments that have been cloned with new children. 24 | * 25 | * This hash may change between runtime sessions (e.g. client and server). 26 | */ 27 | function getConcreteFragmentHash(fragment: ConcreteFragment): string { 28 | let instanceHash = (fragment: any).__instanceHash__; 29 | if (instanceHash == null) { 30 | instanceHash = (_nextFragmentID++).toString(); 31 | (fragment: any).__instanceHash__ = instanceHash; 32 | } 33 | return instanceHash; 34 | } 35 | 36 | module.exports = getConcreteFragmentHash; 37 | -------------------------------------------------------------------------------- /src/network/__mocks__/fetchRelayQuery.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | var fetchRelayQuery = jest.genMockFromModule('fetchRelayQuery'); 13 | 14 | /** 15 | * Mock object to simulate the behavior of a request. Example usage: 16 | * 17 | * // Successful fetch. 18 | * fetchRelayQuery(queryA); 19 | * fetchRelayQuery.mock.requests[0].resolve(response); 20 | * 21 | * // Fetch with partial error. 22 | * fetchRelayQuery(queryB); 23 | * fetchRelayQuery.mock.requests[0].resolve(response, error); 24 | * 25 | * // Failed fetch. 26 | * fetchRelayQuery(queryC); 27 | * fetchRelayQuery.mock.requests[0].reject(error); 28 | * 29 | */ 30 | function genMockRequest(resolve, reject) { 31 | fetchRelayQuery.mock.requests.push({ 32 | resolve(response, error) { 33 | resolve({error: error || null, response}); 34 | }, 35 | reject, 36 | }); 37 | } 38 | 39 | fetchRelayQuery.mock.requests = []; 40 | fetchRelayQuery.mockImplementation(() => new Promise(genMockRequest)); 41 | 42 | module.exports = fetchRelayQuery; 43 | -------------------------------------------------------------------------------- /website/core/HeaderLinks.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule HeaderLinks 10 | */ 11 | 12 | var HeaderLinks = React.createClass({ 13 | links: [ 14 | {section: 'playground', href: '/relay/prototyping/playground.html', text: 'Try it out'}, 15 | {section: 'docs', href: '/relay/docs/getting-started.html#content', text: 'Docs'}, 16 | {section: 'support', href: '/relay/support.html', text: 'Support'}, 17 | {section: 'github', href: 'https://github.com/facebook/relay', text: 'GitHub'}, 18 | ], 19 | 20 | render: function() { 21 | return ( 22 |
    23 | {this.links.map(function(link) { 24 | return ( 25 |
  • 26 | 29 | {link.text} 30 | 31 |
  • 32 | ); 33 | }, this)} 34 |
35 | ); 36 | } 37 | }); 38 | 39 | module.exports = HeaderLinks; 40 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/inlineFragment.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL` 4 | fragment on Node { 5 | ... on User { 6 | userOnlyField, 7 | }, 8 | } 9 | `; 10 | 11 | Output: 12 | var Relay = require('react-relay'); 13 | var x = (function () { 14 | return { 15 | children: [{ 16 | fieldName: 'id', 17 | kind: 'Field', 18 | metadata: { 19 | isGenerated: true, 20 | isRequisite: true 21 | }, 22 | type: 'String' 23 | }, { 24 | fieldName: '__typename', 25 | kind: 'Field', 26 | metadata: { 27 | isGenerated: true, 28 | isRequisite: true 29 | }, 30 | type: 'String' 31 | }, { 32 | children: [{ 33 | fieldName: 'userOnlyField', 34 | kind: 'Field', 35 | metadata: {}, 36 | type: 'String' 37 | }, { 38 | fieldName: 'id', 39 | kind: 'Field', 40 | metadata: { 41 | isGenerated: true, 42 | isRequisite: true 43 | }, 44 | type: 'String' 45 | }], 46 | kind: 'Fragment', 47 | metadata: {}, 48 | name: 'User', 49 | type: 'User' 50 | }], 51 | kind: 'Fragment', 52 | metadata: { 53 | isAbstract: true 54 | }, 55 | name: 'InlineFragment', 56 | type: 'Node' 57 | }; 58 | })(); 59 | -------------------------------------------------------------------------------- /src/tools/isCompatibleRelayFragmentType.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule isCompatibleRelayFragmentType 10 | * @flow 11 | * @typechecks 12 | */ 13 | 14 | 'use strict'; 15 | 16 | import type RelayQuery from 'RelayQuery'; 17 | 18 | /** 19 | * @internal 20 | * 21 | * Determine if the given fragment's type is compatible with the given record 22 | * type. The types are considered compatible if they exactly match or in the 23 | * following cases: 24 | * - Types are not recorded for optimistic records; if the record type is null 25 | * it is assumed to be compatible with the fragment. 26 | * - Abstract fragments are assumed to be compatible with all types; being more 27 | * precise would require access to the full schema inheritance hierarchy. 28 | */ 29 | function isCompatibleRelayFragmentType( 30 | fragment: RelayQuery.Fragment, 31 | recordType: ?string 32 | ): boolean { 33 | return ( 34 | recordType === fragment.getType() || 35 | !recordType || 36 | fragment.isAbstract() 37 | ); 38 | } 39 | 40 | module.exports = isCompatibleRelayFragmentType; 41 | -------------------------------------------------------------------------------- /src/container/__tests__/isReactComponent-test.js: -------------------------------------------------------------------------------- 1 | // /** 2 | // * Copyright 2013-2015, Facebook, Inc. 3 | // * All rights reserved. 4 | // * 5 | // * This source code is licensed under the BSD-style license found in the 6 | // * LICENSE file in the root directory of this source tree. An additional grant 7 | // * of patent rights can be found in the PATENTS file in the same directory. 8 | // * 9 | // * @emails oncall+relay 10 | // */ 11 | // 12 | // 'use strict'; 13 | // 14 | // const React = require('React'); 15 | // const isReactComponent = require('isReactComponent'); 16 | // 17 | // describe('isReactComponent', function() { 18 | // it('identifies components that extends React.Component', function() { 19 | // class MockComponent extends React.Component { 20 | // render() { 21 | // return
; 22 | // } 23 | // } 24 | // expect(isReactComponent(MockComponent)).toBe(true); 25 | // }); 26 | // 27 | // it('identifies components created by React.createClass()', function() { 28 | // var MockComponent = React.createClass({ 29 | // render: () =>
, 30 | // }); 31 | // expect(isReactComponent(MockComponent)).toBe(true); 32 | // }); 33 | // 34 | // it('does not identify function components', function() { 35 | // var MockComponent = () =>
; 36 | // expect(isReactComponent(MockComponent)).toBe(false); 37 | // }); 38 | // }); 39 | -------------------------------------------------------------------------------- /website-prototyping-tools/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "name": "relay-prototyping-tools", 4 | "description": "In-browser prototyping tools for Relay applications", 5 | "version": "0.2.0", 6 | "repository": "facebook/relay", 7 | "license": "BSD-3-Clause", 8 | "dependencies": { 9 | "autoprefixer-loader": "3.1.0", 10 | "babel": "5.8.23", 11 | "babel-core": "5.8.25", 12 | "babel-loader": "5.3.2", 13 | "babel-plugin-react-error-catcher": "1.1.9", 14 | "babel-relay-plugin": "../scripts/babel-relay-plugin", 15 | "codemirror": "5.6.0", 16 | "css-loader": "0.16.0", 17 | "file-loader": "0.8.4", 18 | "graphiql": "0.1.3", 19 | "graphql": "0.4.13", 20 | "graphql-relay": "0.3.2", 21 | "html-webpack-plugin": "1.6.1", 22 | "json-loader": "0.5.3", 23 | "lodash.debounce": "3.1.1", 24 | "lodash.defer": "3.1.0", 25 | "lodash.delay": "3.1.0", 26 | "minimist": "1.2.0", 27 | "normalize.css": "3.0.3", 28 | "querystring": "0.2.0", 29 | "raw-loader": "0.5.1", 30 | "react": "^0.14.0-rc", 31 | "react-codemirror": "0.1.5", 32 | "relay-local-schema": "0.3.0", 33 | "react-relay": "../", 34 | "style-loader": "0.12.3", 35 | "webpack": "1.12.0" 36 | }, 37 | "scripts": { 38 | "start": "webpack --watch --progress --colors", 39 | "build": "webpack --progress --colors --target-dir=build" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/tools/RelayError.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule RelayError 10 | * @typechecks 11 | * @flow 12 | */ 13 | 14 | 'use strict'; 15 | 16 | const sprintf = require('sprintf'); 17 | 18 | /** 19 | * @internal 20 | * 21 | * Factory methods for constructing errors in Relay. 22 | */ 23 | const RelayError = { 24 | create(name: string, format: string, ...args: Array): Error { 25 | return createError('mustfix', name, format, args); 26 | }, 27 | createWarning(name: string, format: string, ...args: Array): Error { 28 | return createError('warn', name, format, args); 29 | }, 30 | }; 31 | 32 | /** 33 | * @private 34 | */ 35 | function createError( 36 | type: string, 37 | name: string, 38 | format: string, 39 | args: Array 40 | ): Error { 41 | /*eslint-disable fb-www/sprintf-like-args */ 42 | const error = new Error(sprintf(format, ...args)); 43 | /*eslint-enable fb-www/sprintf-like-args */ 44 | error.name = name; 45 | (error: any).type = type; 46 | (error: any).framesToPop = 2; 47 | return error; 48 | } 49 | 50 | module.exports = RelayError; 51 | -------------------------------------------------------------------------------- /src/query/RelayRouteFragment.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule RelayRouteFragment 10 | * @flow 11 | * @typechecks 12 | */ 13 | 14 | 'use strict'; 15 | 16 | import type RelayMetaRoute from 'RelayMetaRoute'; 17 | import type {RelayConcreteNode} from 'RelayQL'; 18 | 19 | type FragmentBuilder = (route: RelayMetaRoute) => ?RelayConcreteNode; 20 | 21 | /** 22 | * Represents a query fragment that is conditional upon the active route as a 23 | * function that returns either a literal fragment or a fragment reference. 24 | * 25 | * Example GraphQL: 26 | * 27 | * ``` 28 | * Node { 29 | * ${(route) => matchRoute(route, ...)} 30 | * } 31 | * ``` 32 | */ 33 | class RelayRouteFragment { 34 | _builder: FragmentBuilder; 35 | 36 | constructor(builder: FragmentBuilder) { 37 | this._builder = builder; 38 | } 39 | 40 | /** 41 | * Returns the query fragment that matches the given route, if any. 42 | */ 43 | getFragmentForRoute( 44 | route: RelayMetaRoute 45 | ): ?RelayConcreteNode { 46 | return this._builder(route); 47 | } 48 | } 49 | 50 | module.exports = RelayRouteFragment; 51 | -------------------------------------------------------------------------------- /src/tools/__mocks__/RelayProfiler.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | const emptyFunction = require('emptyFunction'); 13 | const forEachObject = require('forEachObject'); 14 | 15 | var RelayProfiler = { 16 | instrumentMethods: jest.genMockFunction().mockImplementation( 17 | (object, names) => { 18 | forEachObject(names, (name, key) => { 19 | object[key] = RelayProfiler.instrument(name, object[key]); 20 | }); 21 | } 22 | ), 23 | instrument: jest.genMockFunction().mockImplementation( 24 | (name, handler) => { 25 | handler.attachHandler = emptyFunction; 26 | handler.detachHandler = emptyFunction; 27 | return handler; 28 | } 29 | ), 30 | attachAggregateHandler: jest.genMockFunction(), 31 | detachAggregateHandler: jest.genMockFunction(), 32 | profile: jest.genMockFunction().mockImplementation(() => { 33 | return { 34 | stop: jest.genMockFunction(), 35 | }; 36 | }), 37 | attachProfileHandler: jest.genMockFunction(), 38 | detachProfileHandler: jest.genMockFunction(), 39 | }; 40 | 41 | module.exports = RelayProfiler; 42 | -------------------------------------------------------------------------------- /src/traversal/flattenSplitRelayQueries.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule flattenSplitRelayQueries 10 | * @flow 11 | * @typechecks 12 | */ 13 | 14 | 'use strict'; 15 | 16 | import type RelayQuery from 'RelayQuery'; 17 | 18 | import type {SplitQueries} from 'splitDeferredRelayQueries'; 19 | 20 | /** 21 | * Flattens the nested structure returned by `splitDeferredRelayQueries`. 22 | * 23 | * Right now our internals discard the information about the relationship 24 | * between the queries that is encoded in the nested structure. 25 | * 26 | * @internal 27 | */ 28 | function flattenSplitRelayQueries( 29 | splitQueries: SplitQueries 30 | ): Array { 31 | var flattenedQueries = []; 32 | var queue = [splitQueries]; 33 | while (queue.length) { 34 | splitQueries = queue.shift(); 35 | var {required, deferred} = splitQueries; 36 | if (required) { 37 | flattenedQueries.push(required); 38 | } 39 | if (deferred.length) { 40 | queue.push(...deferred); 41 | } 42 | } 43 | return flattenedQueries; 44 | } 45 | 46 | module.exports = flattenSplitRelayQueries; 47 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/GraphQL.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @flow 10 | * @fullSyntaxTransform 11 | */ 12 | 13 | 'use strict'; 14 | 15 | const GraphQL = { 16 | error: require('graphql/error'), 17 | language: require('graphql/language'), 18 | language_parser: require('graphql/language/parser'), 19 | language_source: require('graphql/language/source'), 20 | type: require('graphql/type'), 21 | type_introspection: require('graphql/type/introspection'), 22 | utilities: require('graphql/utilities'), 23 | utilities_buildClientSchema: require('graphql/utilities/buildClientSchema'), 24 | validation: require('graphql/validation'), 25 | validation_rules_KnownFragmentNames: require('graphql/validation/rules/KnownFragmentNames'), 26 | validation_rules_NoUndefinedVariables: require('graphql/validation/rules/NoUndefinedVariables'), 27 | validation_rules_NoUnusedFragments: require('graphql/validation/rules/NoUnusedFragments'), 28 | validation_rules_ScalarLeafs: require('graphql/validation/rules/ScalarLeafs'), 29 | validation_validate: require('graphql/validation/validate'), 30 | }; 31 | 32 | module.exports = GraphQL; 33 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/lib/GraphQL.js: -------------------------------------------------------------------------------- 1 | // @generated 2 | /** 3 | * Copyright 2013-2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | * 10 | * 11 | * @fullSyntaxTransform 12 | */ 13 | 14 | 'use strict'; 15 | 16 | var GraphQL = { 17 | error: require('graphql/error'), 18 | language: require('graphql/language'), 19 | language_parser: require('graphql/language/parser'), 20 | language_source: require('graphql/language/source'), 21 | type: require('graphql/type'), 22 | type_introspection: require('graphql/type/introspection'), 23 | utilities: require('graphql/utilities'), 24 | utilities_buildClientSchema: require('graphql/utilities/buildClientSchema'), 25 | validation: require('graphql/validation'), 26 | validation_rules_KnownFragmentNames: require('graphql/validation/rules/KnownFragmentNames'), 27 | validation_rules_NoUndefinedVariables: require('graphql/validation/rules/NoUndefinedVariables'), 28 | validation_rules_NoUnusedFragments: require('graphql/validation/rules/NoUnusedFragments'), 29 | validation_rules_ScalarLeafs: require('graphql/validation/rules/ScalarLeafs'), 30 | validation_validate: require('graphql/validation/validate') 31 | }; 32 | 33 | module.exports = GraphQL; -------------------------------------------------------------------------------- /src/store/__tests__/RelayRecord-test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @emails oncall+relay 10 | */ 11 | 12 | 'use strict'; 13 | 14 | const RelayRecord = require('RelayRecord'); 15 | 16 | describe('RelayRecord', () => { 17 | beforeEach(() => { 18 | jest.resetModuleRegistry(); 19 | }); 20 | 21 | it('checks if a value is a record', () => { 22 | expect(RelayRecord.isRecord({__dataID__: '123'})).toBe(true); 23 | 24 | expect(RelayRecord.isRecord(null)).toBe(false); 25 | expect(RelayRecord.isRecord(undefined)).toBe(false); 26 | expect(RelayRecord.isRecord([])).toBe(false); 27 | expect(RelayRecord.isRecord({})).toBe(false); 28 | 29 | const deceptiveArray = []; 30 | deceptiveArray.__dataID__ = '123'; 31 | expect(RelayRecord.isRecord(deceptiveArray)).toBe(false); 32 | }); 33 | 34 | it('checks if a key is for metadata', () => { 35 | expect(RelayRecord.isMetadataKey('__dataID__')).toBe(true); 36 | expect(RelayRecord.isMetadataKey('__range__')).toBe(true); 37 | 38 | expect(RelayRecord.isMetadataKey('id')).toBe(false); 39 | expect(RelayRecord.isMetadataKey('')).toBe(false); 40 | }); 41 | }); 42 | -------------------------------------------------------------------------------- /docs/APIReference-PropTypes.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: api-reference-relay-proptypes 3 | title: Relay.PropTypes 4 | layout: docs 5 | category: API Reference 6 | permalink: docs/api-reference-relay-proptypes.html 7 | next: api-reference-relay-store 8 | --- 9 | 10 | Relay introduces two new classes of objects: `RelayContainer` and `Relay.Route`. `Relay.PropTypes` provides prop validators used to assert that props are of these types. 11 | 12 | ## Overview 13 | 14 | *Properties* 15 | 16 | 30 | 31 | ## Example 32 | 33 | ``` 34 | class MyApplication extends React.Component { 35 | static propTypes = { 36 | // Warns if `Component` is not a valid RelayContainer. 37 | Component: Relay.PropTypes.Container.isRequired, 38 | // Warns if `route` is not a valid route. 39 | route: Relay.PropTypes.QueryConfig.isRequired, 40 | }; 41 | render() { 42 | return ( 43 | 47 | ); 48 | } 49 | } 50 | ``` 51 | -------------------------------------------------------------------------------- /website/core/Header.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @providesModule Header 3 | */ 4 | 5 | var React = require('React'); 6 | 7 | var Header = React.createClass({ 8 | slug: function(string) { 9 | // var accents = "àáäâèéëêìíïîòóöôùúüûñç"; 10 | var accents = "\u00e0\u00e1\u00e4\u00e2\u00e8" 11 | + "\u00e9\u00eb\u00ea\u00ec\u00ed\u00ef" 12 | + "\u00ee\u00f2\u00f3\u00f6\u00f4\u00f9" 13 | + "\u00fa\u00fc\u00fb\u00f1\u00e7"; 14 | 15 | var without = "aaaaeeeeiiiioooouuuunc"; 16 | 17 | return string 18 | .toString() 19 | 20 | // Handle uppercase characters 21 | .toLowerCase() 22 | 23 | // Handle accentuated characters 24 | .replace( 25 | new RegExp('[' + accents + ']', 'g'), 26 | function (c) { return without.charAt(accents.indexOf(c)); }) 27 | 28 | // Dash special characters 29 | .replace(/[^a-z0-9]/g, '-') 30 | 31 | // Compress multiple dash 32 | .replace(/-+/g, '-') 33 | 34 | // Trim dashes 35 | .replace(/^-|-$/g, ''); 36 | }, 37 | 38 | render: function() { 39 | var slug = this.slug(this.props.toSlug || this.props.children); 40 | var Heading = 'h' + this.props.level; 41 | 42 | return ( 43 | 44 | 45 | {this.props.children} 46 | {' '}# 47 | 48 | ); 49 | } 50 | }); 51 | 52 | module.exports = Header; 53 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/tools/generateSchemaJson.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @fullSyntaxTransform 10 | */ 11 | 12 | /** 13 | * Generates `testschema.rfc.json` from `testschema.rfc.graphql`. 14 | */ 15 | 16 | const fs = require('fs'); 17 | const path = require('path'); 18 | const language = require('graphql/language'); 19 | const utilities = require('graphql/utilities'); 20 | const graphql = require('graphql'); 21 | 22 | const TESTS_DIR = path.resolve(__dirname, '..', '__tests__'); 23 | 24 | try { 25 | const inFile = path.join(TESTS_DIR, 'testschema.rfc.graphql'); 26 | const outFile = path.join(TESTS_DIR, 'testschema.rfc.json'); 27 | 28 | const body = fs.readFileSync(inFile, 'utf8'); 29 | const ast = language.parse(body); 30 | const astSchema = utilities.buildASTSchema( 31 | ast, 32 | 'Root', 33 | 'Mutation', 34 | 'Subscription' 35 | ); 36 | graphql.graphql(astSchema, utilities.introspectionQuery).then( 37 | function(result) { 38 | const out = JSON.stringify(result, null, 2); 39 | fs.writeFileSync(outFile, out); 40 | }); 41 | } catch (error) { 42 | console.error(error); 43 | console.error(error.stack); 44 | } 45 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/lib/tools/generateSchemaJson.js: -------------------------------------------------------------------------------- 1 | // @generated 2 | /** 3 | * Copyright 2013-2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | * 10 | * @fullSyntaxTransform 11 | */ 12 | 13 | /** 14 | * Generates `testschema.rfc.json` from `testschema.rfc.graphql`. 15 | */ 16 | 17 | 'use strict'; 18 | 19 | var fs = require('fs'); 20 | var path = require('path'); 21 | var language = require('graphql/language'); 22 | var utilities = require('graphql/utilities'); 23 | var graphql = require('graphql'); 24 | 25 | var TESTS_DIR = path.resolve(__dirname, '..', '__tests__'); 26 | 27 | try { 28 | (function () { 29 | var inFile = path.join(TESTS_DIR, 'testschema.rfc.graphql'); 30 | var outFile = path.join(TESTS_DIR, 'testschema.rfc.json'); 31 | 32 | var body = fs.readFileSync(inFile, 'utf8'); 33 | var ast = language.parse(body); 34 | var astSchema = utilities.buildASTSchema(ast, 'Root', 'Mutation', 'Subscription'); 35 | graphql.graphql(astSchema, utilities.introspectionQuery).then(function (result) { 36 | var out = JSON.stringify(result, null, 2); 37 | fs.writeFileSync(outFile, out); 38 | }); 39 | })(); 40 | } catch (error) { 41 | console.error(error); 42 | console.error(error.stack); 43 | } -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/fragmentWithModuleName.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | /** @providesModule Foo.react */ 3 | var Relay = require('react-relay'); 4 | var x = Relay.QL`fragment Foo on Node { id }`; 5 | var y = Relay.QL`fragment Bar on Node { id }`; 6 | 7 | Output: 8 | /** @providesModule Foo.react */ 9 | var Relay = require('react-relay'); 10 | var x = (function () { 11 | return { 12 | children: [{ 13 | fieldName: 'id', 14 | kind: 'Field', 15 | metadata: { 16 | isRequisite: true 17 | }, 18 | type: 'String' 19 | }, { 20 | fieldName: '__typename', 21 | kind: 'Field', 22 | metadata: { 23 | isGenerated: true, 24 | isRequisite: true 25 | }, 26 | type: 'String' 27 | }], 28 | kind: 'Fragment', 29 | metadata: { 30 | isAbstract: true 31 | }, 32 | name: 'Foo', 33 | type: 'Node' 34 | }; 35 | })(); 36 | var y = (function () { 37 | return { 38 | children: [{ 39 | fieldName: 'id', 40 | kind: 'Field', 41 | metadata: { 42 | isRequisite: true 43 | }, 44 | type: 'String' 45 | }, { 46 | fieldName: '__typename', 47 | kind: 'Field', 48 | metadata: { 49 | isGenerated: true, 50 | isRequisite: true 51 | }, 52 | type: 'String' 53 | }], 54 | kind: 'Fragment', 55 | metadata: { 56 | isAbstract: true 57 | }, 58 | name: 'Bar', 59 | type: 'Node' 60 | }; 61 | })(); 62 | -------------------------------------------------------------------------------- /src/container/generic/__tests__/GenericRelayRootContainer-test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @emails oncall+relay 10 | */ 11 | 12 | 'use strict'; 13 | 14 | 15 | const Relay = require('Relay'); 16 | const RelayRoute = require('RelayRoute'); 17 | const RelayStore = require('RelayStore'); 18 | 19 | describe('GenericRelayRootContainer', () => { 20 | var MockContainer; 21 | var mockRoute; 22 | 23 | beforeEach(() => { 24 | mockRoute = RelayRoute.genMockInstance(); 25 | 26 | MockContainer = Relay.createGenericContainer('MockComponent', { 27 | fragments: { 28 | foo: jest.genMockFunction().mockImplementation( 29 | () => Relay.QL`fragment on Node{id,name}` 30 | ), 31 | }, 32 | }); 33 | }); 34 | 35 | 36 | 37 | it('calls callback when data is available', () => { 38 | const updateCallback = jest.genMockFunction(); 39 | const rootContainer = new Relay.GenericRootContainer(updateCallback); 40 | 41 | rootContainer.update(MockContainer, mockRoute, false); 42 | expect(updateCallback).not.toBeCalled(); 43 | RelayStore.primeCache.mock.requests[0].resolve(); 44 | expect(updateCallback).toBeCalled(); 45 | }); 46 | 47 | }); 48 | -------------------------------------------------------------------------------- /src/traversal/writeRelayQueryPayload.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule writeRelayQueryPayload 10 | * @flow 11 | * @typechecks 12 | */ 13 | 14 | 'use strict'; 15 | 16 | const RelayNodeInterface = require('RelayNodeInterface'); 17 | const RelayProfiler = require('RelayProfiler'); 18 | import type RelayQuery from 'RelayQuery'; 19 | const RelayQueryPath = require('RelayQueryPath'); 20 | import type RelayQueryWriter from 'RelayQueryWriter'; 21 | import type {QueryPayload} from 'RelayInternalTypes'; 22 | 23 | /** 24 | * @internal 25 | * 26 | * Traverses a query and payload in parallel, writing the results into the 27 | * store. 28 | */ 29 | function writeRelayQueryPayload( 30 | writer: RelayQueryWriter, 31 | query: RelayQuery.Root, 32 | payload: QueryPayload 33 | ): void { 34 | const store = writer.getRecordStore(); 35 | const path = new RelayQueryPath(query); 36 | 37 | RelayNodeInterface.getResultsFromPayload(store, query, payload) 38 | .forEach(({dataID, result}) => { 39 | writer.writePayload(query, dataID, result, path); 40 | }); 41 | } 42 | 43 | module.exports = RelayProfiler.instrument( 44 | 'writeRelayQueryPayload', 45 | writeRelayQueryPayload 46 | ); 47 | -------------------------------------------------------------------------------- /src/query/__tests__/createRelayQuery-test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @emails oncall+relay 10 | */ 11 | 12 | 'use strict'; 13 | 14 | require('configureForRelayOSS'); 15 | 16 | const Relay = require('Relay'); 17 | const RelayQuery = require('RelayQuery'); 18 | const RelayTestUtils = require('RelayTestUtils'); 19 | 20 | const createRelayQuery = require('createRelayQuery'); 21 | 22 | describe('createRelayQuery', () => { 23 | beforeEach(() => { 24 | jest.resetModuleRegistry(); 25 | 26 | jasmine.addMatchers(RelayTestUtils.matchers); 27 | }); 28 | 29 | it('creates queries from GraphQL', () => { 30 | var root = createRelayQuery( 31 | Relay.QL` 32 | query { 33 | viewer { 34 | newsFeed(first: $count) { 35 | edges { 36 | node { 37 | id 38 | } 39 | } 40 | } 41 | } 42 | } 43 | `, 44 | { 45 | count: 10, 46 | } 47 | ); 48 | expect(root instanceof RelayQuery.Root).toBe(true); 49 | expect(root.getFieldByStorageKey('newsFeed').getCallsWithValues()).toEqual( 50 | [{name: 'first', value: 10}] 51 | ); 52 | }); 53 | }); 54 | -------------------------------------------------------------------------------- /src/store/__mocks__/RelayPendingQueryTracker.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | 'use strict'; 11 | 12 | var RelayPendingQueryTracker = 13 | jest.genMockFromModule('RelayPendingQueryTracker'); 14 | 15 | class MockPendingFetch { 16 | constructor(query) { 17 | this._query = query; 18 | this._resolvable = false; 19 | this._promise = new Promise((resolve, reject) => { 20 | this.resolve = (...args) => { 21 | this._resolvable = true; 22 | return resolve.apply(this, args); 23 | }; 24 | this.reject = reject; 25 | }); 26 | } 27 | getID() { 28 | return this._query.getQuery().getID(); 29 | } 30 | getQuery() { 31 | return this._query; 32 | } 33 | getResolvedPromise() { 34 | return this._promise; 35 | } 36 | isResolvable() { 37 | return this._resolvable; 38 | } 39 | } 40 | 41 | RelayPendingQueryTracker.mockImplementation(function() { 42 | this.add.mock.fetches = []; 43 | this.add.mockImplementation(params => { 44 | var mockFetch = new MockPendingFetch(params.query); 45 | this.add.mock.fetches.push(mockFetch); 46 | return mockFetch; 47 | }); 48 | 49 | return this; 50 | }); 51 | 52 | module.exports = RelayPendingQueryTracker; 53 | -------------------------------------------------------------------------------- /src/legacy/store/generateRQLFieldAlias.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @providesModule generateRQLFieldAlias 10 | * @typechecks 11 | */ 12 | 13 | 'use strict'; 14 | 15 | const base62 = require('base62'); 16 | const crc32 = require('crc32'); 17 | 18 | var PREFIX = '_'; 19 | 20 | /** 21 | * Sanitizes a stringified GraphQL field (including any calls and their values) 22 | * to produce a valid alias. 23 | * 24 | * This is used to auto-alias fields in generated queries, so that developers 25 | * composing multiple components together don't have to worry about collisions 26 | * between components requesting the same fields. (Explicit aliases are only 27 | * needed within a single component when it uses the same field multiple times, 28 | * in order to differentiate these fields in the props). 29 | * 30 | * @internal 31 | * 32 | * @param {string} input 33 | * @return {string} 34 | */ 35 | function generateRQLFieldAlias(input) { 36 | // Field names with no calls can be used as aliases without encoding 37 | var index = input.indexOf('.'); 38 | if (index === -1) { 39 | return input; 40 | } 41 | 42 | return PREFIX + input.substr(0, index) + base62(Math.abs(crc32(input))); 43 | } 44 | 45 | module.exports = generateRQLFieldAlias; 46 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/scripts/transform: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | /** 3 | * Copyright 2013-2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | */ 10 | 11 | const minimist = require('minimist'); 12 | const fs = require('fs'); 13 | const transformGraphQL = require('../lib/tools/transformGraphQL'); 14 | 15 | function main(argv) { 16 | if (!argv.schema) { 17 | console.warn('Usage: transform --file [file] --schema [schema]'); 18 | process.exit(1); 19 | } 20 | if (!fs.existsSync(argv.schema)) { 21 | console.warn('Invalid schema: %s', argv.schema); 22 | process.exit(1); 23 | } 24 | 25 | if (argv.file) { 26 | if (!fs.existsSync(argv.file)) { 27 | console.warn('Invalid file: %s', argv.file); 28 | process.exit(1); 29 | } 30 | transformSource(fs.readFileSync(argv.file, 'utf8'), argv.file); 31 | } else { 32 | var input = ''; 33 | process.stdin.resume(); 34 | process.stdin.setEncoding('utf8'); 35 | process.stdin.on('data', function(chunk) { 36 | input += chunk; 37 | }); 38 | process.stdin.on('end', function() { 39 | transformSource(input, 'stdin'); 40 | }); 41 | } 42 | 43 | function transformSource(source, name) { 44 | process.stdout.write(transformGraphQL(argv.schema, source, name)); 45 | } 46 | } 47 | 48 | main(minimist(process.argv)); 49 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/lib/tools/transformGraphQL.js: -------------------------------------------------------------------------------- 1 | // @generated 2 | /** 3 | * Copyright 2013-2015, Facebook, Inc. 4 | * All rights reserved. 5 | * 6 | * This source code is licensed under the BSD-style license found in the 7 | * LICENSE file in the root directory of this source tree. An additional grant 8 | * of patent rights can be found in the PATENTS file in the same directory. 9 | * 10 | * @fullSyntaxTransform 11 | */ 12 | 13 | 'use strict'; 14 | 15 | var babel = require('babel-core'); 16 | var fs = require('fs'); 17 | var util = require('util'); 18 | 19 | var getBabelRelayPlugin = require('../getBabelRelayPlugin'); 20 | 21 | var _schemas = {}; 22 | function getSchema(schemaPath) { 23 | try { 24 | var schema = _schemas[schemaPath]; 25 | if (!schema) { 26 | schema = JSON.parse(fs.readFileSync(schemaPath, 'utf8')).data; 27 | _schemas[schemaPath] = schema; 28 | } 29 | return schema; 30 | } catch (e) { 31 | throw new Error(util.format('transformGraphQL(): Failed to read schema path `%s`. Error: %s, %s', schemaPath, e.message, e.stack)); 32 | } 33 | } 34 | 35 | function transformGraphQL(schemaPath, source, filename) { 36 | var plugin = getBabelRelayPlugin(getSchema(schemaPath), { 37 | abortOnError: false, 38 | debug: true, 39 | substituteVariables: true, 40 | suppressWarnings: true 41 | }); 42 | return babel.transform(source, { 43 | compact: false, 44 | filename: filename, 45 | plugins: [plugin], 46 | blacklist: ['strict'] 47 | }).code; 48 | } 49 | 50 | module.exports = transformGraphQL; -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/metadataConnectionLimitable.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL` 4 | query { 5 | viewer { 6 | __configs__ { 7 | edges { 8 | node { 9 | name, 10 | }, 11 | }, 12 | }, 13 | }, 14 | } 15 | `; 16 | 17 | Output: 18 | var Relay = require('react-relay'); 19 | var x = (function () { 20 | return { 21 | children: [{ 22 | children: [{ 23 | children: [{ 24 | children: [{ 25 | fieldName: 'name', 26 | kind: 'Field', 27 | metadata: {}, 28 | type: 'String' 29 | }], 30 | fieldName: 'node', 31 | kind: 'Field', 32 | metadata: { 33 | isRequisite: true 34 | }, 35 | type: 'Config' 36 | }, { 37 | fieldName: 'cursor', 38 | kind: 'Field', 39 | metadata: { 40 | isGenerated: true, 41 | isRequisite: true 42 | }, 43 | type: 'String' 44 | }], 45 | fieldName: 'edges', 46 | kind: 'Field', 47 | metadata: { 48 | isPlural: true 49 | }, 50 | type: 'ConfigsConnectionEdge' 51 | }], 52 | fieldName: '__configs__', 53 | kind: 'Field', 54 | metadata: {}, 55 | type: 'ConfigsConnection' 56 | }], 57 | fieldName: 'viewer', 58 | kind: 'Query', 59 | metadata: {}, 60 | name: 'MetadataConnectionLimitable', 61 | type: 'Viewer' 62 | }; 63 | })(); 64 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "babel-relay-plugin", 3 | "version": "0.6.3", 4 | "description": "Babel Relay Plugin for transpiling GraphQL queries for use with Relay.", 5 | "license": "BSD-3-Clause", 6 | "repository": "facebook/relay", 7 | "main": "lib/getBabelRelayPlugin.js", 8 | "scripts": { 9 | "build": "scripts/build-lib", 10 | "prepublish": "npm run build", 11 | "test": "f() { EXIT=0; npm run typecheck || EXIT=$?; NODE_ENV=test jest $@ || EXIT=$?; exit $EXIT; }; f", 12 | "typecheck": "flow check src/", 13 | "update-schema": "babel-node ./src/tools/generateSchemaJson.js", 14 | "update-fixtures": "babel-node ./src/tools/regenerateFixtures.js" 15 | }, 16 | "files": [ 17 | "LICENSE", 18 | "PATENTS", 19 | "README.md", 20 | "lib/" 21 | ], 22 | "devDependencies": { 23 | "babel": "^5.8.23", 24 | "babel-core": "^5.8.25", 25 | "babel-jest": "^5.3.0", 26 | "flow-bin": "0.17.0", 27 | "glob": "^5.0.15", 28 | "jest-cli": "^0.8.1", 29 | "minimist": "^1.1.3", 30 | "mkdirp": "^0.5.1", 31 | "rimraf": "^2.1" 32 | }, 33 | "dependencies": { 34 | "graphql": "0.4.13" 35 | }, 36 | "jest": { 37 | "scriptPreprocessor": "/node_modules/babel-jest", 38 | "persistModuleRegistryBetweenSpecs": true, 39 | "preprocessorIgnorePatterns": [ 40 | "/node_modules/" 41 | ], 42 | "testRunner": "/node_modules/jest-cli/src/testRunners/jasmine/jasmine2.js", 43 | "unmockedModulePathPatterns": [ 44 | "/" 45 | ] 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /website/README.md: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | 3 | Install the supporting infrastructure. 4 | 5 | ``` 6 | (cd ../; npm install) && (cd ../scripts/babel-relay-plugin; npm install) && (cd ../website-prototyping-tools; npm install) && npm install 7 | ``` 8 | 9 | # Developing 10 | 11 | Launch a development server that you can use to preview edits. 12 | 13 | ``` 14 | npm start 15 | # Then open http://localhost:8080/relay/ 16 | ``` 17 | 18 | Anytime you change the contents, just refresh the page to rebuild the site. 19 | 20 | # Publish the website 21 | 22 | ## First time setup 23 | 24 | The publish script expects you to have two sibling folders named `relay` and `relay-gh-pages`. 25 | 26 | ``` 27 | # From relay/website/ 28 | ( 29 | cd ../../ 30 | git clone git@github.com:facebook/relay.git relay-gh-pages 31 | cd relay-gh-pages 32 | git checkout gh-pages 33 | ) 34 | ``` 35 | 36 | ## Building 37 | 38 | It's important that you run the server and hit the site at least once before you build. See ‘Developing,’ above. After that's done, build the website. 39 | 40 | ``` 41 | # From relay/website/ 42 | (cd ../; ./website/publish.sh) 43 | ``` 44 | 45 | ## Publishing 46 | 47 | The build system has now built the website into `relay-gh-pages`. All that's left to do is to check it over, commit it, and push it to `origin/gh-pages`. 48 | 49 | ``` 50 | cd ../../relay-gh-pages 51 | git status # Check it over to see if the changes look right 52 | git diff --word-diff=color # Or go over it in detail 53 | git add --all && git commit -m "Updating the website in preparation for v0.3.0" 54 | git push 55 | ``` 56 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/__fixtures__/mutation.fixture: -------------------------------------------------------------------------------- 1 | Input: 2 | var Relay = require('react-relay'); 3 | var x = Relay.QL` 4 | mutation { 5 | actorSubscribe(input: $input) { 6 | actor { 7 | profilePicture, 8 | }, 9 | }, 10 | } 11 | `; 12 | 13 | Output: 14 | var Relay = require('react-relay'); 15 | var x = (function () { 16 | return { 17 | calls: [{ 18 | kind: 'Call', 19 | metadata: {}, 20 | name: 'actorSubscribe', 21 | value: { 22 | kind: 'CallVariable', 23 | callVariableName: 'input' 24 | } 25 | }], 26 | children: [{ 27 | children: [{ 28 | fieldName: 'profilePicture', 29 | kind: 'Field', 30 | metadata: {}, 31 | type: 'ProfilePicture' 32 | }, { 33 | fieldName: 'id', 34 | kind: 'Field', 35 | metadata: { 36 | isGenerated: true, 37 | isRequisite: true 38 | }, 39 | type: 'String' 40 | }], 41 | fieldName: 'actor', 42 | kind: 'Field', 43 | metadata: { 44 | inferredRootCallName: 'node', 45 | inferredPrimaryKey: 'id' 46 | }, 47 | type: 'User' 48 | }, { 49 | fieldName: 'clientMutationId', 50 | kind: 'Field', 51 | metadata: { 52 | isGenerated: true, 53 | isRequisite: true 54 | }, 55 | type: 'String' 56 | }], 57 | kind: 'Mutation', 58 | metadata: { 59 | inputType: 'ActorSubscribeInput' 60 | }, 61 | name: 'Mutation', 62 | responseType: 'ActorSubscribeResponsePayload' 63 | }; 64 | })(); 65 | -------------------------------------------------------------------------------- /src/legacy/store/__tests__/generateRQLFieldAlias-test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @emails oncall+relay 10 | */ 11 | 12 | 'use strict'; 13 | 14 | const generateRQLFieldAlias = require('generateRQLFieldAlias'); 15 | 16 | var ALIAS_HEURISTIC = /^[\w-]+$/; 17 | 18 | function expectEncode(input) { 19 | var encoded = generateRQLFieldAlias(input); 20 | expect(ALIAS_HEURISTIC.test(encoded)).toBe(true); 21 | expect(encoded).not.toEqual(input); 22 | } 23 | 24 | describe('GraphQLFieldEncoder', () => { 25 | it('does not encode field names without calls', () => { 26 | expect(generateRQLFieldAlias('friends')).toEqual('friends'); 27 | }); 28 | 29 | it('encodes field names with calls', () => { 30 | expectEncode('friends.orderby(importance).first(10)'); 31 | }); 32 | 33 | it('encodes field names with call variables', () => { 34 | expectEncode('friends.first()'); 35 | }); 36 | 37 | it('encodes field names with weird characters in calls', () => { 38 | expectEncode('friends.orderby(= e1 \\ )'); 39 | }); 40 | 41 | it('returns the same hash for the same input', () => { 42 | var input = 'friends.orderby(importance).first(20)'; 43 | expectEncode(input); 44 | expect(generateRQLFieldAlias(input)) 45 | .toEqual(generateRQLFieldAlias(input)); 46 | }); 47 | }); 48 | -------------------------------------------------------------------------------- /scripts/babel-relay-plugin/src/tools/transformGraphQL.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | * @fullSyntaxTransform 10 | */ 11 | 12 | 'use strict'; 13 | 14 | var babel = require('babel-core'); 15 | var fs = require('fs'); 16 | var util = require('util'); 17 | 18 | var getBabelRelayPlugin = require('../getBabelRelayPlugin'); 19 | 20 | var _schemas = {}; 21 | function getSchema(schemaPath) { 22 | try { 23 | var schema = _schemas[schemaPath]; 24 | if (!schema) { 25 | schema = JSON.parse(fs.readFileSync(schemaPath, 'utf8')).data; 26 | _schemas[schemaPath] = schema; 27 | } 28 | return schema; 29 | } catch (e) { 30 | throw new Error(util.format( 31 | 'transformGraphQL(): Failed to read schema path `%s`. Error: %s, %s', 32 | schemaPath, 33 | e.message, 34 | e.stack 35 | )); 36 | } 37 | } 38 | 39 | function transformGraphQL(schemaPath, source, filename) { 40 | var plugin = getBabelRelayPlugin(getSchema(schemaPath), { 41 | abortOnError: false, 42 | debug: true, 43 | substituteVariables: true, 44 | suppressWarnings: true, 45 | }); 46 | return babel.transform(source, { 47 | compact: false, 48 | filename: filename, 49 | plugins: [plugin], 50 | blacklist: ['strict'], 51 | }).code; 52 | } 53 | 54 | module.exports = transformGraphQL; 55 | -------------------------------------------------------------------------------- /examples/todo/scripts/updateSchema.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env babel-node --optional es7.asyncFunctions 2 | /** 3 | * This file provided by Facebook is for non-commercial testing and evaluation 4 | * purposes only. Facebook reserves all rights not expressly granted. 5 | * 6 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 7 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 8 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 9 | * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 10 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 11 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 | */ 13 | 14 | import fs from 'fs'; 15 | import path from 'path'; 16 | import { schema } from '../data/schema'; 17 | import { graphql } from 'graphql'; 18 | import { introspectionQuery, printSchema } from 'graphql/utilities'; 19 | 20 | // Save JSON of full schema introspection for Babel Relay Plugin to use 21 | (async () => { 22 | var result = await (graphql(schema, introspectionQuery)); 23 | if (result.errors) { 24 | console.error( 25 | 'ERROR introspecting schema: ', 26 | JSON.stringify(result.errors, null, 2) 27 | ); 28 | } else { 29 | fs.writeFileSync( 30 | path.join(__dirname, '../data/schema.json'), 31 | JSON.stringify(result, null, 2) 32 | ); 33 | } 34 | })(); 35 | 36 | // Save user readable type system shorthand of schema 37 | fs.writeFileSync( 38 | path.join(__dirname, '../data/schema.graphql'), 39 | printSchema(schema) 40 | ); 41 | --------------------------------------------------------------------------------