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

Ignore value nullability #28

Merged
merged 2 commits into from
Dec 22, 2019
Merged

Conversation

brabeji
Copy link
Contributor

@brabeji brabeji commented Dec 19, 2019

  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

Bug fix

  • What is the current behavior? (You can also link to an open issue here)

The link validates the response data but does not account for @skip and @include directives.

  • What is the new behavior (if this is a feature change)?

The link now disregards result value type nullability. We should just convert scalars and don't bother with the nullability validation (apollo client does this). This fixes the link raising errors for non-nullable fields even when they're skipped with @skip directive. This should also take care of @include directive, but this is yet to be tested.

@eturino
Copy link
Owner

eturino commented Dec 20, 2019

@brabeji LGTM but lint fails in CI. Could you fix that? I probably will change that lint rule later tbh…

@brabeji
Copy link
Contributor Author

brabeji commented Dec 20, 2019

@eturino Definitely, I was just probing if this is a valid change. Will fix asap

@eturino
Copy link
Owner

eturino commented Dec 20, 2019

I am thinking about this change a bit more. Indeed this link should not be responsible to ensure null/non-nulls. While your change fixes it for that case, it wouldn't do it on a nested field.

Maybe what we can do is to change the behaviour of ensureNullableType

export function ensureNullableType(

We call this at the beginning of treatValue(). What if instead of calling that, we call directly getNullableType()?

const type = ensureNullableType(value, givenType, fieldNode);

We would have to adapt this test

describe("null values on non-null field", () => {

What do you think @brabeji ?

@eturino
Copy link
Owner

eturino commented Dec 20, 2019

I've added an issue #29 to cover the removal of the nullability checks.

@brabeji
Copy link
Contributor Author

brabeji commented Dec 21, 2019

What if instead of calling that, we call directly getNullableType()?

Yes, that makes sense. I wasn't digging deep enough!

I have some issues with the resulting TS type, which I was unable to solve yet, though. See https://github.com/eturino/apollo-link-scalars/pull/28/files#diff-a5b54a3eee29198834db8832951d216eR69

I've "adapted" 🔪 the test and broken coverage. I'll fix that later today.

Copy link
Owner

@eturino eturino left a comment

Choose a reason for hiding this comment

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

I see. I'll have a look this evening and see if we can avoid that

@brabeji
Copy link
Contributor Author

brabeji commented Dec 21, 2019

I've compared coverage results with master and I can't see any increase in uncovered lines count. Does it look like -0.2% might be expected change when removing code?

@eturino
Copy link
Owner

eturino commented Dec 21, 2019

@brabeji
The issue with using getNullableType() directly is because of the typing definition. We can change the ensureNullableType() function to be:

export function ensureNullableType(
  type: GraphQLOutputType | GraphQLInputType
): GraphQLNullableType {
  return isNonNullType(type) ? type.ofType : type;
}

and that should work fine. If I am not mistaken, that is what getNullableType() does anyway.

btw, re the percentage of lines tested, do not worry. The deleted file was fully tested so taking it out of the equation will always reduce the overall % of tested lines.

@eturino
Copy link
Owner

eturino commented Dec 21, 2019

@all-contributors please add @brabeji for bug, tests, code and idea

@allcontributors
Copy link
Contributor

@eturino

I've put up a pull request to add @brabeji! 🎉

@eturino eturino merged commit 740eaa1 into eturino:master Dec 22, 2019
eturino added a commit that referenced this pull request Dec 22, 2019
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.

None yet

2 participants