Skip to content

Can typescript-react-apollo generate TypedDocumentNode? #9754

Closed Answered by alexeyr-ci
alexeyr-ci asked this question in Q&A
Discussion options

You must be logged in to vote

What I ended up doing is using both plugins together, and adding a post-processing hook:

const removeUntypedDocument = (path: string) => {
  const contents = fs.readFileSync(path, 'utf8');
  const newContents = contents.replace(
    // This regex detects the gql tag without a cast to TypedDocumentNode at the end.
    /export const \w*(Document|Doc) = (\/\*#__PURE__\*\/ )?gql`[^`]*`;\n?/mg,
    '',
  );
  fs.writeFileSync(path, newContents);
};

and

      hooks: {
        afterOneFileWrite: removeUntypedDocument,
      },

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by alexeyr-ci
Comment options

You must be logged in to vote
2 replies
@alexeyr-ci
Comment options

@Urigo
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants