Skip to content

Conversation

@felipe-gdr
Copy link
Member

@felipe-gdr felipe-gdr commented Jan 29, 2024

Add support for @defer in the GraphQL execution.

Note: this implementation is still experimental.

This implementation is based on the state of graphql/graphql-spec#742. More specifically at the state of this commit graphql/graphql-spec@c630301.

The execution behaviour should match what we get from running Apollo Server 4.9.5 with graphql-js v17.0.0-alpha.2

In this already merged PR, we added support for @defer in Executable Normalized Fields: #3395

This reverts commit 0025495.
Revert "Merge pull request graphql-java#1964 from graphql-java/remove-deferred-2"

This reverts commit a0d327d, reversing
changes made to 3101f48.

Revert "Merge pull request graphql-java#1961 from graphql-java/remove-deferred-support"

This reverts commit 3101f48, reversing
changes made to 10eeacc.
* Will result on 1 instance of `DeferredCall`, containing calls for the 2 fields: "text" and "summary".
*/
@Internal
public class DeferredCall implements IncrementalCall<DeferPayload> {
Copy link
Member

Choose a reason for hiding this comment

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

Naming is hard but this (ans the ENF version) should be some other name

  • DeferredBlockCall
  • DeferredFragmentCall
  • DeferredFragmentInvocation

@dondonz dondonz added this to the 2024 April: breaking changes milestone Feb 11, 2024
}

private void collectFragmentSpread(FieldCollectorParameters parameters, Set<String> visitedFragments, Map<String, MergedField> fields, FragmentSpread fragmentSpread) {
private void collectFragmentSpread(FieldCollectorParameters parameters, Set<String> visitedFragments, Map<String, MergedField> fields, FragmentSpread fragmentSpread, boolean incrementalSupport) {
Copy link
Member

Choose a reason for hiding this comment

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

maybe we dont need the incrementalSupport FF here - eg always do it BUT then never used it elsewhere ?

Copy link
Contributor

@felipe-gdr-atlassian felipe-gdr-atlassian Feb 12, 2024

Choose a reason for hiding this comment

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

I think the less new code we execute the better. So I'm with the opinion that we can keep this behind the FF as well

static {
incrementalSupport = false
}
}
Copy link
Member

Choose a reason for hiding this comment

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

nice

*/
@ExperimentalApi
public static final String ENABLE_INCREMENTAL_SUPPORT = "ENABLE_INCREMENTAL_SUPPORT";

Copy link
Member

Choose a reason for hiding this comment

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

I think we should love this anotehr class - yes the mechanism is this - but the static should be elsewhere

One thought is this

public @interface ExperimentalApi {
    String ENABLE_INCREMENTAL_SUPPORT  = "ENABLE_INCREMENTAL_SUPPORT";
}

which then allows

GraphQLContext.newContext().put(ExperimentalApi.ENABLE_INCREMENTAL_SUPPORT,true);

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense 👍 I'm making the change

public void enqueue(Collection<IncrementalCall<? extends IncrementalPayload>> calls) {
if (!calls.isEmpty()) {
calls.forEach(this::enqueue);
}
Copy link
Member

Choose a reason for hiding this comment

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

why !calls.isEmpty())

is this just and allAll kinda thing ??

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right, there's no need for this empty check. Let me remove it.

path: ["post"],
data: [summary: "A summary"]
]
]
Copy link
Member

Choose a reason for hiding this comment

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

sghould we check for a label as null or missing ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yep, good call. Let me add one 👍

The spec doesn't explicitly mentions what the behaviour should be in the scenario when label: null.

It clearly states that the value must be a static string (i.e: it can't be passed as a variable).

So we have 2 options here:
1- we treat queries that have label: null as invalid - we can write a new validation rule for that. This kind of makes sense. Since the value has to be static, there's no reason for query owners to set label: null, ever. They should just omit that argument altogether.
2- we treat queries that have label: null the same way we do for @defers that don't have a label at all
I honestly think it doesn't matter that much at this point, so I'll go with option 2, simply because it's the easier to implement (we don't need to write a new validation rule)

@@ -0,0 +1,1371 @@
package graphql.execution.incremental
Copy link
Member

Choose a reason for hiding this comment

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

I like this test a lot - great testing

Copy link
Contributor

Choose a reason for hiding this comment

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

🙇

@bbakerman bbakerman self-requested a review February 12, 2024 02:49
Copy link
Member

@bbakerman bbakerman left a comment

Choose a reason for hiding this comment

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

Feb 12

I am happy to give this a tick but I want the FF to be moved to its own class - bit GraphqlContext

So either ExperimentalApi as suggested OR some where like that

@andimarek andimarek added this pull request to the merge queue Feb 13, 2024
Merged via the queue into graphql-java:master with commit 1a12660 Feb 13, 2024
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

Successfully merging this pull request may close these issues.

5 participants