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

Make Response object return optional if such config selected #331

Merged

Conversation

sav007
Copy link
Contributor

@sav007 sav007 commented Mar 16, 2017

ResponseFieldMapper<? extends Operation.Data> responseFieldMapper();
ResponseFieldMapper<D> responseFieldMapper();

T wrapData(D data);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

will be called by ResponseConverter

@@ -44,12 +44,17 @@ public String queryDocument() {
}

@Override
public Optional<TestQuery.Data> wrapData(TestQuery.Data data) {
return Optional.fromNullable(data);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Example how data will be wrapped with optional

@@ -55,7 +55,7 @@
}
}
jsonReader.endObject();
return new Response<>(operation, data, errors);
return new Response<>(operation, operation.wrapData(data), errors);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this call will wrap data

@BenSchwab
Copy link
Contributor

BenSchwab commented Mar 16, 2017

Do we have any tests that test what happens when optional is disabled?

Edit: looks like we do: https://github.com/apollographql/apollo-android/pull/331/files#diff-37977119f5d5bf9f9b3285afc785edd3R53

Copy link
Contributor

@BenSchwab BenSchwab left a comment

Choose a reason for hiding this comment

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

This looks good to me --

just to double check, the reason we need to add a new method to every model instead of just adding a boolean wrap field, and a generic runtime wrap utility method is that depending on the presence of libraries (like guava) the wrap code might access an optional implementation that not all user's have a library for?

@sav007
Copy link
Contributor Author

sav007 commented Mar 17, 2017

Yes, that correct. We can have 2 Optional implementations: guava or our own shadowed version. So boolean field is not enough. Plus our Runtime lib knows nothing about guava. So only if user uses Guava we will wrap data (via method wrapData) to guava Optional, otherwise we will wrap it into our shadowed Optional

@sav007
Copy link
Contributor Author

sav007 commented Mar 17, 2017

@digitalbuddha @marwanad any comments?

@digitalbuddha
Copy link
Contributor

digitalbuddha commented Mar 17, 2017 via email

@sav007 sav007 merged commit f5cd001 into apollographql:master Mar 18, 2017
@sav007 sav007 deleted the feature-290/make-response-return-optional branch March 18, 2017 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants