gajus/babel-plugin-graphql-tag

Does this work for gql imported from @apollo/client?

Open

#41 创建于 2020年7月20日

在 GitHub 查看
 (5 评论) (10 反应) (0 负责人)JavaScript (27 fork)github user discovery
enhancementhelp wanted

仓库指标

Star
 (174 star)
PR 合并指标
 (PR 指标待抓取)

描述

The readme doesn't make it clear if this Babel plugin is able to replace gql when it is imported from places other than graphql-tag; namely @apollo/client.

I tried to load this plugin in the Babel REPL to find out, but it never loads successfully. In a Next.js repo, looking at the resulting bundle, it seems to not work?

No one could answer the question here. I'm surprised the community hasn't smoothed this over yet, since Apollo is advising everyone to import gql from @apollo/client for Apollo Client v3 which had a very long beta period:

The @apollo/client package includes graphql-tag as a dependency and re-exports gql. To simplify your dependencies, we recommend importing gql from @apollo/client and removing all graphql-tag dependencies. — https://www.apollographql.com/docs/react/migrating/apollo-client-3-migration/#graphql-tag

This seems like bad advice. They don't even follow their own advice in their "Compiling queries with Babel" docs:

This approach will allow you to use the graphql-tag library as usual — https://www.apollographql.com/docs/react/performance/babel/#using-babel-plugin-graphql-tag

Maybe Apollo didn't give much thought to performance when designing and documenting their new API?

Either way, if this plugin doesn't handle gql imported from @apollo/client it probably needs to moving forward.

贡献者指南