Stencil-Apollo — Stencil meets GraphQL
Stencil-Apollo lets you easily use GraphQL in Web Components.
GraphQL is everywhere! Together with Typescript it is one of those technologies everyone wants to get their hands on in 2019.
When using GraphQL on the client, the most popular library is the powerful Apollo Client. Today, Apollo currently has an official support for leading Web Frameworks like React and Angular.
But what if you don’t have to use those frameworks to create a really powerful and performant apps? Or what if you want to expose Web Components with shared logic like GraphQL data fetching to developers who use different frameworks?
Web Components and GraphQL
That’s where Stencil come in. It’s a Web Components compiler that combines some of the best features from Angular, React and Vue to create web applications or re-usable platform agnostic UI libraries based on Web Components.
But what if you want to use GraphQL in your Stencil projects or expose that power to your Web Components users?
Today, I am happy to announce the release of a new open source library
Now it is much easier to use StencilJS and create GraphQL-based applications. Stencil-Apollo has the same functionalities as its React sibling React-Apollo, and the usage is really simple.
Stencil and Apollo
Because Stencil-Apollo uses Apollo-Client, you’re still able to take advantage of an entire ecosystem of Apollo Links and Cache implementations.
Everything in Stencil-Apollo is based on Web Components
There are exactly 4 of them:
apollo-providerdefines an Apollo-Client so other Stencil-Apollo components can use it (same as React-Apollo’s
As you know in GraphQL there are three kinds of operations and Stencil-Apollo got all them covered:
apollo-querylets you fetch data
apollo-mutationis responsible to call mutations
apollo-subscriptionhandles subscription for you
As you can see, their names are pretty easy to remember!
Stencil-Apollo combines the change detection mechanism of Apollo Client and StencilJS’s Virtual DOM, like React-Apollo does for React’s VDOM.
To start using Stencil-Apollo check out our examples and docs:
Stencil Apollo Library. Contribute to ardatan/stencil-apollo development by creating an account on GitHub.
Stencil-Apollo works quite well with Ionic 4, and we’re planning to give support for all other frameworks, the same way as Ionic 4 does by using the power of Web Components.
Ready-to-use and strongly typed GraphQL components
The GraphQL Code Generator can be used to generate TypeScript typings for both server and client.
Now it also supports Stencil-Apollo!
Check out our example with GraphQL-Code-Generator
WhatsApp PWA Clone using Stencil and Ionic 4
Follow the process here:
Follow us on GitHub and Medium, we are planning to release many more posts in the next couple of weeks about what we’ve learned using GraphQL in recent years.