Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to use apollo-client through a CDN? #4595

Closed
MartinManev opened this issue Mar 18, 2019 · 11 comments
Closed

Is it possible to use apollo-client through a CDN? #4595

MartinManev opened this issue Mar 18, 2019 · 11 comments

Comments

@MartinManev
Copy link

To me it seems like a very basic thing to do but I'm not seeing any documentation or obvious way to do it. I don't see any file in jsDelivr or UNPKG that is designed to be included this way. I tried bundle.umd.js but it produces various errors for the different libraries (apollo-client, apollo-link, apollo-link-http, apollo-cache-inmemory, ...). Could someone provide a working example of this?

@JoviDeCroock
Copy link
Contributor

What errors does this url: https://unpkg.com/[email protected]/bundle.umd.js provide for you?

If you can give some tips on this I might be able to fix it

@MartinManev
Copy link
Author

Simply adding
<script src="https://unpkg.com/[email protected]/bundle.umd.js"></script>
produces
Uncaught TypeError: Cannot read property 'utilities' of undefined at bundle.umd.js:4 at bundle.umd.js:5
This can be tested in JSFiddle.
I tried importing apollo-utilities through a CDN too, but the error kept appearing.
<script src="https://unpkg.com/[email protected]/lib/bundle.umd.js"></script>
Then I saw that in apollo-client the reference to utilities is
global.apollo.utilities
While apollo-utilities registers itself as
global['apollo.utilities']
So I managed to fix this issue by editing the bundle file manually, but then more errors piled up and I soon gave up.

@MartinManev
Copy link
Author

From my understanding it is not actually possible to achieve this.

The apollo bundle depends on graphql-js which has a similar issue to this one.
graphql/graphql-js#1639

One of the answers there is:

We distribute GraphQL as CJS/MJS package on NPM.
This library is huge (ATM. ~700kb and growing with each release) but highly modular so we expect that frontend apps will use only necessary parts. That's why we don't release it as a single file bundle and expect developers to use it together with bundlers.

A possible solution for my case would be to bundle apollo+graphql as a single file and host it on a cdn. That way I will be able to reuse it across multiple projects.

@DabeDotCom
Copy link

Timely! I was hoping to do this yesterday, too... «sigh»

@benjamn
Copy link
Member

benjamn commented Apr 29, 2019

Although I/we have some exciting ideas for better ways to deliver the Apollo Client libraries (from a CDN, separate from the main application JS bundle, with better caching), I'm afraid @MartinManev's comment is exactly correct for the time being. In general, only libraries that have no external dependencies can be (easily) loaded as UMD bundles from unpkg.com.

@benjamn benjamn closed this as completed Apr 29, 2019
@suryacaprice
Copy link

are there any alternatives or workaround to use this via CDN .

@viebel
Copy link

viebel commented Feb 24, 2020

are there any alternatives or workaround to use this via CDN ?

1 similar comment
@qidian99
Copy link

qidian99 commented Mar 5, 2020

are there any alternatives or workaround to use this via CDN ?

@eddivalen
Copy link

Yes here's the example from Akryum https://jsfiddle.net/Akryum/oyejk2qL/

@jayshah123
Copy link

Is there any rollup config that can make up such a bundle?

@hwillson
Copy link
Member

@jayshah123 see #8222 (coming in 3.4)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants