Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This is a custom ApolloLink which we use to clean the "__typename" field to prevent sending it to the GraphQL server. omitDeep based on this gist:

This comment has been minimized.

Copy link

commented Dec 16, 2017

how do you integrate that ApolloLink in the ApolloClient?


This comment has been minimized.

Copy link
Owner Author

commented Dec 18, 2017

Hi @pedall,

In the init component I concatenate the Apollo links used in the app and composed them like this:

const myAppLink = ApolloLink.from ([

      link: myAppLink,
      cache: cache

Please let me know if this helps!



This comment has been minimized.

Copy link

commented Jan 5, 2018

Thanks for the snippet! I had to extend the omitDeep method to also let through Date objects, else they got stripped:

const omitDeep = (obj: object, key: string | number): object => {
  const keys: Array<any> = Object.keys(obj);
  const newObj: any = {};
  keys.forEach((i: any) => {
    if (i !== key) {
      const val: any = obj[i];
      if (val instanceof Date) newObj[i] = val;
      else if (Array.isArray(val)) newObj[i] = omitDeepArrayWalk(val, key);
      else if (typeof val === 'object' && val !== null) newObj[i] = omitDeep(val, key);
      else newObj[i] = val;
  return newObj;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.