-
Notifications
You must be signed in to change notification settings - Fork 656
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
sav007
merged 3 commits into
apollographql:master
from
sav007:feature-290/make-response-return-optional
Mar 18, 2017
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
apollo-api/src/main/java/com/apollographql/android/api/graphql/Mutation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.apollographql.android.api.graphql; | ||
|
||
public interface Mutation<D extends Operation.Data, V extends Operation.Variables> extends Operation<D, V> { | ||
public interface Mutation<D extends Operation.Data, T, V extends Operation.Variables> extends Operation<D, T, V> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
apollo-api/src/main/java/com/apollographql/android/api/graphql/Query.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package com.apollographql.android.api.graphql; | ||
|
||
/** TODO */ | ||
public interface Query<D extends Operation.Data, V extends Operation.Variables> extends Operation<D, V> { | ||
public interface Query<D extends Operation.Data, T, V extends Operation.Variables> extends Operation<D, T, V> { | ||
} |
26 changes: 12 additions & 14 deletions
26
apollo-api/src/main/java/com/apollographql/android/api/graphql/Response.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,37 @@ | ||
package com.apollographql.android.api.graphql; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
/** Represents either a successful or failed response received from the GraphQL server. */ | ||
public class Response<T extends Operation.Data> { | ||
@Nonnull private final Operation operation; | ||
@Nullable private final T data; | ||
@Nullable private final List<Error> errors; | ||
public class Response<T> { | ||
private final Operation operation; | ||
private final T data; | ||
private final List<Error> errors; | ||
|
||
public Response(@Nonnull Operation operation) { | ||
public Response(Operation operation) { | ||
this(operation, null, null); | ||
} | ||
|
||
public Response(@Nonnull Operation operation, @Nullable T data, @Nullable List<Error> errors) { | ||
public Response(Operation operation, T data, List<Error> errors) { | ||
this.operation = operation; | ||
this.data = data; | ||
this.errors = errors; | ||
this.errors = errors != null ? errors : Collections.<Error>emptyList(); | ||
} | ||
|
||
public boolean isSuccessful() { | ||
return errors == null || errors.isEmpty(); | ||
return errors.isEmpty(); | ||
} | ||
|
||
@Nonnull public Operation operation() { | ||
public Operation operation() { | ||
return operation; | ||
} | ||
|
||
@Nullable public T data() { | ||
public T data() { | ||
return data; | ||
} | ||
|
||
@Nullable public List<Error> errors() { | ||
public List<Error> errors() { | ||
return errors; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
import javax.annotation.Nullable; | ||
|
||
@Generated("Apollo GraphQL") | ||
public final class TestQuery implements Query<TestQuery.Data, TestQuery.Variables> { | ||
public final class TestQuery implements Query<TestQuery.Data, Optional<TestQuery.Data>, TestQuery.Variables> { | ||
public static final String OPERATION_DEFINITION = "query TestQuery($episode: Episode, $stars: Int!, $greenValue: Float!) {\n" | ||
+ " heroWithReview(episode: $episode, review: {stars: $stars, favoriteColor: {red: 0, green: $greenValue, blue: 0}}) {\n" | ||
+ " __typename\n" | ||
|
@@ -43,13 +43,18 @@ public String queryDocument() { | |
return QUERY_DOCUMENT; | ||
} | ||
|
||
@Override | ||
public Optional<TestQuery.Data> wrapData(TestQuery.Data data) { | ||
return Optional.fromNullable(data); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Example how data will be wrapped with optional |
||
} | ||
|
||
@Override | ||
public TestQuery.Variables variables() { | ||
return variables; | ||
} | ||
|
||
@Override | ||
public ResponseFieldMapper<? extends Operation.Data> responseFieldMapper() { | ||
public ResponseFieldMapper<TestQuery.Data> responseFieldMapper() { | ||
return new Data.Mapper(); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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