Version 2 Removes variables and trigger named slots from <apollo-mutation>, replacing them with a single anonymous slot. This gives users more control over their mutation components.
The previous named-slot-based API assumed that the user wanted the trigger to appear in the DOM after the variable-inputs, but this isn't always what the user wants. Users also had to make their inputs and triggers direct children of the mutation element - it would not work if they nested them in <label> or <header> elements, for example.
Instead of using slot="variable" add a data-variable attribute to any input-like element that represents a variable, e.g. <input data-variable="varName"\> would represent the value of the varName variable.
Similarly, to assign a button-like element as the trigger, add a trigger attribute to it.
Version 2 also removes the protected trigger and button accessors, and replaces them with triggers and buttons, which return NodeLists.
<apollo-mutationinput-key="input"><!-- Oops! appears after `a-input` in shadow DOM --><buttonslot="trigger">Mutate!</button><label><span>Name:</span><!-- Oops! Not slotted into `<apollo-mutation>`! --><inputslot="variable"data-variable="name"/></label></apollo-mutation>
Previous versions mixed the ApolloElement interface into the host element. This was a bad hack, if you relied on it (e.g. by referencing this.data, etc.), change your references to the hook controller instead.
functionQueryComponent(){const{ data }=useQuery(SomeQuery);useEffect(()=>{this.dispatchEvent(newCustomEvent('data'))},[data]);}
customElements.define('query-component',component(QueryComponent));document.querySelector('query-component').addEventListener('data',event=>{// referencing `data` on the element - Bad!const{ data }= event.target;});
functionUsesQueryComponent(){const{ data }=useQuery(SomeQuery);useEffect(()=>{this.dispatchEvent(newCustomEvent('data',{ detail:{ data }}))},[data]);}
customElements.define('uses-query-component',component(UsesQueryComponent));document.querySelector('uses-query-component').addEventListener('data',event=>{// referencing `data` from the hook's controller - Better!const{ data }= event.detail;});
From @apollo-elements/hybrids 3.x
Previous versions required the use of the client factory to mix the ApolloElement interface into the host element. Render functions and other references to the host would access the query data on host.data, etc.
Version 4 removes the client factory and keeps the GraphQL data within the factory's controller.
Change your references from the host to the factory's property:
More broadly, mixins users can use controller-based workflows by applying the ControllerHostMixin:
import{ApolloQueryMixin}from'@apollo-elements/mixins';import{SomeQuery}from'./Some.query.graphql';exportclassQueryElementextendsApolloQueryMixin(HTMLElement)<typeofSomeQuery>{myRenderCallback(){// get the query data on the elementconst{ data }=this;// ...somehow render the query data}}
import{ControllerHostMixin}from'@apollo-elements/mixins';import{SomeQuery}from'./Some.query.graphql';exportclassElementWithAQueryextendsControllerHostMixin(HTMLElement){
query =newApolloQueryController(this,SomeQuery);update(){this.myRenderCallback()// Don't forget the super callsuper.update();}myRenderCallback(){// get the query data from the Controllerconst{ data }=this.query;// ...somehow render the query data}}
From @apollo-elements/polymer 3.x
The element names and import paths have changed. Prefix them with polymer-.