Skip to content

Instantly share code, notes, and snippets.

@mrajaeim
Created October 20, 2023 20:16
Show Gist options
  • Select an option

  • Save mrajaeim/2fd75eec878c9f6d014b631b9de6d32f to your computer and use it in GitHub Desktop.

Select an option

Save mrajaeim/2fd75eec878c9f6d014b631b9de6d32f to your computer and use it in GitHub Desktop.
How to not delete @client directive for mocking gql from codes in Apollo client!
import { gql as apolloGql } from "@apollo/client";
const gql = (strings, ...keys) => {
if (
process.env.NODE_ENV === "test" ||
process.env.NODE_ENV === "production"
) {
strings = strings.map((str) =>
str.replace(/\@client\s/gi, "").replace(/\s\@client/gi, ""),
);
}
return apolloGql(strings, ...keys);
};
export default gql;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment