Skip to content

relay-compiler: default feature flags are not added when missing featureFlags in config #5063

@ansemb

Description

@ansemb

Problem

Default feature flags are not added when featureFlags is not set; every feature flag is false.

With the recent release of v19:
https://relay.dev/blog/2025/04/02/relay-19/#alias-required-on-conditional-fragments

The enforce_fragment_alias_where_ambiguous feature flag has been set to true by default.

However, for a relay.config without featureFlags e.g.:

{
  //...
  "projects": {
    "test": {
      "customScalarTypes": {},
      "enumModuleSuffix": ".test",
      "schema": "packages/relay-test-utils-internal/testschema.graphql",
      "language": "javascript"
    }
  }
}

The default flags are not set, meaning enforce_fragment_alias_where_ambiguous is false.

Adding an empty featureFlags enables the default flags:

{
  //...
  "projects": {
    "test": {
      //...
      "featureFlags": {},            <---------------- adding this enables default flags
    }
  }
}

yields the same as:

{
  //...
  "projects": {
    "test": {
      //...
      "featureFlags": {
        "enforce_fragment_alias_where_ambiguous": {
          "kind": "enabled"
        }
      }
    }
  }
}

Repro on this branch:
https://github.com/ansemb/relay/blob/user/ansemb/feature-flag-repro

by adding an @include:
https://github.com/ansemb/relay/blob/user/ansemb/feature-flag-repro/compiler/test-project/src/App.js#L14

Toggling this line with featureFlags give different results:
https://github.com/ansemb/relay/blob/user/ansemb/feature-flag-repro/compiler/test-project/relay.config.json#L17

with the following (expected) error, when enforce_fragment_alias_where_ambiguous is enabled:

❯ ../target/release/relay compiler                                                               (base)
[INFO] Querying files to compile...
[INFO] [test] compiling...
[ERROR] Error in the project `test`: ✖ Expected `@alias` directive. Fragment spreads with (or within an inline fragment with) `@include` are conditionally fetched. Add `@alias` to this spread to expose the fragment reference as a nullable property.

  compiler/test-project/src/App.js:14:10
   13 │       ...Component_node
   14 │       ...User_dataFragment @include(if: $includeUserBody)
      │          ^^^^^^^^^^^^^^^^^
   15 │     }

  ℹ The condition is defined here:

  compiler/test-project/src/App.js:14:28
   13 │       ...Component_node
   14 │       ...User_dataFragment @include(if: $includeUserBody)
      │                            ^^^^^^^^
   15 │     }

[ERROR] Compilation failed.
[ERROR] Unable to run relay compiler. Error details:
Failed to build:
 - Validation errors: 1 error(s) encountered above.

Expectation

The below configs should yield the same result.

No featureFlags:

{
  //...
  "projects": {
    "test": {
      "customScalarTypes": {},
      "enumModuleSuffix": ".test",
      "schema": "packages/relay-test-utils-internal/testschema.graphql",
      "language": "javascript"
    }
  }
}

Empty featureFlags:

{
  //...
  "projects": {
    "test": {
      "customScalarTypes": {},
      "enumModuleSuffix": ".test",
      "schema": "packages/relay-test-utils-internal/testschema.graphql",
      "featureFlags": {},
      "language": "javascript",
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions