Skip to content

Conversation

@bbakerman
Copy link
Member

@bbakerman bbakerman commented Jul 29, 2023

This PR provides @oneOf support to graphql-java

related to #3266

This is now complete.

The error messages here are inspired by the graphql-js versions.

I chose to add isOneOf into our pre built Introspection queries by default and have an option to turn it off if it causes problems (I dont see how it would be just in case)

I am a fan of the directive based approach of this mechanism

This code is considered experimental namely because the spec has not been accepted. The PR has been put into the reference implementation graphql-js however so its not pie in the sky stuff

true,
false,
true,
true,
Copy link
Member Author

Choose a reason for hiding this comment

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

on by default in new versions

Copy link
Member Author

Choose a reason for hiding this comment

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

but some one could turn it off if need be

public static VariableReference of(String name) {
return newVariableReference().name(name).build();
}

Copy link
Member Author

Choose a reason for hiding this comment

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

just a better helper to make one - like StringValue.of()

]) | CoercedVariables.of([var: "abc"]) | [arg: [a: "abc"]]

}

Copy link
Member Author

Choose a reason for hiding this comment

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

most of the tests are here - these are taken from the examples given in the spec update plus some they missed

er.errors[0].message == "Exception while fetching data (/f) : OneOf type field 'OneOf.a' must be non-null."

// lots more covered in unit tests
}
Copy link
Member Author

Choose a reason for hiding this comment

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

some end 2 end testing behind the unit tested we have for ValueResolver

throw new OneOfNullValueException(msg);
}
}

Copy link
Member Author

Choose a reason for hiding this comment

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

remember we can have a mix of input - literals and maps and invalid input might be a with a variable with no map entries or multiple.

The unit tests for this explore these different conditions

}
// eventually GraphQLDirective as applied directive goes away
return directives.stream().anyMatch(d -> Directives.OneOfDirective.getName().equals(d.getName()));
}
Copy link
Member Author

Choose a reason for hiding this comment

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

The boolean is calculated on creation and hence fast from that time forward

}
if (additionalDirectives.stream().noneMatch(d -> d.getName().equals(Directives.OneOfDirective.getName()))) {
additionalDirectives.add(Directives.OneOfDirective);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

always available like deprecated and specifiedby

@bbakerman bbakerman changed the title WIP - oneOf directive support oneOf directive support Aug 1, 2023
@bbakerman bbakerman requested a review from dondonz August 1, 2023 21:57
@bbakerman bbakerman changed the title oneOf directive support Experimental - oneOf directive support Aug 5, 2023
Copy link
Member

@dondonz dondonz left a comment

Choose a reason for hiding this comment

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

Woo hoo!

@dondonz dondonz added this to the 2023 October milestone Aug 15, 2023
@bbakerman bbakerman added this pull request to the merge queue Aug 22, 2023
Merged via the queue into master with commit fe28db5 Aug 22, 2023
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.

3 participants