menu

Apollo

A community of developers, designers and others who love Apollo and GraphQL. 🚀

Channels
# All channels
view-forward
# General
view-forward
# Apollo Angular
view-forward
# Announcements
view-forward
# Apollo Android
view-forward
# Apollo Client
view-forward
# Apollo iOS
view-forward
# Apollo Link
view-forward
# Apollo Link Rest
view-forward
# Local State
view-forward
# Apollo Studio
view-forward
# Apollo Server
view-forward
# Apollo Tooling
view-forward
# Contributing
view-forward
# Docs
view-forward
# Events
view-forward
# GraphQL Tools
view-forward
# Jobs
view-forward
# Random
view-forward
# React Apollo
view-forward
# Showcase
view-forward
# Subscriptions
view-forward
# Testing
view-forward
# Vue Apollo
view-forward
Team

Apollo client queries -- strip whitespace

May 12, 2020 at 6:24pm

Apollo client queries -- strip whitespace

May 12, 2020 at 6:24pm
Hey there. Is there any way to strip whitespace on the client-side HTTP requests apollo-link-http executes? I've been successful in adding a patch to apollo-link-http-common to strip the whitespace on server queries, but can't seem to remove the whitespace on the same queries client-side.
Things I've tried:
  1. stripping all whitespace where queries are defined before being exported and executed
  2. implement Apollo Link middleware to intercept & strip the whitespace on the request (confirmed the whitespace was gone in the console, still appearing in the XHR request)
Any ideas would be greatly appreciated!

May 12, 2020 at 7:19pm
I think your only choice might be to fork apollo-link-http and modify it to strip whitespace. I haven't found any other way to do it so far
  • reply
  • like
thats what I've done in number 1 actually -- the gql tag is being passed a query with all the whitespace removed, but it's somehow persisting in the HTTP request which I don't really understand. interesting idea -- I may be able to write a patch for it like I've done with apollo-link-http-common -- I can give that a shot as well
  • reply
  • like
Disregard my original suggestion, I didn't think that all the way through. graphql-tag parses the query into AST, so something has to parse the AST back into a string to be sent with the request. Any formatting to the original query would be lost. Here is where the query is converted back to a string. Like suggested, you'd need to write your own link that applied whatever transformation after the query is printed.
  • reply
  • like
Or if you're ok with hacky solutions you could monkey patch the print function from the graphql package
  • reply
  • like