Skip to content

Conversation

@kamilkisiela
Copy link
Member

@kamilkisiela kamilkisiela commented Aug 12, 2016

Closes #62

  • docs apollostack/docs#173

Example:

import { Subject } from 'rxjs/Subject';

const name = new Subject();
const city = new Subject();
const obs = client.watchQuery({
  query, 
  variables: {
    name,
    city
  }
});

obs.subscribe(result => {
  console.log(result);
});

// waits for values to be emitted

name.next('Kamil');

// still waits

city.next('Warsaw'); // build the query with { name: 'Kamil', city: 'Warsaw' }

city.next('Cracow'); // rebuild the query with { name: 'Kamil', city: 'Cracow' }

@kamilkisiela kamilkisiela added enhancement New feature or request in progress labels Aug 12, 2016
@kamilkisiela kamilkisiela added this to the v0.4.3 milestone Aug 12, 2016
@kamilkisiela kamilkisiela force-pushed the variable-observable branch 3 times, most recently from b76e2d1 to 2c82d30 Compare August 13, 2016 10:57
@kamilkisiela
Copy link
Member Author

kamilkisiela commented Aug 13, 2016

Done but it seems like there is an issue with mockNetworkInterface

apollographql/apollo-client#535

Also a problem with missing apollo-specific method (like refetch) after mergeMap

@kamilkisiela kamilkisiela force-pushed the variable-observable branch 2 times, most recently from 5b1c9c4 to 48322f0 Compare August 13, 2016 14:50
@kamilkisiela
Copy link
Member Author

Seems like the problem with missing apollo-specific methods has been solved.

@kamilkisiela
Copy link
Member Author

Possible cases:

All variables as Subjects

import { Subject } from 'rxjs/Subject';

const name = new Subject();
const city = new Subject();
const obs = client.watchQuery({
  query, 
  variables: {
    name,
    city
  }
});

obs.subscribe(result => {
  console.log(result);
});

// waits for values to be emitted

name.next('Kamil');

// still waits

city.next('Warsaw'); // builds the query with {name: 'Kamil', city: 'Warsaw' }

Mixed

import { Subject } from 'rxjs/Subject';

const name = new Subject();
const obs = client.watchQuery({
  query, 
  variables: {
    name,
    city: 'Warsaw'
  }
});

obs.subscribe(result => {
  console.log(result);
});

// waits for values to be emitted

name.next('Kamil'); // builds the query with {name: 'Kamil', city: 'Warsaw' }

No Subjects

const name = 'Kamil';
const obs = client.watchQuery({
  query, 
  variables: {
    name,
    city: 'Warsaw'
  }
});

obs.subscribe(result => {
  console.log(result);
});

// builds the query with {name: 'Kamil', city: 'Warsaw' }

@jbaxleyiii
Copy link
Contributor

This is so awesome @kamilkisiela

@kamilkisiela
Copy link
Member Author

kamilkisiela commented Aug 14, 2016

@jbaxleyiii Any suggestions about the implementation? It might be the final solution but I'm still waiting to merge it.

I was thinking to implement it in ApolloClient, somehow.

@kamilkisiela
Copy link
Member Author

kamilkisiela commented Aug 14, 2016

I was also thinking about writing a blog post about it. angular2-apollo with Angular2 RC5 and RxJS support with this killer feature is a huge thing, I think.

@jboothe
Copy link

jboothe commented Aug 14, 2016

@kamilkisiela Definitely +1 on the blog post.

@Urigo
Copy link
Member

Urigo commented Aug 14, 2016

@robwormald would love to get your take on this

const cleanOptions = omit(options, 'variables');
const newOptions = assign(cleanOptions, { variables: newVariables });

apolloRef.apollo = this.client.watchQuery(newOptions);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kamilkisiela would it be better to do a refetch with the new variables instead of creating a new query here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbaxleyiii I don't know if it would work with switchMap, I'll take a look on this.

@jbaxleyiii
Copy link
Contributor

@kamilkisiela notes added!

@kamilkisiela
Copy link
Member Author

Docs added apollostack/docs#173

@Urigo Urigo merged commit 3e84d6d into master Aug 16, 2016
@kamilkisiela kamilkisiela deleted the variable-observable branch August 16, 2016 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants