graphql-zeus icon indicating copy to clipboard operation
graphql-zeus copied to clipboard

typedDocumentNode plugin: Usage with Apollo

Open junwen-k opened this issue 2 years ago • 0 comments

Issue

Projects that are using Apollo Client 3.0 onwards should use exports from @apollo/client instead of @graphql-typed-document-node/core and graphql-tag respectively.

When we pass in --td flag when generating, it outputs:

import { TypedDocumentNode } from '@graphql-typed-document-node/core';
import gql from 'graphql-tag';
...

Proposal

Ideally, the CLI would be smart enough to detect if the project is using Apollo Client 3.x onwards (e.g, checking package.json for @apollo/client), and change the generated file to:

import { TypedDocumentNode, gql } from '@apollo/client';
...

Current Solution

I've manually changed the imports to use @apollo/client without installing additional packages.

Alternative Solution

If this is too many cases to be covered (E.g, to cover not only Apollo but other library as well), we could instead provide examples and let users to create this file themselves.

References:

Apollo 3.0.0: gql Apollo 3.2.0: typedDocumentNode

junwen-k avatar Aug 31 '23 13:08 junwen-k