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

Apollo stores mutation variable as java objects refs instead of using marshaller #977

Closed
mwajeeh opened this issue Jul 6, 2018 · 0 comments · Fixed by #997
Closed

Apollo stores mutation variable as java objects refs instead of using marshaller #977

mwajeeh opened this issue Jul 6, 2018 · 0 comments · Fixed by #997

Comments

@mwajeeh
Copy link

mwajeeh commented Jul 6, 2018

Apollo should stores mutation variables in database using marshaller instead it seems like it is storing them by invoking toString() on them which causes it to store as object ref. This makes database grow with each mutation invocation with no apparent value. Check attached screenshot of table.

screen shot 2018-07-05 at 7 31 49 pm

Issue seems to come from com.apollographql.apollo.api.ResponseField#asJsonValue. Ideally com.apollographql.apollo.api.Operation.Variables should implement some Marshaller interface which com.apollographql.apollo.api.ResponseField#asJsonValue can utilize.

Here is one of compact generated input file:

@Generated("Apollo GraphQL")
public final class UpdateStarredForThreadsInput {
  private final Input<String> clientMutationId;

  private final @NotNull String orgID;

  private final boolean starred;

  private final @NotNull List<String> threadIDs;

  private final Input<String> uuid;

  private volatile int $hashCode;

  private volatile boolean $hashCodeMemoized;

  UpdateStarredForThreadsInput(Input<String> clientMutationId, @NotNull String orgID,
      boolean starred, @NotNull List<String> threadIDs, Input<String> uuid) {
    this.clientMutationId = clientMutationId;
    this.orgID = orgID;
    this.starred = starred;
    this.threadIDs = threadIDs;
    this.uuid = uuid;
  }
  public InputFieldMarshaller marshaller() {
    return new InputFieldMarshaller() {
      @Override
      public void marshal(InputFieldWriter writer) throws IOException {
        if (clientMutationId.defined) {
          writer.writeString("clientMutationId", clientMutationId.value);
        }
        writer.writeCustom("orgID", com.spruce.messenger.domain.apollo.type.CustomType.ID, orgID);
        writer.writeBoolean("starred", starred);
        writer.writeList("threadIDs", new InputFieldWriter.ListWriter() {
          @Override
          public void write(InputFieldWriter.ListItemWriter listItemWriter) throws IOException {
            for (final String $item : threadIDs) {
              listItemWriter.writeCustom(CustomType.ID, $item);
            }
          }
        });
        if (uuid.defined) {
          writer.writeString("uuid", uuid.value);
        }
      }
    };
  }
}
@sav007 sav007 self-assigned this Jul 17, 2018
sav007 added a commit to sav007/apollo-android that referenced this issue Jul 18, 2018
For GraphQL input types if they are involved in building cache key we were using plain `.toString` call.
With this commit we first serialize input type to map, resolve all variable references and sort by name, then serialize result map to json string.

Closes apollographql#977
Closes apollographql#941
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants