-
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.
Show a helpful error if a resolver returns an interface with no imple…
…mentors (#4428) Summary: **Context:** Without this we generate a broken Flow type. We will eventually support Relay Resolvers that return interfaces. Today they are not permitted in the common case. However, once we do allow them, we must ensure that the schema includes at least once concrete type that implements that interface. Without that property, we will generate invalid Flow types. **This change** Adds additional validation for implementors of client-defined interfaces if they are being used as a return type for RelayResolvers and tests. Also updates an existing test to have it only test the existing validation for blocking interfaces as a return type. Pull Request resolved: #4428 Test Plan: `./scripts/update-fixtures.sh` `cargo test` specifically: `cargo test -p relay-transforms --test client_edges_test` `cargo test -p relay-compiler --test relay_compiler_compile_relay_artifacts_test relay_resolver_edge_to_interface_with_no_implementors` `cargo test -p relay-compiler --test relay_compiler_compile_relay_artifacts_test relay_resolver_edge_to_interface_with_child_interface_and_no_implementors` Reviewed By: captbaritone Differential Revision: D48852264 Pulled By: monicatang fbshipit-source-id: 5d9ebbee4423eef8f1aaf4dd031e3e3227675f19
- Loading branch information
1 parent
a3fbc12
commit 5d22d1c
Showing
10 changed files
with
167 additions
and
6 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...xtures/relay-resolver-edge-to-interface-with-child-interface-and-no-implementors.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,43 @@ | ||
==================================== INPUT ==================================== | ||
# expected-to-throw | ||
query relayResolverEdgeToInterfaceWithChildInterfaceAndNoImplementorsQuery { | ||
resolver_field { | ||
name | ||
} | ||
} | ||
|
||
# %extensions% | ||
|
||
""" | ||
An interface with no concrete implementors | ||
""" | ||
interface SomeInterface { | ||
name: String | ||
} | ||
|
||
interface ChildInterface implements SomeInterface { | ||
name: String | ||
age: Int | ||
} | ||
|
||
extend type Query { | ||
resolver_field: SomeInterface | ||
@relay_resolver(import_path: "./path/to/Resolver.js") | ||
} | ||
==================================== ERROR ==================================== | ||
✖︎ Client Edges that reference client-defined interface types are not currently supported in Relay. | ||
|
||
relay-resolver-edge-to-interface-with-child-interface-and-no-implementors.graphql:3:3 | ||
2 │ query relayResolverEdgeToInterfaceWithChildInterfaceAndNoImplementorsQuery { | ||
3 │ resolver_field { | ||
│ ^^^^^^^^^^^^^^ | ||
4 │ name | ||
|
||
|
||
✖︎ No types implement the client interface SomeInterface. Interfaces returned by a @RelayResolver must have at least one concrete implementation. | ||
|
||
<generated>:2:44 | ||
1 │ # expected-to-throw | ||
2 │ query relayResolverEdgeToInterfaceWithChildInterfaceAndNoImplementorsQuery { | ||
│ ^^^^^^^^^^^^^ | ||
3 │ resolver_field { |
25 changes: 25 additions & 0 deletions
25
...ixtures/relay-resolver-edge-to-interface-with-child-interface-and-no-implementors.graphql
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,25 @@ | ||
# expected-to-throw | ||
query relayResolverEdgeToInterfaceWithChildInterfaceAndNoImplementorsQuery { | ||
resolver_field { | ||
name | ||
} | ||
} | ||
|
||
# %extensions% | ||
|
||
""" | ||
An interface with no concrete implementors | ||
""" | ||
interface SomeInterface { | ||
name: String | ||
} | ||
|
||
interface ChildInterface implements SomeInterface { | ||
name: String | ||
age: Int | ||
} | ||
|
||
extend type Query { | ||
resolver_field: SomeInterface | ||
@relay_resolver(import_path: "./path/to/Resolver.js") | ||
} |
38 changes: 38 additions & 0 deletions
38
...e_relay_artifacts/fixtures/relay-resolver-edge-to-interface-with-no-implementors.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,38 @@ | ||
==================================== INPUT ==================================== | ||
# expected-to-throw | ||
query relayResolverEdgeToInterfaceWithNoImplementorsQuery { | ||
resolver_field { | ||
name | ||
} | ||
} | ||
|
||
# %extensions% | ||
|
||
""" | ||
An interface with no implementors | ||
""" | ||
interface SomeInterface { | ||
name: String | ||
} | ||
|
||
extend type Query { | ||
resolver_field: SomeInterface | ||
@relay_resolver(import_path: "./path/to/Resolver.js") | ||
} | ||
==================================== ERROR ==================================== | ||
✖︎ Client Edges that reference client-defined interface types are not currently supported in Relay. | ||
|
||
relay-resolver-edge-to-interface-with-no-implementors.graphql:3:3 | ||
2 │ query relayResolverEdgeToInterfaceWithNoImplementorsQuery { | ||
3 │ resolver_field { | ||
│ ^^^^^^^^^^^^^^ | ||
4 │ name | ||
|
||
|
||
✖︎ No types implement the client interface SomeInterface. Interfaces returned by a @RelayResolver must have at least one concrete implementation. | ||
|
||
<generated>:2:35 | ||
1 │ # expected-to-throw | ||
2 │ query relayResolverEdgeToInterfaceWithNoImplementorsQuery { | ||
│ ^^^^^^^^^^^^^ | ||
3 │ resolver_field { |
20 changes: 20 additions & 0 deletions
20
...le_relay_artifacts/fixtures/relay-resolver-edge-to-interface-with-no-implementors.graphql
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,20 @@ | ||
# expected-to-throw | ||
query relayResolverEdgeToInterfaceWithNoImplementorsQuery { | ||
resolver_field { | ||
name | ||
} | ||
} | ||
|
||
# %extensions% | ||
|
||
""" | ||
An interface with no implementors | ||
""" | ||
interface SomeInterface { | ||
name: String | ||
} | ||
|
||
extend type Query { | ||
resolver_field: SomeInterface | ||
@relay_resolver(import_path: "./path/to/Resolver.js") | ||
} |
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