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

Allow configurable @defer/@stream names #4467

Closed
wants to merge 2 commits into from

Conversation

robrichard
Copy link
Contributor

This is not an attempt to get Relay to conform to the current defer/stream spec draft, but rather just a small step in that direction by allowing configurable directive & argument names.

Currently Relay requires the argument initial_count on @stream, but the GraphQL spec uses camelCase for all names.

This PR updates Relay compiler to follow the same pattern used by ConnectionInterface, introducing DeferStreamInterface to allow configuring the names and arguments of the defer & stream directive.

The first commit adds the configuration updating all touch points to reference the configuration.

The second commit changes the defaults to camelCase, to match the defaults used in ConnectionInterface. This makes the diff substantially larger as many tests and fixtures need to be updated. I'm happy to remove this commit from this PR if desired.

@facebook-github-bot
Copy link
Contributor

@captbaritone has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@captbaritone
Copy link
Contributor

Looks like the "CI / Compiler output check" CI step is failing. Can update https://github.com/facebook/relay/blob/main/scripts/config.tests.json to opt back into the old names?

@robrichard robrichard force-pushed the initialCount branch 3 times, most recently from 6fffd63 to 9be04c8 Compare October 9, 2023 14:24
@robrichard
Copy link
Contributor Author

@captbaritone all checks are passing now. It was failing because relay-extensions.graphql is statically added to schemas to add the @stream_connection directive.

I updated connection_constants to decouple the @stream_connection argument names from the @stream argument names. So with these updates @stream_connection will always use the current snake_case names, but they will be transformed to the @defer and @stream argument names passed in through the config.

@facebook-github-bot
Copy link
Contributor

@captbaritone has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@captbaritone has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@captbaritone
Copy link
Contributor

@robrichard Can you add a followup PR (I'll try to merge this one as is) to make the panics in this file into diagnostics?

panic!("Unexpected argument to @defer: {}", arg.name.item);
}
}
Self { if_arg, label_arg }
}
}
/// Utility to access the arguments of the @stream directive.
pub struct StreamDirective<'a> {
pub if_arg: Option<&'a Argument>,
pub label_arg: Option<&'a Argument>,
pub initial_count_arg: Option<&'a Argument>,
pub use_customized_batch_arg: Option<&'a Argument>,
}
impl<'a> StreamDirective<'a> {
/// Extracts the arguments from the given directive assumed to be a @stream
/// directive.
/// Panics on any unexpected arguments.
pub fn from(directive: &'a Directive) -> Self {
let mut if_arg = None;
let mut label_arg = None;
let mut initial_count_arg = None;
let mut use_customized_batch_arg = None;
for arg in &directive.arguments {
if arg.name.item == DEFER_STREAM_CONSTANTS.if_arg {
if_arg = Some(arg);
} else if arg.name.item == DEFER_STREAM_CONSTANTS.label_arg {
label_arg = Some(arg);
} else if arg.name.item == DEFER_STREAM_CONSTANTS.initial_count_arg {
initial_count_arg = Some(arg);
} else if arg.name.item == DEFER_STREAM_CONSTANTS.use_customized_batch_arg {
use_customized_batch_arg = Some(arg);
} else {
panic!("Unexpected argument to @stream: {}", arg.name.item);

These can now happen as a result of not specifying the the right config for your schema and no user error should result in a panic from the compiler.

@facebook-github-bot
Copy link
Contributor

@captbaritone merged this pull request in 58da806.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants