Skip to content

Conversation

@bbakerman
Copy link
Member

@bbakerman bbakerman commented Feb 27, 2022

I wanted to spike whether we can transition to passing "state" to each instrumentation method call rather than creating an object.

I think this works really well and is NON API breaking.

If we did this I think we would

  • deprecated the old methods that only take a "parameter with state" object
  • deprecater the getState on the parameter objects
  • create side line default methods for each instrumentation method so it takes state but it calls back like these do
  • go through the provided graphql-java instrumentations and make them only use the new methods

…passing in state to the instrumentation fields
@bbakerman bbakerman added the Not to be merged spikes or other stuff that should never or not yet to be merged label Feb 27, 2022
public InstrumentationContext<ExecutionResult> beginField(InstrumentationFieldParameters parameters, InstrumentationState state) {
return new ChainedInstrumentationContext<>(map(instrumentations, it -> it.beginField(parameters, state)));
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note I still need to create a wrapper ChainedInstrumentationContext object per call

The alternative is

        ImmutableList<InstrumentationContext<Object>> contexts = map(instrumentations, it -> it.beginFieldFetch(parameters, getState(it, state)));
        return new InstrumentationContext<Object>() {
            @Override
            public void onDispatched(CompletableFuture<Object> result) {
                contexts.forEach(ctx -> ctx.onDispatched(result));
            }

            @Override
            public void onCompleted(Object result, Throwable t) {
                contexts.forEach(ctx -> ctx.onCompleted(result,t));
            }
        };

and this is an object allocation anyway - since we MUST call back when the result is dispatched and most importantly when its finished

@bbakerman
Copy link
Member Author

BTW this is failing some instrumentation tests because they assert that the tested methods have not been updated

    InstrumentationContext<ExecutionResult> beginField(InstrumentationFieldParameters parameters) {
        assert parameters.getInstrumentationState() == instrumentationState
        return new TestingInstrumentContext("field-$parameters.field.name", executionList, throwableList, useOnDispatch)
    }

This needs t be fixed up if we went with these I think. I need to look more in to this

@bbakerman
Copy link
Member Author

Done in another PR

@bbakerman bbakerman closed this Apr 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Not to be merged spikes or other stuff that should never or not yet to be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants