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

relay-compiler - @stream argument naming does not follow spec: initialCount vs initial_count ? #3619

Closed
damikun opened this issue Oct 30, 2021 · 7 comments

Comments

@damikun
Copy link

damikun commented Oct 30, 2021

Current compiler (not rust experimental) require for @stream argument naming as @stream(initial_count:value) but gql-specification define this as initialCount...

If i go over sources relay specialy check for nitial_count naming :

arg => arg.name === 'initial_count',

If GraphQL server follow schema specification (initialCount) it is not possible to compile with error:

- Invalid use of @stream, the 'initial_count' argument is required. ...

Schema specification for @defer and @stream:

https://graphql.org/blog/2020-12-08-improving-latency-with-defer-and-stream-directives/
or
https://github.com/graphql/graphql-spec/pull/742/files

Compiler should follow schema specification or don't check this and use type from schema definition...

Versions:
"relay-compiler": "12.0.0",

@damikun damikun changed the title relay-compiler - @stream what is argument naming initialCount or initial_count ? relay-compiler - @stream what is argument naming does not follow spec: initialCount vs initial_count ? Oct 30, 2021
@damikun damikun changed the title relay-compiler - @stream what is argument naming does not follow spec: initialCount vs initial_count ? relay-compiler - @stream argument naming does not follow spec: initialCount vs initial_count ? Oct 30, 2021
@alunyov
Copy link
Contributor

alunyov commented Nov 2, 2021

Thanks for the report!

Current compiler (not rust experimental)

Our overall plan is to deprecate the current JS compiler: #3180. So all our current efforts are focused on that, and we're not planning on adding/fixing issues in the JS version.

@alunyov alunyov closed this as completed Nov 2, 2021
@damikun
Copy link
Author

damikun commented Nov 2, 2021

@alunyov Are you sure that rust one has not equal problem ?

I can see usage of initial_count (not spec arg. naming) in sources for Rust compiler... (it is equal problem) Please validate that before closing this issue.. I did not test compilation with rust but I can see maybe it has equal issue after quick look on Rust sources.. If you can validate my opinion it can be fine :)

The problem is most of servers fully follow GraphQL spec with it is not possible to compile.... because compiler use different arg. naming as specification and throw always error...

This is from rust sources

initial_count_arg: "initial_count".intern(),

if let Some(initial_count_arg) = initial_count_arg {

Can be find directly in tests
https://github.com/facebook/relay/blob/86842c141eb59b31269893f224bf24375a2b3539/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-missing-initial-count-arg.invalid.expected

@josephsavona
Copy link
Contributor

Yeah, our implementation is based on Facebook's internal implementation of stream and defer upon which the official GraphQL spec version was based. However the spec made some changes such as renaming some fields. We have an outstanding task to update to support the OSS spec in addition to our internal version.

@damikun
Copy link
Author

damikun commented Nov 3, 2021

Heh ok understand that... Good thanks, that server I'm using able me to override core framework types so i can use it.. Because this is usually hardcoded on both sides..

@damikun
Copy link
Author

damikun commented Nov 3, 2021

@maraisr Nice to see also this workeround... I'm currently doing this on server since HC enable to write TypeInterceptor. But yes thats server specific workeround..

public class StreamTypeInterceptor : TypeInterceptor{

        #nullable enable
        public override void OnBeforeCompleteType(
        ITypeCompletionContext completionContext,
        DefinitionBase? definition,
        IDictionary<string, object?> contextData)
        {
        #nullable disable

            if(definition is DirectiveTypeDefinition directiveTypeDefinition 
            && directiveTypeDefinition?.RuntimeType == typeof(StreamDirective)){
                                
                var InitCountArg = directiveTypeDefinition.Arguments
                    .First(e=>e.Property?.Name == "InitialCount");

                if(InitCountArg != null){
                    InitCountArg.Name = "initial_count";
                }
            }
        }
    }

(+) You need the Document rewrite middleware (iterate and rewrite stream SintaxNodes in tree) since HC use some hardcoded constant.. So TypeInterceptor only adapt schema but not execution stuff..

https://github.com/damikun/trouble-training/blob/main/Src/APIServer/Aplication/Graphql/Extensions/StreamTypeInterceptor.cs

https://github.com/damikun/trouble-training/blob/main/Src/APIServer/API/Configuration/StreamRenameMiddelware.cs

@maraisr
Copy link
Contributor

maraisr commented Nov 3, 2021

Ya just a rename and all is well. 🚀

Hope this lands in OSS under similar flags as the other things do.

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

No branches or pull requests

4 participants