Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

apollo-client 2.0 #57

Merged
merged 1 commit into from Jan 18, 2018
Merged

apollo-client 2.0 #57

merged 1 commit into from Jan 18, 2018

Conversation

matart15
Copy link
Contributor

Trying to use apollo-client 2 .
Easiest way is pass apollo-client v2 object directly. But this check skips client and builds v1 client.

So, If this v1 client instanceOf check is removed we can use v2 client like this.

import buildApolloClient from 'aor-graphql-client-graphcool'
import ApolloClient from 'apollo-client';
import { HttpLink } from 'apollo-link-http';
import { ApolloLink, concat } from 'apollo-link';

  const client = new ApolloClient({
    link: new HttpLink({ uri: 'http://localhost:3000' }),
    cache: new InMemoryCache().restore(window.__APOLLO_STATE__),
  });

  buildApolloClient({
    client: apolloClient,
  })

Copy link
Collaborator

@djhi djhi left a comment

Choose a reason for hiding this comment

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

I see the problem but we should still be able to pass options and build a client if not specified. It would be better to introduce a new clientOptions parameter. If client is specified, use it, otherwise build one with the clientOptions

@@ -34,6 +34,7 @@ const getOptions = (options, aorFetchType, resource) => {

export default async options => {
const {
clientObject,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd rather name this one client and rename the old client to clientOptions. We could then remove completely the check for ApolloClient at L48.

This will be a breaking change though and we need to update the documentation accordingly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. I will change it.
But what about tests?

If we need to chage tests I am going to take 1 or 2 days

clientOptions && clientOptions instanceof ApolloClient ? clientOptions : buildApolloClient(clientOptions);
let client = clientObject
if(!client){
client = clientOptions && clientOptions instanceof ApolloClient ? clientOptions : buildApolloClient(clientOptions);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you remove that and just build the ApolloClient if no client was provided already ?

@matart15
Copy link
Contributor Author

@djhi I cahnged README too. is it ok?

Copy link
Collaborator

@djhi djhi left a comment

Choose a reason for hiding this comment

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

Almost there, you should also mention in the documentation that you can pass an existing client with the client option

@matart15
Copy link
Contributor Author

It is already mentioned here. https://github.com/marmelab/aor-graphql/blame/master/packages/aor-graphql-client/README.md#L103

@djhi djhi merged commit 3628a00 into marmelab:master Jan 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants