Coder Social home page Coder Social logo

christianulbrich / stencil-apollo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ardatan/stencil-apollo

0.0 1.0 0.0 348 KB

Stencil Apollo Library

Home Page: https://medium.com/the-guild/stencil-apollo-stencil-meets-graphql-6fec577ee615

TypeScript 96.69% CSS 0.01% HTML 3.30%

stencil-apollo's Introduction

stencil

npm version Discord Chat

Stencil-Apollo is a collection of web components built using Stencil.

Release Blog Post: Stencil-Apollo - Stencil meets GraphQL

You can start using it in your existing project like its sibling React-Apollo;

Install it using npm or yarn;

  $ yarn add stencil-apollo

or

  $ npm i stencil-apollo

and don't forget to install other necessary dependencies if you don't have them.

  $ yarn add graphql @types/graphql graphql-tag apollo-boost

Add esnext.asynciterable to compilerOptions.lib field in tsconfig.json to make TypeScript allow GraphQL to use AsyncIterator.

 {
 ...
  "compilerOptions": {
    "lib": ["dom", "es2017", "esnext.asynciterable"],
  },
  ...
}

Then add stencil-apollo to your global file which is src/global/app.ts by default or your root component file;

import 'stencil-apollo';

Finally you can provide your ApolloClient instance on your root component, then use components everywhere in your project;

<apollo-provider client={new ApolloClient(...)}>
...
</apollo-provider>
  <apollo-query query={ gql`query { foo }` } renderer={
    ({ data, loading }) => {
       if (loading) {
        return 'Loading';
       }
       return <p>Foo: {data.foo}</p>;
    }
  } />

or you can use functional components like React-Apollo

import { Query } from 'stencil-apollo';

<Query query={ gql`query { foo }` }>
  {
    ({ data, loading }) => {
      if (loading) {
      return 'Loading';
      }
      return <p>Foo: {data.foo}</p>;
    }
  }
</Query>

stencil-apollo's People

Contributors

amshalem avatar ardatan avatar mikaelkaron avatar nmkettler avatar renovate-bot avatar renovate[bot] avatar urigo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.