Stencil-Apollo — Stencil meets GraphQL

Stencil-Apollo lets you easily use GraphQL in Web Components.

Mar 6, 2019 · 3 min read

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?

The solution!

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.

Look how easy it is to use stencil-apollo!

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.

There are exactly 4 of them:

  • apollo-provider defines an Apollo-Client so other Stencil-Apollo components can use it (same as React-Apollo’s ApolloProvider).

As you know in GraphQL there are three kinds of operations and Stencil-Apollo got all them covered:

  • apollo-query lets you fetch data
  • apollo-mutation is responsible to call mutations
  • apollo-subscription handles 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 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.

This tool also generates strongly typed React-Apollo components and Apollo-Angular services to improve the development experience. It turns your GraphQL operations into ready to use elements.

How Stencil-Apollo works with GraphQL-Code-Generator

Check out our example with GraphQL-Code-Generator

WhatsApp PWA Clone using Stencil and Ionic 4

We’re also working on an example Stencil PWA project that uses Stencil-Apollo which will be another variation of our WhatsApp Clone.

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.

The Guild

The Guild

Thanks to Urigo


Written by

JavaScript Enthusiast, member of The Guild

The Guild

The Guild

The Guild

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade