Swydo / blaze-apollo

Blaze integration for the Apollo Client
MIT License
54 stars 6 forks source link

Error on client #16

Open ricaragao opened 6 years ago

ricaragao commented 6 years ago

I have an error in my client:

Exception in template helper: TypeError: Template.instance(...).gqlQuery is not a function

Below my code:

import './directors.html';
import gql from 'graphql-tag';

const MY_QUERY = gql`{
    getDirectors {
    label
    hostname
    ip
  }
}`

Template.directors.helpers({
  directors() {
    return Template.instance()
      .gqlQuery({
        query: MY_QUERY
      })
      .get();

  }
});
unigazer commented 6 years ago

@ricaragao Try it like this

import gql from 'graphql-tag';
import ApolloClient from 'apollo-client';
import { ApolloLink } from 'apollo-link'
import { InMemoryCache } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';
import { MeteorAccountsLink } from 'meteor/apollo'
import { setup } from 'meteor/swydo:blaze-apollo';

const client = new ApolloClient({
    link: ApolloLink.from([
        new MeteorAccountsLink(),
        new HttpLink({
            uri: '/graphql'
        })
    ]),
    cache: new InMemoryCache()
});

setup({ client });

Template.directors.helpers({
  directors() {

    const MY_QUERY = gql`
    {
        getDirectors {
            label
            hostname
            ip
        }
    }`

    return Template.instance().gqlQuery({ query: MY_QUERY }).get().getDirectors;
  }
});