Skip to content

Commit

Permalink
graphql tags no longer produce implicit objects
Browse files Browse the repository at this point in the history
Summary:
This changes the babel plugin to no longer produce an implicit object in some cases.

Previously, if a `graphql` tag was not somewhere in an object literal in the parent path, it would produce an object with the name of the fragment after the first `_` (defaulting to `data`) as the key. If these rules sound complicated and confusing to you, you're probably not alone. That's why we're removing this case and simplifying the transform.

Reviewed By: josephsavona, jstejada

Differential Revision: D14247660

fbshipit-source-id: b2567dc7879ed85e560fce595d160d5eacef305d
  • Loading branch information
kassens authored and facebook-github-bot committed Mar 1, 2019
1 parent 92514aa commit 1f26086
Show file tree
Hide file tree
Showing 32 changed files with 300 additions and 1,223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -522,32 +522,6 @@ module.exports = RelayCompatContainer.createContainer(CompatProfilePic, {
});
`;
exports[`matches expected output: error_confusing-fragment-name.txt 1`] = `
~~~~~~~~~~ INPUT ~~~~~~~~~~
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
*/
'use strict';
const RelayCompatContainer = require('RelayCompatContainer');
const graphql = require('graphql');
const CompatProfile = () => null;
module.exports = RelayCompatContainer.createContainer(CompatProfile, graphql\`
fragment CompatProfile_data on User {
name
}
\`);
~~~~~~~~~~ OUTPUT ~~~~~~~~~~
ERROR:
Error: BabelPluginGraphQL: Fragment \`CompatProfile_data\` should not end in \`_data\` to avoid conflict with a fragment named \`CompatProfile\` which also provides resulting data via the React prop \`data\`. Either rename this fragment to \`CompatProfile\` or choose a different prop name.
`;
exports[`matches expected output: error_too-many-fragments.txt 1`] = `
~~~~~~~~~~ INPUT ~~~~~~~~~~
/**
Expand Down Expand Up @@ -663,11 +637,13 @@ class RefetchExample extends React.Component {
module.exports = createRefetchContainer(
RefetchExample,
graphql\`
fragment RefetchExample_user on User {
name
}
\`,
{
user: graphql\`
fragment RefetchExample_user on User {
name
}
\`
},
graphql\`
query RefetchExampleRefetchQuery {
viewer {
Expand Down Expand Up @@ -1455,77 +1431,6 @@ module.exports = RelayCompatContainer.createContainer(CompatProfile, {
});
`;
exports[`matches expected output: no-object.txt 1`] = `
~~~~~~~~~~ INPUT ~~~~~~~~~~
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
*/
'use strict';
const RelayCompatContainer = require('RelayCompatContainer');
const graphql = require('graphql');
const CompatProfile = () => null;
module.exports = RelayCompatContainer.createContainer(CompatProfile, graphql\`
fragment CompatProfile_user on User {
name
}
\`);
~~~~~~~~~~ OUTPUT ~~~~~~~~~~
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
*/
'use strict';
const RelayCompatContainer = require('RelayCompatContainer');
const graphql = require('graphql');
const CompatProfile = () => null;
module.exports = RelayCompatContainer.createContainer(CompatProfile, {
user: {
modern: function () {
return require("CompatProfile_user.graphql");
},
classic: function (RelayQL_GENERATED) {
return {
kind: "FragmentDefinition",
argumentDefinitions: [],
node: function () {
return {
children: [{
fieldName: "name",
kind: "Field",
metadata: {},
type: "String"
}, {
fieldName: "id",
kind: "Field",
metadata: {
isGenerated: true,
isRequisite: true
},
type: "ID"
}],
id: RelayQL_GENERATED.__id(),
kind: "Fragment",
metadata: {},
name: "CompatProfile_user",
type: "User"
};
}()
};
}
}
});
`;
exports[`matches expected output: query.txt 1`] = `
~~~~~~~~~~ INPUT ~~~~~~~~~~
/**
Expand Down Expand Up @@ -1644,79 +1549,6 @@ const CompatViewerQuery = {
};
`;
exports[`matches expected output: simple-named-fragment.txt 1`] = `
~~~~~~~~~~ INPUT ~~~~~~~~~~
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
*/
'use strict';
const RelayCompatContainer = require('RelayCompatContainer');
const graphql = require('graphql');
const CompatProfile = () => null;
module.exports = RelayCompatContainer.createContainer(CompatProfile, graphql\`
fragment CompatProfile on User {
name
...SomeOtherContainer
}
\`);
~~~~~~~~~~ OUTPUT ~~~~~~~~~~
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
*/
'use strict';
const RelayCompatContainer = require('RelayCompatContainer');
const graphql = require('graphql');
const CompatProfile = () => null;
module.exports = RelayCompatContainer.createContainer(CompatProfile, {
data: {
modern: function () {
return require("CompatProfile.graphql");
},
classic: function (RelayQL_GENERATED) {
const SomeOtherContainer = SomeOtherContainer.getFragment("data");
return {
kind: "FragmentDefinition",
argumentDefinitions: [],
node: function () {
return {
children: [].concat.apply([], [{
fieldName: "name",
kind: "Field",
metadata: {},
type: "String"
}, {
fieldName: "id",
kind: "Field",
metadata: {
isGenerated: true,
isRequisite: true
},
type: "ID"
}, RelayQL_GENERATED.__frag(SomeOtherContainer)]),
id: RelayQL_GENERATED.__id(),
kind: "Fragment",
metadata: {},
name: "CompatProfile",
type: "User"
};
}()
};
}
}
});
`;
exports[`matches expected output: within-class-reference.txt 1`] = `
~~~~~~~~~~ INPUT ~~~~~~~~~~
/**
Expand All @@ -1733,9 +1565,9 @@ const CompatProfilePic = require('CompatProfilePic');
class CompatProfile extends React.Component {
render() {
return <div>
<CompatProfilePic user={this.props.data} />
{this.props.data.name}
{this.props.data.subscribeStatus}
<CompatProfilePic user={this.props.actor} />
{this.props.actor.name}
{this.props.actor.subscribeStatus}
</div>;
}
Expand All @@ -1756,13 +1588,15 @@ class CompatProfile extends React.Component {
}
}
module.exports = createFragmentContainer(CompatProfile, graphql\`
fragment CompatProfile on Actor {
name
subscribeStatus
...CompatProfilePic_user
}
\`);
module.exports = createFragmentContainer(CompatProfile, {
actor: graphql\`
fragment CompatProfile_actor on Actor {
name
subscribeStatus
...CompatProfilePic_user
}
\`,
});
~~~~~~~~~~ OUTPUT ~~~~~~~~~~
/**
Expand All @@ -1785,9 +1619,9 @@ const CompatProfilePic = require('CompatProfilePic');
class CompatProfile extends React.Component {
render() {
return <div>
<CompatProfilePic user={this.props.data} />
{this.props.data.name}
{this.props.data.subscribeStatus}
<CompatProfilePic user={this.props.actor} />
{this.props.actor.name}
{this.props.actor.subscribeStatus}
</div>;
}
Expand Down Expand Up @@ -1874,9 +1708,9 @@ class CompatProfile extends React.Component {
}
module.exports = createFragmentContainer(CompatProfile, {
data: {
actor: {
modern: function () {
return require("CompatProfile.graphql");
return require("CompatProfile_actor.graphql");
},
classic: function (RelayQL_GENERATED) {
const CompatProfilePic_user = CompatProfilePic.getFragment("user");
Expand Down Expand Up @@ -1917,7 +1751,7 @@ module.exports = createFragmentContainer(CompatProfile, {
metadata: {
isAbstract: true
},
name: "CompatProfile",
name: "CompatProfile_actor",
type: "Actor"
};
}()
Expand Down
Loading

0 comments on commit 1f26086

Please sign in to comment.