Skip to content

Commit

Permalink
DissalowIDAsAlias on nested fields
Browse files Browse the repository at this point in the history
Reviewed By: kassens

Differential Revision: D18816334

fbshipit-source-id: e08ae96ae53bc5ea4edceba09303bd07c4725e3d
  • Loading branch information
alunyov authored and facebook-github-bot committed Dec 4, 2019
1 parent 7ab9612 commit c4547f9
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9473,6 +9473,41 @@ Fragment {
}
`;
exports[`compileRelayArtifacts matches expected output: id-as-alias.invalid.graphql 1`] = `
~~~~~~~~~~ INPUT ~~~~~~~~~~
# expected-to-throw
fragment User_fragment on User {
id: name
}
fragment ProfilePicture on User {
profilePicture(size: $size) {
id: uri
}
}
~~~~~~~~~~ OUTPUT ~~~~~~~~~~
THROWN EXCEPTION:
Encountered 2 errors:
- Relay does not allow aliasing fields to \`id\`. This name is reserved for the globally unique \`id\` field on \`Node\`.
Source: GraphQL request (3:3)
2: fragment User_fragment on User {
3: id: name
^
4: }
- Relay does not allow aliasing fields to \`id\`. This name is reserved for the globally unique \`id\` field on \`Node\`.
Source: GraphQL request (8:5)
7: profilePicture(size: $size) {
8: id: uri
^
9: }
`;
exports[`compileRelayArtifacts matches expected output: inline-and-mask-are-incompatible.invalid.graphql 1`] = `
~~~~~~~~~~ INPUT ~~~~~~~~~~
# expected-to-throw
Expand Down Expand Up @@ -9896,26 +9931,6 @@ Source: GraphQL request (17:24)
`;
exports[`compileRelayArtifacts matches expected output: is-as-alias.invalid.graphql 1`] = `
~~~~~~~~~~ INPUT ~~~~~~~~~~
# expected-to-throw
fragment User_fragment on User {
id: name
}
~~~~~~~~~~ OUTPUT ~~~~~~~~~~
THROWN EXCEPTION:
Relay does not allow aliasing fields to \`id\`. This name is reserved for the globally unique \`id\` field on \`Node\`.
Source: GraphQL request (3:3)
2: fragment User_fragment on User {
3: id: name
^
4: }
`;
exports[`compileRelayArtifacts matches expected output: kitchen-sink.graphql 1`] = `
~~~~~~~~~~ INPUT ~~~~~~~~~~
query NodeQuery($id: ID!, $cond: Boolean!, $PictureSize: [Int]!) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# expected-to-throw
fragment User_fragment on User {
id: name
}

fragment ProfilePicture on User {
profilePicture(size: $size) {
id: uri
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion packages/relay-compiler/transforms/DisallowIdAsAlias.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function visitField<T: ScalarField | LinkedField>(field: T): T {
[field.loc],
);
}
return field;
return this.traverse(field);
}

/**
Expand Down

0 comments on commit c4547f9

Please sign in to comment.