You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I've been learning Svelte and one of the small apps I have built is a POC for using Svelte with a graphql backend. For this I have of course used the fine svelte-apollo library along with bits and bobs from apollo itself. I'm posting this issue as a "note" as much as a question/bug report, since I cannot say this necessarily is an issue with svelte-apollo, but may be my somewhat inept way of setting things up or the general messiness of the javascript universe, but I thought someone might either have some insight into what's going on or maybe have a similar problem and then this might be a fix. I'm using rollup to get Svelte to build and I am guessing there is a connection there.
So. I started out creating my test app with the setup of ApolloClient in the <script> section of App.svelte. And it worked very nicely.
App.svelte
<script>
import {ApolloClient,HttpLink,InMemoryCache,split} from "apollo-boost";
import {WebSocketLink} from "apollo-link-ws";
import {getMainDefinition} from "apollo-utilities";
import {setClient} from "svelte-apollo";
import {Container,Row,Col} from "sveltestrap";
import Batches from "./Batches.svelte";
const headers = {"content-type": "application/json","x-hasura-admin-secret": "notSecret",};
const getHeaders = () =>{returnheaders;};
const wsLink = new WebSocketLink({uri: "ws://localhost:8080/v1/graphql",options: {reconnect: true,lazy: true,connectionParams: ()=>{return{headers: getHeaders()};},},});
const httpLink = new HttpLink({uri: "http://localhost:8080/v1/graphql",headers: getHeaders(),});
const link = split(
({query}) =>{const{ kind, operation }=getMainDefinition(query);returnkind==="OperationDefinition"&&operation==="subscription";},
wsLink,
httpLink
);
const cache = new InMemoryCache();
const client = new ApolloClient({link,cache,onError: ({ networkError, graphQLErrors })=>{console.log("graphQLErrors",graphQLErrors);console.log("networkError",networkError);},});
setClient(client);
</script><Container><Row><Col><Batches/></Col></Row></Container>
Works fine and I get a list of batches. But here's the curious thing. I extracted most of the apollo-related code that creates the client into its own .js file and used it as an import in my App.svelte. And then I get this error in the console: ReferenceError: process is not defined with references to the last line of bundle.js and to line 7 of graphql/jsutils/instanceOf.mjs.
instanceOf.mjs looks like this (I have indicated the line with the error):
/** * A replacement for instanceof which includes an error warning when multi-realm * constructors are detected. */// See: https://expressjs.com/en/advanced/best-practice-performance.html#set-node_env-to-production// See: https://webpack.js.org/guides/production/ERRORHERE-->exportdefaultprocess.env.NODE_ENV==='production' ? // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')// eslint-disable-next-line no-shadowfunctioninstanceOf(value,constructor){returnvalueinstanceofconstructor;} : // eslint-disable-next-line no-shadowfunctioninstanceOf(value,constructor){if(valueinstanceofconstructor){returntrue;}if(value){varvalueClass=value.constructor;varclassName=constructor.name;if(className&&valueClass&&valueClass.name===className){thrownewError("Cannot use ".concat(className," \"").concat(value,"\" from another module or realm.\n\nEnsure that there is only one instance of \"graphql\" in the node_modules\ndirectory. If different versions of \"graphql\" are the dependencies of other\nrelied on modules, use \"resolutions\" to ensure only one version is installed.\n\nhttps://yarnpkg.com/en/docs/selective-version-resolutions\n\nDuplicate \"graphql\" modules cannot be used at the same time since different\nversions may have different capabilities and behavior. The data from one\nversion used in the function from another could produce confusing and\nspurious results."));}}returnfalse;};
Now I'm not super well informed on how JS importing and modules work but I'm guessing the last line of bundle.js should look like this: }(process)); instead of }()); and all goes south when it doesn't!
After quite a bit of fiddling I found that I could solve my problem by changing the order of my imports! Usually I import external dependencies first followed by "local" stuff:
App.svelte:
<script>
import {setClient} from "svelte-apollo";
import {client} from "./apollo";
import Batches from "./Batches.svelte";
setClient(client);
</script>...
and this is when I get the error above. But if I swap the order in App.svelte to
<script>
import {client} from "./apollo";
import {setClient} from "svelte-apollo";
import Batches from "./Batches.svelte";
setClient(client);
</script>
everything works again! Say whaaat?!?
Final note: It seems I'm using an "old" way of importing apollo, as the docs now refer to @apollo/client and sub parts thereof. I tried changing my imports to that with the result that I get the error above regardless of order of importing!
The text was updated successfully, but these errors were encountered:
Hello, I've been learning Svelte and one of the small apps I have built is a POC for using Svelte with a graphql backend. For this I have of course used the fine svelte-apollo library along with bits and bobs from apollo itself. I'm posting this issue as a "note" as much as a question/bug report, since I cannot say this necessarily is an issue with svelte-apollo, but may be my somewhat inept way of setting things up or the general messiness of the javascript universe, but I thought someone might either have some insight into what's going on or maybe have a similar problem and then this might be a fix. I'm using rollup to get Svelte to build and I am guessing there is a connection there.
So. I started out creating my test app with the setup of ApolloClient in the <script> section of App.svelte. And it worked very nicely.
App.svelte
Batches.svelte
Works fine and I get a list of batches. But here's the curious thing. I extracted most of the apollo-related code that creates the
client
into its own .js file and used it as an import in my App.svelte. And then I get this error in the console:ReferenceError: process is not defined
with references to the last line of bundle.js and to line 7 of graphql/jsutils/instanceOf.mjs.instanceOf.mjs looks like this (I have indicated the line with the error):
Now I'm not super well informed on how JS importing and modules work but I'm guessing the last line of bundle.js should look like this:
}(process));
instead of}());
and all goes south when it doesn't!After quite a bit of fiddling I found that I could solve my problem by changing the order of my imports! Usually I import external dependencies first followed by "local" stuff:
App.svelte:
apollo.js:
and this is when I get the error above. But if I swap the order in App.svelte to
everything works again! Say whaaat?!?
Final note: It seems I'm using an "old" way of importing apollo, as the docs now refer to
@apollo/client
and sub parts thereof. I tried changing my imports to that with the result that I get the error above regardless of order of importing!The text was updated successfully, but these errors were encountered: