-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add validations for mutation resolvers
Reviewed By: alunyov Differential Revision: D50993473 fbshipit-source-id: bc0804753f8668a83f06dff00c259e22620a353b
- Loading branch information
1 parent
ef84550
commit 904924c
Showing
17 changed files
with
598 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
192 changes: 192 additions & 0 deletions
192
...lay_compiler_integration/fixtures/client_mutation_resolver_different_mutation_ok.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
==================================== INPUT ==================================== | ||
//- foo.js | ||
/** | ||
* @RelayResolver Mutation.foo_mutation: Person | ||
*/ | ||
|
||
/** | ||
* @RelayResolver NotCalledMutation.baz_mutation: Boolean | ||
*/ | ||
|
||
//- bar.js | ||
graphql`mutation barMutation { | ||
baz_mutation | ||
}` | ||
|
||
//- relay.config.json | ||
{ | ||
"language": "flow", | ||
"schema": "./schema.graphql", | ||
"eagerEsModules": true, | ||
"featureFlags": { | ||
"enable_relay_resolver_transform": true, | ||
"enable_relay_resolver_mutations": true | ||
}, | ||
"schemaExtensions": [ | ||
"./extensions.graphql" | ||
] | ||
} | ||
|
||
//- schema.graphql | ||
|
||
type Mutation | ||
|
||
type NotCalledMutation | ||
|
||
type Query | ||
|
||
schema { | ||
query: Query, | ||
mutation: NotCalledMutation, | ||
} | ||
|
||
//- extensions.graphql | ||
|
||
type Person { | ||
name: String! | ||
age: Int! | ||
} | ||
==================================== OUTPUT =================================== | ||
//- __generated__/Mutation__foo_mutation$normalization.graphql.js | ||
/** | ||
* <auto-generated> SignedSource<<87fb321a30684890a8b77e1bdb2cf79a>> | ||
* @flow | ||
* @lightSyntaxTransform | ||
* @nogrep | ||
*/ | ||
|
||
/* eslint-disable */ | ||
|
||
'use strict'; | ||
|
||
/*:: | ||
import type { NormalizationSplitOperation } from 'relay-runtime'; | ||
|
||
export type Mutation__foo_mutation$normalization = {| | ||
+age: number, | ||
+name: string, | ||
|}; | ||
|
||
*/ | ||
|
||
var node/*: NormalizationSplitOperation*/ = { | ||
"kind": "SplitOperation", | ||
"metadata": {}, | ||
"name": "Mutation__foo_mutation$normalization", | ||
"selections": [ | ||
{ | ||
"kind": "ClientExtension", | ||
"selections": [ | ||
{ | ||
"alias": null, | ||
"args": null, | ||
"kind": "ScalarField", | ||
"name": "name", | ||
"storageKey": null | ||
}, | ||
{ | ||
"alias": null, | ||
"args": null, | ||
"kind": "ScalarField", | ||
"name": "age", | ||
"storageKey": null | ||
} | ||
] | ||
} | ||
] | ||
}; | ||
|
||
export default node; | ||
|
||
//- __generated__/barMutation.graphql.js | ||
/** | ||
* <auto-generated> SignedSource<<6f79ca8d7718498c480388c5b22a5130>> | ||
* @flow | ||
* @lightSyntaxTransform | ||
* @nogrep | ||
*/ | ||
|
||
/* eslint-disable */ | ||
|
||
'use strict'; | ||
|
||
/*:: | ||
import type { ClientRequest, Mutation } from 'relay-runtime'; | ||
import {baz_mutation as notCalledMutationBazMutationResolverType} from "../foo.js"; | ||
// Type assertion validating that `notCalledMutationBazMutationResolverType` resolver is correctly implemented. | ||
// A type error here indicates that the type signature of the resolver module is incorrect. | ||
(notCalledMutationBazMutationResolverType: () => ?boolean); | ||
export type barMutation$variables = {||}; | ||
export type barMutation$data = {| | ||
+baz_mutation: ?boolean, | ||
|}; | ||
export type barMutation = {| | ||
response: barMutation$data, | ||
variables: barMutation$variables, | ||
|}; | ||
*/ | ||
|
||
import {baz_mutation as notCalledMutationBazMutationResolver} from './../foo'; | ||
|
||
var node/*: ClientRequest*/ = { | ||
"fragment": { | ||
"argumentDefinitions": [], | ||
"kind": "Fragment", | ||
"metadata": null, | ||
"name": "barMutation", | ||
"selections": [ | ||
{ | ||
"kind": "ClientExtension", | ||
"selections": [ | ||
{ | ||
"alias": null, | ||
"args": null, | ||
"fragment": null, | ||
"kind": "RelayResolver", | ||
"name": "baz_mutation", | ||
"resolverModule": notCalledMutationBazMutationResolver, | ||
"path": "baz_mutation" | ||
} | ||
] | ||
} | ||
], | ||
"type": "NotCalledMutation", | ||
"abstractKey": null | ||
}, | ||
"kind": "Request", | ||
"operation": { | ||
"argumentDefinitions": [], | ||
"kind": "Operation", | ||
"name": "barMutation", | ||
"selections": [ | ||
{ | ||
"kind": "ClientExtension", | ||
"selections": [ | ||
{ | ||
"name": "baz_mutation", | ||
"args": null, | ||
"fragment": null, | ||
"kind": "RelayResolver", | ||
"storageKey": null, | ||
"isOutputType": true | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"params": { | ||
"cacheID": "b7409af7b3a13247f776ad3f9192c84b", | ||
"id": null, | ||
"metadata": {}, | ||
"name": "barMutation", | ||
"operationKind": "mutation", | ||
"text": null | ||
} | ||
}; | ||
|
||
(node/*: any*/).hash = "bbe24bc0c4cab0597abfafef11f07b88"; | ||
|
||
export default ((node/*: any*/)/*: Mutation< | ||
barMutation$variables, | ||
barMutation$data, | ||
>*/); |
47 changes: 47 additions & 0 deletions
47
.../relay_compiler_integration/fixtures/client_mutation_resolver_different_mutation_ok.input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//- foo.js | ||
/** | ||
* @RelayResolver Mutation.foo_mutation: Person | ||
*/ | ||
|
||
/** | ||
* @RelayResolver NotCalledMutation.baz_mutation: Boolean | ||
*/ | ||
|
||
//- bar.js | ||
graphql`mutation barMutation { | ||
baz_mutation | ||
}` | ||
|
||
//- relay.config.json | ||
{ | ||
"language": "flow", | ||
"schema": "./schema.graphql", | ||
"eagerEsModules": true, | ||
"featureFlags": { | ||
"enable_relay_resolver_transform": true, | ||
"enable_relay_resolver_mutations": true | ||
}, | ||
"schemaExtensions": [ | ||
"./extensions.graphql" | ||
] | ||
} | ||
|
||
//- schema.graphql | ||
|
||
type Mutation | ||
|
||
type NotCalledMutation | ||
|
||
type Query | ||
|
||
schema { | ||
query: Query, | ||
mutation: NotCalledMutation, | ||
} | ||
|
||
//- extensions.graphql | ||
|
||
type Person { | ||
name: String! | ||
age: Int! | ||
} |
33 changes: 33 additions & 0 deletions
33
...ts/relay_compiler_integration/fixtures/client_mutation_resolver_invalid_disabled.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
==================================== INPUT ==================================== | ||
//- foo.js | ||
/** | ||
* @RelayResolver Mutation.foo_mutation: Boolean | ||
*/ | ||
|
||
//- bar.js | ||
graphql`mutation barMutation { | ||
foo_mutation | ||
}` | ||
|
||
//- relay.config.json | ||
{ | ||
"language": "flow", | ||
"schema": "./schema.graphql", | ||
"eagerEsModules": true, | ||
"featureFlags": { | ||
"enable_relay_resolver_transform": true | ||
} | ||
} | ||
|
||
//- schema.graphql | ||
|
||
type Mutation | ||
==================================== OUTPUT =================================== | ||
✖︎ Resolvers on the mutation type Mutation are disallowed without the enable_relay_resolver_mutations feature flag | ||
|
||
foo.js:1:3 | ||
1 │ * | ||
│ ^ | ||
2 │ * @RelayResolver Mutation.foo_mutation: Boolean | ||
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
3 │ |
23 changes: 23 additions & 0 deletions
23
...tests/relay_compiler_integration/fixtures/client_mutation_resolver_invalid_disabled.input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//- foo.js | ||
/** | ||
* @RelayResolver Mutation.foo_mutation: Boolean | ||
*/ | ||
|
||
//- bar.js | ||
graphql`mutation barMutation { | ||
foo_mutation | ||
}` | ||
|
||
//- relay.config.json | ||
{ | ||
"language": "flow", | ||
"schema": "./schema.graphql", | ||
"eagerEsModules": true, | ||
"featureFlags": { | ||
"enable_relay_resolver_transform": true | ||
} | ||
} | ||
|
||
//- schema.graphql | ||
|
||
type Mutation |
Oops, something went wrong.