FAST: ApolloQuery
ApolloQuery
inherits from ApolloElement
and implements the ApolloQueryInterface
.
Read the query component guides for examples and tips.
import { ApolloQuery, customElement, html, repeat } from '@apollo-elements/fast';
import { styles } from './launches.css.js';
import { LaunchesQuery } from './Launches.query.graphql.js';
import { compose, map, propOr, unary } from './fp-helpers.js';
import '@apollo-elements/components/apollo-client';
const getLaunches = compose(
unary(Array.from),
propOr('launchesPast', []),
propOr('data', null)
);
const getPatch = compose(propOr('mission_patch_small'), propOr('links'));
@customElement({
name: 'spacex-launches',
styles,
template: html<Launches>`
<ol>
${repeat(compose(getLaunches), html``)}
</ol>
`,
})
class Launches extends ApolloQuery<typeof LaunchesQuery> {
query = LaunchesQuery;
variables = { limit: 3 };
}
/** right-to-left function composition */
export const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
/** safe property access */
export const propOr = (name, or) => o => o?.[name] ?? or;
/** safe point-free array map */
export const map = f => xs => xs?.map?.(f) ?? [];
/** nary function to unary function */
export const unary = f => x => f(x);
import { gql } from '@apollo/client/core';
export const LaunchesQuery = gql`
query LaunchesQuery($limit: Int) {
launchesPast(limit: $limit) {
mission_name
links { mission_patch_small }
}
}
`;
<script type="module" src="launches.js"></script>
<apollo-client uri="https://api.spacex.land/graphql">
<spacex-launches></spacex-launches>
</apollo-client>
import { css } from '@microsoft/fast-element';
export const styles = css`
:host {
--image-size: 40px;
}
li img {
height: var(--image-size);
width: auto;
}
li article {
height: var(--image-size);
display: flex;
justify-content: space-between;
}
`;
import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client/core';
window.__APOLLO_CLIENT__ = new ApolloClient({
cache: new InMemoryCache(),
link: new HttpLink({ uri: 'https://api.spacex.land/graphql' }),
});
ApolloQuery
🚀 Custom element base class that connects to your Apollo cache.
Properties
variables
Variables<D, V> | null
Query variables.
An object that maps from the name of a variable as used in the query GraphQL document to that variable's value.
noAutoSubscribe
no-auto-subscribeboolean
nextFetchPolicy
next-fetch-policyWatchQueryFetchPolicy | NextFetchPolicyFunction<D, V>
networkStatus
NetworkStatus
fetchPolicy
fetch-policyWatchQueryFetchPolicy
errorPolicy
error-policyErrorPolicy
data
Data<D> | null
Latest query data.
Exports
import { ApolloQuery } from '@apollo-elements/fast/apollo-query';