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

Enforce Oneof behavior at execution time #3

Open
wants to merge 3 commits into
base: oneof-validation
Choose a base branch
from

Conversation

erikkessler1
Copy link
Owner

This enforces the behavior of Oneof Input Object and Oneof Objects during the execution phase of fulfilling a GraphQL request.

describe('Execute: Handles Oneof Input Objects and Oneof Objects', () => {
describe('Oneof Input Objects', () => {
const rootValue = {
test() {
Copy link

Choose a reason for hiding this comment

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

Should these tests echo back the oneOf input object argument rather than returning a hard coded literal to ensure the inputs make it all the way through the resolvers?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Good call.

},
};

it('accepts a good default value', () => {
Copy link

Choose a reason for hiding this comment

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

Do we also need test coverage for field argument defaults and input object input field defaults that use oneOf input objects?

EDIT: I guess the validation for those scenarios is still pending based on graphql#3049.

@@ -221,6 +229,15 @@ describe('valueFromAST', () => {
);
expectValueFrom('{ requiredBool: null }', testInputObj).to.equal(undefined);
expectValueFrom('{ bool: true }', testInputObj).to.equal(undefined);
expectValueFrom('{ a: "abc" }', testOneOfInputObj).to.deep.equal({
Copy link

Choose a reason for hiding this comment

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

Is it worth testing a oneOf input object with one key that has a value that can't be coerced e.g. {a: 1}?

This ensures that we enforce the rules for Oneof Input Objects at
execution time.
This ensures the Oneof Objects resolve to an object with exactly one
non-null entry.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants