Parcel 2 nightly failure: ApolloClient Invariant violation #4737
-
🐛 bug reportImporting graphql files now returns a string instead of returning graphql tags. Not entirely sure if this is intended behavior. This causes failures when using apollo client. The quick fix for this is to wrap the string around a gql tag. 🎛 Configuration (.babelrc, package.json, cli command){
"name": "parcel2scopehoistingfail",
"version": "1.0.0",
"description": "",
"main": "index.html",
"dependencies": {
"@apollo/react-hooks": "^3.1.5",
"@sentry/browser": "^5.17.0",
"apollo-boost": "^0.4.9",
"graphql": "^15.1.0",
"parcel": "^2.0.0-nightly.288",
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"devDependencies": {
"graphql-import-macro": "^1.0.0"
},
"scripts": {
"build": "parcel build index.html",
"build-with-no-scope-hoist": "parcel build index.html --no-scope-hoist"
},
"author": "",
"license": "ISC"
} 🤔 Expected BehaviorShould run/build correctly 😯 Current BehaviorInvariant violation for apollo client 🔦 ContextThis pull request seems to be the cause of this error. 💻 Code Samplehttps://github.com/water-a/Parcel2GraphQLFailure 🌍 Your Environment
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This is not a bug it's intended behaviour and was a breaking change in the graphql transformer. This decision was mainly due to it pretty much only being used in apollo and creating larger bundles and non usable assets for anyone who wanted to use a smaller or faster graphql library or even write their own. Also it saves some bytes in the final bundle size and should also make code parsing slightly faster as there is less code to parse. Execution might be slightly slower although I doubt you would really notice as graphql-tag is a pretty small library. You can just run our result in Example: // Returns processed graphql query string
import TestQuery from "./test.gql";
// Convert to the Apollo Specific Query AST
const ParsedQuery = gql(test);
const Test = () => {
const { data } = useQuery(ParsedQuery, {
fetchPolicy: "cache-and-network",
});
}; |
Beta Was this translation helpful? Give feedback.
This is not a bug it's intended behaviour and was a breaking change in the graphql transformer.
This decision was mainly due to it pretty much only being used in apollo and creating larger bundles and non usable assets for anyone who wanted to use a smaller or faster graphql library or even write their own.
Also it saves some bytes in the final bundle size and should also make code parsing slightly faster as there is less code to parse. Execution might be slightly slower although I doubt you would really notice as graphql-tag is a pretty small library.
You can just run our result in
graphql-tag
and it'll work...Example: