GraphQL implementation #78
Replies: 2 comments 1 reply
-
Glad you got something working!
|
Beta Was this translation helpful? Give feedback.
-
Edit: I'll leave everything I wrote regardless for future reference. Hey! Thanks for getting back to me. I feel kind of stupid saying this; but I never figured that native Anyway, made an (albeit very basic) example repo for GraphQL with native
@apollo/client (Example repo / apollo branch)All efforts required adding this to the snowpack config. alias: {
"react": "preact/compat",
"react-dom": "preact/compat"
} Otherwise, I would get this issue: [snowpack] node_modules/@apollo/client/react/context/ApolloConsumer.js
Module "react" could not be resolved by Snowpack (Is it installed?). When having added the alias for Preact Compat, Apollo throws this: (node:76839) UnhandledPromiseRejectionWarning:
Invariant Violation: Invariant Violation: 22
------
22: {
file: "@apollo/client/link/http/checkFetcher.js",
node: new InvariantError("\n\"fetch\" has not been found globally and no fetcher has been configured. To fix this, install a fetch package (like https://www.npmjs.com/package/cross-fetch), instantiate the fetcher, and pass it into your HttpLink constructor. For example:\n\nimport fetch from 'cross-fetch';\nimport { ApolloClient, HttpLink } from '@apollo/client';\nconst client = new ApolloClient({\n link: new HttpLink({ uri: '/graphql', fetch })\n});\n ")
}, Which can be resolved as per error message, by adding a import fetch from 'cross-fetch';
const GraphQL = new ApolloClient({
link: new HttpLink({ uri: 'https://countries-274616.ew.r.appspot.com', fetch }),
cache: new InMemoryCache(),
}); Despite, when linking a fetch package, all packages I've tried seem to run into the same issue
|
Beta Was this translation helpful? Give feedback.
-
Hey there!
Been playing around, and really liking
microsite
so far.One thing I would love though, is having a GraphQL client implemented in some way. I tried to set some up with
microsite
myself, but ran into various issues:@apollo/client
Ran into issues with
fetch
.When polyfilling this, ran into issues with
XMLHttpRequest
, sadly.urql/preact
Due to the simplicity of
microsite
(which I love, by the way. Simplicity is good.), I found this setup to be too hard to do. I need to wrap something top level (i.e. App) with a Provider, which isn't really possible unless I modify the microsite code(?) (i.e.dist/document.js
), if I'm not mistaken.graphql-request
Works fine in dev mode, but gets confused about
window
not existing on build.Edit:
Alright, guess I overcomplicated things. 😅 Using
fetch
works just fine in both environments.Cheers! ✨
Beta Was this translation helpful? Give feedback.
All reactions