
Build high-performance #GraphQL web apps using #webcomponents with Apollo Elements
- Tweets118
- Following21
- Followers115
- Likes134

ALT <apollo-client uri="https://api.spacex.land/graphql"> <apollo-query> <script type="application/graphql" src="NextLaunch.query.graphql"></script> <template>{%raw%} <h2>{{ data.launchNext.mission_name }}</h2> <p>launches from <em>{{ data.launchNext.launch_site.site_name }}</em> aboard <em>{{ data.launchNext.rocket.rocket_name }}</em></p> </template>{%endraw%} </apollo-query> </apollo-client>

ALT ๐ฆ success packages published successfully: ๐ฆ @apollo-elements/atomico@0.0.0-next.3 ๐ฆ @apollo-elements/components@2.0.0-next.9 ๐ฆ @apollo-elements/core@0.1.0-next.7 ๐ฆ @apollo-elements/fast@2.0.0-next.8 ๐ฆ @apollo-elements/gluon@4.0.0-next.6 ๐ฆ @apollo-elements/haunted@2.0.0-next.5 ๐ฆ @apollo-elements/hybrids@4.0.0-next.5 ๐ฆ @apollo-elements/lit-apollo@4.0.0-next.8 ๐ฆ @apollo-elements/mixins@4.0.0-next.7 ๐ฆ @apollo-elements/polymer@4.0.0-next.5

ALT Screenshot of chat screen with javascript disabled: Apollo Elements 3 minutes ago Write GraphQL in HTML with Apollo Elements HTML-FTW 3 minutes ago Use plain HTML to define GraphQL templates and operations noscript-noproblem a minute ago Even works without JavaScript on Chromium browsers with SSR ๐คฏ Apollo Elements a minute ago Are GraphQL web components the future of your front end? Apollo Elements 57 seconds ago Check out Apollo Elements - https://next.apolloelements.dev
![@customElement('fruit-stand') class FruitStand extends LitElement { static readonly fruits = ['๐ฅญ', '๐', '๐', '๐', '๐ฅ']; fruits = new ApolloQueryController(this, FruitsQuery, { variables: { fruit: '๐ฅญ' }, }); radio(fruit) { return html` <input id="${fruit}" type="radio" name="id" value="${fruit}" ?checked="${this.fruits.data?.fruits?.fruit == fruit}" @change="${() => this.fruits.variables = { fruit }"/> <label for="${fruit}">${fruit}</label> ` } render() { const picked = this.fruits.data?.fruits; return html` <h2>Pick a fruit!</h2> ${FruitStand.fruits.map(this.radio, this)} <figure class=${classMap({ loading: this.fruits.loading })}> <img src=${ifDefined(picked?.image)} alt="" aria-labelledby="caption"/> <figcaption id="caption"> Yum, ${picked?.fruit ?? 'fruit'}! </figcaption> </figure> `; } }](https://pbs.twimg.com/media/E4pWRNHX0AEDYa9.jpg?name=small&format=webp)
ALT @customElement('fruit-stand') class FruitStand extends LitElement { static readonly fruits = ['๐ฅญ', '๐', '๐', '๐', '๐ฅ']; fruits = new ApolloQueryController(this, FruitsQuery, { variables: { fruit: '๐ฅญ' }, }); radio(fruit) { return html` <input id="${fruit}" type="radio" name="id" value="${fruit}" ?checked="${this.fruits.data?.fruits?.fruit == fruit}" @change="${() => this.fruits.variables = { fruit }"/> <label for="${fruit}">${fruit}</label> ` } render() { const picked = this.fruits.data?.fruits; return html` <h2>Pick a fruit!</h2> ${FruitStand.fruits.map(this.radio, this)} <figure class=${classMap({ loading: this.fruits.loading })}> <img src=${ifDefined(picked?.image)} alt="" aria-labelledby="caption"/> <figcaption id="caption"> Yum, ${picked?.fruit ?? 'fruit'}! </figcaption> </figure> `; } }
![<apollo-query id="leeway-userlist"> <script type="application/graphql" src="Users.query.graphql"></script> <template> <link rel="stylesheet" href="components/shared.css"/> <link rel="stylesheet" href="components/userlist.css"/> <template type="if" if="{{ error }}"> <aside id="error"> <h1>๐ข Such Sad, Very Error! ๐ฐ</h1> <pre>{{ error.message || 'Unknown Error' }}</pre> </aside> </template> <header> <span role="presentation" class="status {{ data.localUser.status }}"></span> <span class="nick">{{ data.localUser.nick ?? 'Users' }}</span> </header> <template type="repeat" repeat="{{ data.users ?? [] }}"> <template type="if" if="{{ item.id !== data.localUser.id }}"> <div class="user"> <span aria-label="{{ item.status }}" class="status {{ item.status }}"></span> {{ item.nick ?? '' }} </div> </template> </template> </template> </apollo-query>](https://pbs.twimg.com/media/E4eFgQNWUAAwzDn.jpg?name=small&format=webp)
ALT <apollo-query id="leeway-userlist"> <script type="application/graphql" src="Users.query.graphql"></script> <template> <link rel="stylesheet" href="components/shared.css"/> <link rel="stylesheet" href="components/userlist.css"/> <template type="if" if="{{ error }}"> <aside id="error"> <h1>๐ข Such Sad, Very Error! ๐ฐ</h1> <pre>{{ error.message || 'Unknown Error' }}</pre> </aside> </template> <header> <span role="presentation" class="status {{ data.localUser.status }}"></span> <span class="nick">{{ data.localUser.nick ?? 'Users' }}</span> </header> <template type="repeat" repeat="{{ data.users ?? [] }}"> <template type="if" if="{{ item.id !== data.localUser.id }}"> <div class="user"> <span aria-label="{{ item.status }}" class="status {{ item.status }}"></span> {{ item.nick ?? '' }} </div> </template> </template> </template> </apollo-query>
![import { useQuery, component, html } from '@apollo-elements/haunted'; import { LaunchesQuery } from './Launches.query.graphql.js'; function Launches({ document = null, variables = null }) { const { data } = useQuery(LaunchesQuery, { variables: { limit: 3 } }); const launches = data?.launchesPast ?? []; return html` <link rel="stylesheet" href="launches.css"/> <ol> ${launches.map(x => html` <li> <article> <span>${x.mission_name}</span> <img .src="${x.links.mission_patch_small}" alt="Badge" role="presentation"/> </article> </li> `)} </ol> `; } customElements.define('spacex-launches', component(Launches));](https://pbs.twimg.com/media/E4JrjJNXEAM2YtH.jpg?name=small&format=webp)
ALT import { useQuery, component, html } from '@apollo-elements/haunted'; import { LaunchesQuery } from './Launches.query.graphql.js'; function Launches({ document = null, variables = null }) { const { data } = useQuery(LaunchesQuery, { variables: { limit: 3 } }); const launches = data?.launchesPast ?? []; return html` <link rel="stylesheet" href="launches.css"/> <ol> ${launches.map(x => html` <li> <article> <span>${x.mission_name}</span> <img .src="${x.links.mission_patch_small}" alt="Badge" role="presentation"/> </article> </li> `)} </ol> `; } customElements.define('spacex-launches', component(Launches));

ALT <apollo-client uri="https://api.spacex.land/graphql"> <apollo-query> <script type="application/graphql" src="queries/LatestLaunch.graphql"></script> <template> <link rel="stylesheet" href="components/spacex-launch.css"/> <article class="{{ data ? 'resolved' : 'loading' }}"> <h2>Latest Launch</h2> <img .src="{{ data.launchLatest.links.mission_patch }}" alt="mission patch"/> <p> Mission {{ data.launchLatest.id }}, <strong>{{ data.launchLatest.mission_name }}</strong> Launched <time>{{ data.launchLatest.launch_date_utc }}</time> aboard <strong>{{ data.launchLatest.rocket.rocket_name }}</strong> </p> </article> </template> </apollo-query> </apollo-client>
![import { ApolloQueryController } from '@apollo-elements/core'; import { ScrollInController } from '../utils'; class PaginatedQueryHost extends LitElement { private query = new ApolloQueryController(this, PaginatedQuery, { onData: () => this.scroller.reobserve(), variables: { offset: 0 }, }) private scroller = new ScrollInController(this, { selector: 'li:nth-last-child(5)', onIntersect: target => this.query.fetchMore({ variables: { offset: parseInt(target.dataset.id), } }), }) render() { const items = this.query.data?.items ?? []; return html` <ol>${items.map(x => html` <li data-id="${x.id}"> <a href="${x.url}">${x.name}</a> </li> `)}</ol> `; } }](https://pbs.twimg.com/media/E0kgxsNXEAc5YMn.jpg?name=small&format=webp)
ALT import { ApolloQueryController } from '@apollo-elements/core'; import { ScrollInController } from '../utils'; class PaginatedQueryHost extends LitElement { private query = new ApolloQueryController(this, PaginatedQuery, { onData: () => this.scroller.reobserve(), variables: { offset: 0 }, }) private scroller = new ScrollInController(this, { selector: 'li:nth-last-child(5)', onIntersect: target => this.query.fetchMore({ variables: { offset: parseInt(target.dataset.id), } }), }) render() { const items = this.query.data?.items ?? []; return html` <ol>${items.map(x => html` <li data-id="${x.id}"> <a href="${x.url}">${x.name}</a> </li> `)}</ol> `; } }







