Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental support for @semanticNonNull #4601

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fragment TestFragment on User
alias: None,
definition: WithLocation {
location: argument_definitions.graphql:161:171,
item: FieldID(518),
item: FieldID(523),
},
arguments: [],
directives: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ fragment F2 on Query @argumentDefinitions(
alias: None,
definition: WithLocation {
location: fragment_with_arguments_defaulting.graphql:342:352,
item: FieldID(518),
item: FieldID(523),
},
arguments: [],
directives: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ fragment Foo on Users {
id
}
==================================== ERROR ====================================
✖︎ Unknown type 'Users'. Did you mean `User` or `Query`?
✖︎ Unknown type 'Users'. Did you mean `User`, `Opera`, or `Query`?

unknown-fragment-type-suggestions.invalid.graphql:2:17
1 │ # expected-to-throw
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ type Foo {
alias: None,
definition: WithLocation {
location: client-fields.graphql:226:238,
item: FieldID(518),
item: FieldID(523),
},
arguments: [],
directives: [],
Expand Down Expand Up @@ -228,7 +228,7 @@ type Foo {
alias: None,
definition: WithLocation {
location: client-fields.graphql:367:370,
item: FieldID(519),
item: FieldID(524),
},
arguments: [],
directives: [],
Expand All @@ -245,15 +245,15 @@ type Foo {
},
InlineFragment {
type_condition: Some(
Object(79),
Object(81),
),
directives: [],
selections: [
ScalarField {
alias: None,
definition: WithLocation {
location: client-fields.graphql:470:472,
item: FieldID(520),
item: FieldID(525),
},
arguments: [],
directives: [],
Expand All @@ -279,14 +279,14 @@ type Foo {
},
variable_definitions: [],
used_global_variables: [],
type_condition: Object(79),
type_condition: Object(81),
directives: [],
selections: [
ScalarField {
alias: None,
definition: WithLocation {
location: client-fields.graphql:526:528,
item: FieldID(520),
item: FieldID(525),
},
arguments: [],
directives: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ extend type Query {
alias: None,
definition: WithLocation {
location: custom_scalar_directive_arg_variable.graphql:100:115,
item: FieldID(519),
item: FieldID(524),
},
arguments: [],
directives: [
Expand Down Expand Up @@ -104,7 +104,7 @@ extend type Query {
alias: None,
definition: WithLocation {
location: custom_scalar_directive_arg_variable.graphql:160:170,
item: FieldID(521),
item: FieldID(526),
},
arguments: [],
directives: [],
Expand All @@ -115,7 +115,7 @@ extend type Query {
alias: None,
definition: WithLocation {
location: custom_scalar_directive_arg_variable.graphql:181:203,
item: FieldID(520),
item: FieldID(525),
},
arguments: [],
directives: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extend type Query {
alias: None,
definition: WithLocation {
location: custom_scalar_variable_arg.graphql:100:115,
item: FieldID(519),
item: FieldID(524),
},
arguments: [
Argument {
Expand Down Expand Up @@ -91,7 +91,7 @@ extend type Query {
alias: None,
definition: WithLocation {
location: custom_scalar_variable_arg.graphql:151:161,
item: FieldID(521),
item: FieldID(526),
},
arguments: [],
directives: [],
Expand All @@ -102,7 +102,7 @@ extend type Query {
alias: None,
definition: WithLocation {
location: custom_scalar_variable_arg.graphql:172:194,
item: FieldID(520),
item: FieldID(525),
},
arguments: [
Argument {
Expand Down
13 changes: 13 additions & 0 deletions compiler/crates/relay-config/src/typegen_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ pub struct TypegenConfig {
/// of an union with the raw type, null and undefined.
#[serde(default)]
pub typescript_exclude_undefined_from_nullable_union: bool,

/// EXPERIMENTAL: If your environment is configured to handles errors out of band, either via
/// a network layer which discards responses with errors, or via enabling strict
/// error handling in the runtime, you can enable this flag to have Relay generate
/// non-null types for fields which are marked as semantically non-null in
/// the schema.
///
/// Currently semantically non-null fields must be specified in your schema
/// using the `@semanticNonNull` directive as specified in:
/// https://github.com/apollographql/specs/pull/42
#[serde(default)]
pub experimental_emit_semantic_nullability_types: bool,
}

impl Default for TypegenConfig {
Expand All @@ -125,6 +137,7 @@ impl Default for TypegenConfig {
no_future_proof_enums: Default::default(),
eager_es_modules: Default::default(),
typescript_exclude_undefined_from_nullable_union: Default::default(),
experimental_emit_semantic_nullability_types: Default::default(),
}
}
}
14 changes: 14 additions & 0 deletions compiler/crates/relay-test-schema/src/testschema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1191,3 +1191,17 @@ type Settings {
type WithWrongViewer {
actor_key: Viewer
}

extend type Query {
opera: Opera
}

type Opera {
composer: User @semanticNonNull
cast: [Portrayal] @semanticNonNull(levels: [0, 1])
}

type Portrayal {
singer: User @semanticNonNull
character: String @semanticNonNull
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fragment Foo_user on User {
{
...BestFriendResolverFragment_name @__RelayResolverMetadata
# RelayResolverMetadata {
# field_id: FieldID(518),
# field_id: FieldID(523),
# import_path: "BestFriendResolver",
# import_name: None,
# field_alias: None,
Expand All @@ -65,7 +65,7 @@ fragment Foo_user on User {
{
...BestFriendResolverFragment_name @__RelayResolverMetadata
# RelayResolverMetadata {
# field_id: FieldID(518),
# field_id: FieldID(523),
# import_path: "BestFriendResolver",
# import_name: None,
# field_alias: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fragment Foo_node on Node {
{
...BestFriendResolverFragment_name @__RelayResolverMetadata
# RelayResolverMetadata {
# field_id: FieldID(518),
# field_id: FieldID(523),
# import_path: "BestFriendResolver",
# import_name: None,
# field_alias: None,
Expand Down Expand Up @@ -72,7 +72,7 @@ fragment Foo_node on Node {
{
...BestFriendResolverFragment_name @__RelayResolverMetadata
# RelayResolverMetadata {
# field_id: FieldID(518),
# field_id: FieldID(523),
# import_path: "BestFriendResolver",
# import_name: None,
# field_alias: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fragment Foo_user on User {
{
...BestFriendResolverFragment_name @__RelayResolverMetadata
# RelayResolverMetadata {
# field_id: FieldID(520),
# field_id: FieldID(525),
# import_path: "BestFriendResolver",
# import_name: None,
# field_alias: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fragment Foo_user on User {
{
...BestFriendResolverFragment_name @__RelayResolverMetadata
# RelayResolverMetadata {
# field_id: FieldID(519),
# field_id: FieldID(524),
# import_path: "BestFriendResolver",
# import_name: None,
# field_alias: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fragment Foo_user on User {
{
...BestFriendResolverFragment_name @__RelayResolverMetadata
# RelayResolverMetadata {
# field_id: FieldID(518),
# field_id: FieldID(523),
# import_path: "BestFriendResolver",
# import_name: None,
# field_alias: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fragment Foo_user on User {
{
...BestFriendResolverFragment_name @__RelayResolverMetadata
# RelayResolverMetadata {
# field_id: FieldID(518),
# field_id: FieldID(523),
# import_path: "BestFriendResolver",
# import_name: None,
# field_alias: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fragment Foo_user on User {
{
...BestFriendResolverFragment_name @__RelayResolverMetadata
# RelayResolverMetadata {
# field_id: FieldID(518),
# field_id: FieldID(523),
# import_path: "BestFriendResolver",
# import_name: None,
# field_alias: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fragment Foo_user on User {
{
...BestFriendResolverFragment_name @__RelayResolverMetadata
# RelayResolverMetadata {
# field_id: FieldID(518),
# field_id: FieldID(523),
# import_path: "BestFriendResolver",
# import_name: None,
# field_alias: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fragment Foo_user on User {
{
...BestFriendResolverFragment_name @__RelayResolverMetadata
# RelayResolverMetadata {
# field_id: FieldID(518),
# field_id: FieldID(523),
# import_path: "BestFriendResolver",
# import_name: None,
# field_alias: None,
Expand All @@ -57,7 +57,7 @@ fragment Foo_user on User {
{
...BestFriendResolverFragment_name @__RelayResolverMetadata
# RelayResolverMetadata {
# field_id: FieldID(518),
# field_id: FieldID(523),
# import_path: "BestFriendResolver",
# import_name: None,
# field_alias: None,
Expand Down Expand Up @@ -115,7 +115,7 @@ fragment RefetchableClientEdgeQuery_Foo_user_best_friend on User @__ClientEdgeGe
{
...BestFriendResolverFragment_name @__RelayResolverMetadata
# RelayResolverMetadata {
# field_id: FieldID(518),
# field_id: FieldID(523),
# import_path: "BestFriendResolver",
# import_name: None,
# field_alias: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fragment Foo_user on User {
{
...BestFriendResolverFragment_name @__RelayResolverMetadata
# RelayResolverMetadata {
# field_id: FieldID(518),
# field_id: FieldID(523),
# import_path: "BestFriendResolver",
# import_name: None,
# field_alias: None,
Expand All @@ -54,7 +54,7 @@ fragment Foo_user on User {
{
...BestFriendResolverFragment_name @__RelayResolverMetadata
# RelayResolverMetadata {
# field_id: FieldID(518),
# field_id: FieldID(523),
# import_path: "BestFriendResolver",
# import_name: None,
# field_alias: None,
Expand Down Expand Up @@ -110,7 +110,7 @@ fragment RefetchableClientEdgeQuery_Foo_user_best_friend on User @__ClientEdgeGe
{
...BestFriendResolverFragment_name @__RelayResolverMetadata
# RelayResolverMetadata {
# field_id: FieldID(518),
# field_id: FieldID(523),
# import_path: "BestFriendResolver",
# import_name: None,
# field_alias: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fragment Foo_user on ClientUser {
{
...BestFriendFragment @__RelayResolverMetadata
# RelayResolverMetadata {
# field_id: FieldID(519),
# field_id: FieldID(524),
# import_path: "BestFriendResolver",
# import_name: None,
# field_alias: Some(
Expand Down Expand Up @@ -74,7 +74,7 @@ fragment Foo_user on ClientUser {
{
...BestFriendFragment @__RelayResolverMetadata
# RelayResolverMetadata {
# field_id: FieldID(519),
# field_id: FieldID(524),
# import_path: "BestFriendResolver",
# import_name: None,
# field_alias: Some(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fragment Foo_user on ClientUser {
{
...BestFriendFragment @__RelayResolverMetadata
# RelayResolverMetadata {
# field_id: FieldID(519),
# field_id: FieldID(524),
# import_path: "BestFriendResolver",
# import_name: None,
# field_alias: None,
Expand All @@ -72,7 +72,7 @@ fragment Foo_user on ClientUser {
{
...BestFriendFragment @__RelayResolverMetadata
# RelayResolverMetadata {
# field_id: FieldID(519),
# field_id: FieldID(524),
# import_path: "BestFriendResolver",
# import_name: None,
# field_alias: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fragment Foo_user on User {
{
...BestFriendResolverFragment_name @__RelayResolverMetadata
# RelayResolverMetadata {
# field_id: FieldID(519),
# field_id: FieldID(524),
# import_path: "BestFriendResolver",
# import_name: None,
# field_alias: None,
Expand All @@ -48,7 +48,7 @@ fragment Foo_user on User {
# live: false,
# output_type_info: Composite(
# ResolverNormalizationInfo {
# inner_type: Object(79),
# inner_type: Object(81),
# plural: false,
# normalization_operation: WithLocation {
# location: <generated>:59:70,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extend type User {
fragment Foo_user on User {
...PopStarNameResolverFragment_name @__RelayResolverMetadata
# RelayResolverMetadata {
# field_id: FieldID(518),
# field_id: FieldID(523),
# import_path: "PopStarNameResolver",
# import_name: None,
# field_alias: Some(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extend type User {
fragment Foo_user on User {
__id @__RelayResolverMetadata
# RelayResolverMetadata {
# field_id: FieldID(518),
# field_id: FieldID(523),
# import_path: "PopStarNameResolver",
# import_name: None,
# field_alias: None,
Expand Down
Loading
Loading