Summary: `arguments` is a reserved word in JavaScript.
Reviewed By: yungsters
Differential Revision: D2888219
fb-gh-sync-id: 38ed92b3ef53efd6942186df99b5abdcc949fbf2
Summary: Changes the `babel-relay-plugin` build script to output a `lib/HASH` file that servers with caching (e.g. React Native) can use as a cache breaker (instead of having to check every file in the plugin). This is especially valuable when developing new plugin features because it enables testing without manually dirtying the package version number.
Reviewed By: josephsavona
Differential Revision: D2888573
fb-gh-sync-id: 1e0f4f3c4c24d9bf02e54c21cecf54ef8b780ea1
Summary:
I've sent a PR for this: https://github.com/facebook/relay/pull/781.
Not terrible important, just being obsessive compulsive.
I figure it's ok to change www as long as I change the open source version too.
Then next time they sync nothing will change.
Reviewed By: samwgoldman
Differential Revision: D2885711
fb-gh-sync-id: b32ed8defed55e233a92fe9e23804adbe3aac9e9
Summary: Bypasses certain Relay field validation rules for subfields of fragments having generated directive. The purpose is for Relay fragments that are generated from native fragments where native fragments are legal GraphQL but don't pass Relay's validation.
Reviewed By: josephsavona
Differential Revision: D2876082
fb-gh-sync-id: 0c7e5e659651535715862b122aab53d81cfd5bbd
Summary: This conflicts with our internal transform setup, we'll have to find another way to do this.
Reviewed By: yuzhi
Differential Revision: D2873773
fb-gh-sync-id: 30d1c25ec5cc4698bfaeb5a521cb15df33da1b47
Summary: Bypasses certain Relay field validation rules for subfields of fragments having generated directive. The purpose is for Relay fragments that are generated from native fragments where native fragments are legal GraphQL but don't pass Relay's validation.
Reviewed By: josephsavona
Differential Revision: D2868812
fb-gh-sync-id: ba786ea66973925a3269cfac25f82fa1979e2c5a
Summary: Adds support for `relay(isConnectionWithoutNodeID: true)`, which is a way for products using connections with `id`-less nodes to squelch the warning. (The net effect is that new fields will not be fetched for these nodes.)
Reviewed By: josephsavona
Differential Revision: D2726799
fb-gh-sync-id: 863eaf35155910243cf29655e100b52dfd7e070d
Summary:
For `RANGE_DELETE` mutations, the response payload may contain the node that is removed from the connection instead of only its ID. (Unlike for `NODE_DELETE`, it makes sense for a `RANGE_DELETE`'s response payload to contain a field for the removed node because the node has not been deleted.)
This changes `RANGE_DELETE`'s `deletedIDFieldName` configuration to support an array path to the field that contains the node removed from the connection.
Reviewed By: josephsavona
Differential Revision: D2864151
fb-gh-sync-id: 3b8105d49a69fbfb6d60fcf547f1ee84cdf6c127
Summary: Bypasses certain Relay field validation rules for subfields of fragments having generated directive. The purpose is for Relay fragments that are generated from native fragments where native fragments are legal GraphQL but don't pass Relay's validation.
Reviewed By: josephsavona
Differential Revision: D2868812
fb-gh-sync-id: be34b95a1e079efd5a0010e2eadfdf97996e7f23
Summary: Presently, we assume that childless fields are scalars. This diff adds `canHaveSubselections` metadata to printed queries. We can use this information to determine if a childless field is childless because it's a scalar, or simply because it has no subselections.
Reviewed By: yungsters
Differential Revision: D2863838
fb-gh-sync-id: a17f7f35118d952d754ad108512dbb79133df0ae
Summary: Previously, this test was testing against `taggable_activities` which is not in the test schema. I chose another suitable plural field: `all_timezones`.
Reviewed By: josephsavona
Differential Revision: D2859732
fb-gh-sync-id: 2f541b7157193b6ebf71a8dc6e9a1bc2ec8c29e8
Summary:
`babel-relay-plugin` depends transforms the “Relay.QL” TaggedTemplateExpression nodes in the source. If it does not run before the “es2015-template-literals” transform, it will not transform the Relay.QL template literals correctly.
This is important, because with Babel 6, you can’t control the plugin order. And so in a case like React Native, where plugins from React Native’s babelrc are loaded before the projects babelrc, it’s impossible to use the Babel Relay Plugin without overriding the entire transform list.
Note - I made this change in the babelAdapter, rather than in the plugin code itself, in order to retain Babel 5 compatibility.
Closes https://github.com/facebook/relay/pull/714
Reviewed By: yungsters
Differential Revision: D2862250
fb-gh-sync-id: 1c7342bda81b4dfbb7746ce1edee110ecd7b759b
Summary:
I've updated the GitHub version too, so next deploy will overwrite
this change with the correct version too.
Need to fix this to fix landcastle, which is freaking out since it doesn't have
a fbpkg for 0.17.0
Reviewed By: jeffmo, mroch
Differential Revision: D2851154
fb-gh-sync-id: 42c8bd98cf25af53cf5da1d094bb5bbdbbea5f8f
Summary: D2806143 removes callers of this `hash`. This cleans it up on the plugin side.
Reviewed By: steveluscher
Differential Revision: D2808537
fb-gh-sync-id: d5864ea91b82d2caf5159a01df49f329429ba141
Summary: Pulls `GraphQLRelayDirective` into a separate module so that it is easier to read, refer to, update, etc.
Reviewed By: steveluscher
Differential Revision: D2726177
fb-gh-sync-id: ef9da006b5121581f371e4913908497fa7c786e8
Summary:
There is currently a bug with the concrete fragment hashes generated by `babel-relay-plugin`.
Each fragment is supposed to have a unique hash, but the input to this hash is the entire string content of the `Relay.QL` template literal. This means that each fragment (including inline fragments) will have the same concrete fragment hash. This causes bugs like not correctly printing two inline fragments (which uses the concrete fragment hash as a memoization key).
This fixes the bug by generating a unique concrete fragment hash for each fragment in a `Relay.QL` expression.
Reviewed By: steveluscher
Differential Revision: D2799942
fb-gh-sync-id: ef34db199d1ee8533277fd2b585d6a2743f00ef0
Summary:
Fixes most of the `npm run lint` issues. There are two commits here: the first codemods the dangling comma, and the second one fixes a few other eslint issues. Take in full or in part, with or without attribution (as there are quite many lines changed!).
Closes https://github.com/facebook/relay/pull/661
Reviewed By: yungsters
Differential Revision: D2760109
fb-gh-sync-id: 740af9ae050d1c6ecff9d673af8ed07021f505eb
Summary:
The class transform is slightly different internally at facebook causing this
test to break either internally or open source. This adds a small hack to remove
the helper code from the transformed output.
Reviewed By: cpojer
Differential Revision: D2760436
fb-gh-sync-id: 565c8c3b4ba9fc7c406fecf8e8dcac0046be925e
Summary:
This is the big one. See D2728470 for an explanation.
I had to relax some checks because previously jasmine wouldn't check functions for equality (wtf!?).
I also patched jasmine not to be so strict about objects *for now*. The type of the object and undefined keys aren't being checked any more with this diff, same as in jasmine 1. Removing these patches results in about 800 test failures and I would like to clean this up later; this diff is already too big. I did start fixing these two failures in a lot of tests, so you'll see it in this diff, but then I gave up.
bypass-lint
Reviewed By: fabiomcosta
Differential Revision: D2728491
fb-gh-sync-id: ca956c96d59c6c644428f6c7ecf3802554b1acb6
Summary: We originally added logic to store or infer the `__typename` of records for data synchronization purposes. For that use case the type wasn't needed for client records. However, now that we're using it to make operations such as writing, diffing, etc faster (by pruning traversal of non-matching fragment types), we should store the type for all records.
Reviewed By: yungsters
Differential Revision: D2714539
fb-gh-sync-id: 8788a5813e42e737691095c99eee2509558cc46b
Summary: Simplifies the flattening/refragmenting of tracked queries and synthesized mutations, as well as addressing #596.
Changes:
- Change `RelayQueryTracker` to stop flattening tracked queries. Instead, the tracked children of a node are simply concatenated.
- Change `RelayMutationQuery` to stop refragmenting mutation fragments now that the tracked nodes aren't flattened.
- Change `RelayMutationQuery#buildFragmentForEdgeInsertion` to find any matching descendant tracked child, instead of assuming that tracked nodes are flattened and that fields are all top-level.
- Now that we never refragment, remove `RelayQueryField#getParentType` and accompanying metadata from babel-relay-plugin.
- Change `flattenRelayQuery` to retain fragments where necessary, instead flattening nested nodes of the same type. This necessitates storing the type of root and field nodes (added in `babel-relay-plugin`).
- Changed the interface to `RelayQueryField.build` to accept a single object to make it easier to pass just `fieldName` and `type`, and updated all callers to specify a type.
Closes https://github.com/facebook/relay/pull/627
Reviewed By: yungsters
Differential Revision: D2687452
fb-gh-sync-id: 171db358e582658f679fc1048435c2fccfe182f2
Summary: The `babel-relay-plugin` is supposed to work on older versions of node, so we should not use `Array#find`. (There is already a local polyfill.)
Reviewed By: josephsavona
Differential Revision: D2701846
fb-gh-sync-id: 1d3c45c8c4e6db57a1dd23a517fb1edde2113e1e
Summary: `RelayQueryWriter` no longer writes the results of unmatched fragments. However, `diffRelayQuery` still attempts to diff fragments that don't match the known type. The logic is:
- when diffing, we shouldn't look at fragments whose types don't match
- but we can't *remove* those fragments, because if we end up refetching the node, it might be a different record whose type could match that fragment
- so we should treat non-matching fragments as requisite fields and only keep them if the node would otherwise be refetched
Closes https://github.com/facebook/relay/pull/632
Reviewed By: yungsters
Differential Revision: D2698189
fb-gh-sync-id: 87a6e604bed622d49eb06f537b350246ca300beb
Summary: The Relay runtime (and `relay-graphql-js` specification) expects that the input argument name to mutations (and subscriptions) be `input`, so we should always output `input`.
Reviewed By: josephsavona
Differential Revision: D2686258
fb-gh-sync-id: bcdd09bbd8c07e4e0cbc3ce858ccb3ffb80a895b
Summary: Adds support for configuring the `babel-relay-plugin` for use with the legacy version of GraphQL. (The goal of this project is to switch Facebook onto the same version of GraphQL as the open sourced.)
This adds the ability to configure:
- Name of the mutation input argument.
- Whether generated fields should use `camelCase` or `snake_case`.
This also changes the custom validator inteface so that `graphql` is an injected dependency. This allows the validator to use the identical instance of `graphql` that `babel-relay-plugin` uses (and not another instance of it, which causes problems with `instanceof` checks among other things).
Reviewed By: josephsavona
Differential Revision: D2684161
fb-gh-sync-id: c974538c90baa13c151d2aba5f73568b4a6acb14
Summary: The plugin currently only adds an `id` field if the type *always* implements `Node`. This changes the behavior to add `... on Node { id }` whenever a field/fragment *may* implement `Node`.
// Schema
type Node {
id: String
}
interface Actor {
name: String
}
type User implements Node Actor {
id: String
name: String
}
type Page implements Actor {
name: String
}
// Input
fragment on Actor {
name
}
// Effective Output
fragment on Actor {
name
... on Node { id, __typename }
}
Reviewed By: yungsters
Differential Revision: D2684119
fb-gh-sync-id: c365819b270331184d86958f00508557e57fe6a6
Summary: The only runtime dependency of `babel-relay-plugin` is now `graphql` (can move `babel-core` to a dev dependency).
Reviewed By: yungsters
Differential Revision: D2683393
fb-gh-sync-id: b47afe6489a93c0e391133f0fcab0c17eb96e50d
Summary: Support passing a custom validation function to `babel-relay-plugin` via options.
Reviewed By: yungsters
Differential Revision: D2683127
fb-gh-sync-id: d3e4de78eabaddb07d0d29d26623e2e699a3b1ab
Summary: Adds support for compiling `subscription { ... }` documents to `babel-relay-plugin`. These are represented almost identicallly to mutations.
Reviewed By: yungsters
Differential Revision: D2682956
fb-gh-sync-id: e7cc8289cc8628bff3dd0868a4fa333d7afdd8f5
Summary: graphql/language/schema was merged with graphql/language in graphql-js v0.4.3.
Also fixed needed `npm run update-schema` in root by adding `babel` as a devDependecy, which provides `node_modules/.bin/babel-node` executable. The changes in `babel-relay-plugin/lib/RelayQLAST.js` are perhaps due to differing babel helper versions. This version is built using a clean install.
Closes https://github.com/facebook/relay/pull/622
Reviewed By: yungsters
Differential Revision: D2682649
fb-gh-sync-id: 7c57ad610740977fd3efd6717461249cab66839c
Summary: Adds a compatibility layer to `babel-relay-plugin` to work in both babel 5 and 6.
Reviewed By: steveluscher
Differential Revision: D2680806
fb-gh-sync-id: 3ca0b1133a6593093f68f2d8177885453477f147
Summary: `RelayQueryWriter` currently traverses *all* fragments when processing a payload and attempts to write their fields, regardless of whether the result type and fragment type actually match. For fields with an abstract/union type, we should instead only follow fragments whose type matches the actual result type - this can have a significant effect on performance, especially in cases where the top-level query has a union with a high branching factor.
For example, the previous writer would traverse both fragments A & B in the below example. With these changes, only fragment A is traversed (the type of the record).
```
// query
fragment on Type {
id
__typename
... on A { ... }
... on B { ... }
}
// response
{
id: "...",
__typename: "A"
...
}
```
This necessitated the following other changes:
- Changes `RelayQueryPath` to record fragments along the path, so that they can be correctly followed/skipped on refetch.
- Changes `RelayStoreData.buildFragmentQueryForDataID` to no longer refragment queries created for `setVariables`. This preserves fragments better and is also faster (avoids another full tree traversal).
- Adds `isConcrete` metadata to fragments of a concrete type; abstract fragments must always be traversed (skipping them would require understanding the full inheritance tree of the schema which isn't worth it). The default for runtime generated fragments is to assume they are an abstract type, which ensures that only known-safe fragments will be skipped.
Closes https://github.com/facebook/relay/pull/571
Reviewed By: yungsters
Differential Revision: D2631911
fb-gh-sync-id: 1ee19e2b8138290731cb4e8582c14f1abb53b919
Summary: Adds configurable support in `babel-relay-plugin` for transforming variable substitution. For example:
const SIZE = 32;
Relay.QL`
node(id: ${userID}) {
id
}
`;
It can be enabled by passing in `substituteVariables: true` as the second argument to `getBabelRelayPlugin()`. If not enabled, at least this will now serve a better error message (instead of a GraphQL parse error with invalid "...").
Reviewed By: josephsavona
Differential Revision: D2661746
fb-gh-sync-id: 5516aa07c5f6465a6dbc8136886ecff1608b73a8
Summary: Creates a hash for each static fragment. This can be used to cheaply communicate query and fragment identities (especially across client/server/native) without serializing an entire tree.
Reviewed By: josephsavona
Differential Revision: D2642620
fb-gh-sync-id: cdb58947179ca496cdce5ee6e3c0bcea56bb9fda
Summary: Need to include 12139c8 for the release.
Closes https://github.com/facebook/relay/pull/583
Reviewed By: yungsters
Differential Revision: D2642919
fb-gh-sync-id: f51f061bd40eadae8d25c3b2292278d972592a06
Summary: Returns true when the root field wraps a `GraphQLList`
Reviewed By: josephsavona
Differential Revision: D2635462
fb-gh-sync-id: 40b4dfa162db1fcbf86672ff4cdbf0652372b582