Code Monkey home page Code Monkey logo

Comments (10)

mdbiscan avatar mdbiscan commented on May 22, 2024

Looking at this more, I'm seeing other methods as undefined: trackSubscription, activeSubscriptions, unsubscribeAll.

Seems to have reference to the wrong service? mutate, query, and watchQuery are all defined.

from ember-apollo-client.

bgentry avatar bgentry commented on May 22, 2024

@mdbiscan how are you trying to use Apollo? The recommended way is to import a query manager mixin and use that in your route/controller/component/etc:

import Route from "@ember/routing/route";
import RouteQueryManager from "ember-apollo-client/mixins/route-query-manager";
import query from "my-app/gql/queries/human";

export default Route.extend(RouteQueryManager, {
  model(params) {
    let variables = { id: params.id };
    return this.get("apollo").watchQuery({ query, variables }, "human");
  }
});

Though I just realized the readme has some spots that use this.apollo instead of this.get("apollo"), which could potentially cause issues.

from ember-apollo-client.

mdbiscan avatar mdbiscan commented on May 22, 2024

This was my original route:

import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import RouteQueryManager from 'ember-apollo-client/mixins/route-query-manager';
import query from 'ember-apollo-example/gql/queries/allAuthors';

export default Route.extend(RouteQueryManager, {
  apollo: service(),

  model(params) {
    return this.get('apollo')
      .query({ query }, 'author')
      .catch(error => console.error(`Authors Route: ${error}`));
  },
});

This will return the original error. I switched to the following code:

import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import RouteQueryManager from 'ember-apollo-client/mixins/route-query-manager';
import query from 'ember-apollo-example/gql/queries/allAuthors';

export default Route.extend(RouteQueryManager, {
  apollo: service(),

  model(params) {
    const variables = { id: params.id };

    return this.get('apollo')
      .watchQuery({ query, variables }, 'author')
      .catch(error => console.error(`Authors Route: ${error}`));
  },
});

However, I still get the same error whether or not I use query or watchQuery and whether or not I pass variables (which I am not, so they are null anyway).

One last thing: Removing the mixin (just to get the request going), in my network tab, I definitely get a query returned with no errors. However, the model being returned is always undefined. It's a promise, but undefined when resolved. That has my head scratching...

from ember-apollo-client.

bgentry avatar bgentry commented on May 22, 2024

Ah, I see the issue. By including the apollo service directly, you’re actually overriding the apollo query manager. The fix is to only use the mixin and not the service injection.

from ember-apollo-client.

mdbiscan avatar mdbiscan commented on May 22, 2024

OK, that makes sense now that you point it out. I'm doing this now:

import Route from '@ember/routing/route';
import RouteQueryManager from 'ember-apollo-client/mixins/route-query-manager';
import query from 'ember-apollo-example/gql/queries/allAuthors';

export default Route.extend(RouteQueryManager, {
  model(params) {
    const variables = { id: params.id };

    return this.get('apollo')
      .watchQuery({ query, variables }, 'author')
      .catch(error => console.error(`Authors Route: ${error}`));
  },
});

Getting this error: Uncaught TypeError: Cannot set property '_apolloObservable' of undefined

from ember-apollo-client.

mdbiscan avatar mdbiscan commented on May 22, 2024

Interestingly, I changed back to query from watchQuery, and receive no errors. However, the promise returns undefined still.

from ember-apollo-client.

viniciussbs avatar viniciussbs commented on May 22, 2024

Have you tried to replace .watchQuery({ query, variables }, 'author') to .watchQuery({ query, variables })?

from ember-apollo-client.

mdbiscan avatar mdbiscan commented on May 22, 2024

Ah, that worked. Not sure how it muddled everything.

from ember-apollo-client.

bgentry avatar bgentry commented on May 22, 2024

Yeah, that's a known issue. If your query doesn't return any data then there's nothing for us to Ember.get on. I'm not sure there's a good solution to it though without a big API change. Glad you got it working!

from ember-apollo-client.

mdbiscan avatar mdbiscan commented on May 22, 2024

Ah, well that's good to know. Thanks again for the help!

from ember-apollo-client.

Related Issues (20)

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.