Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I add a custom link to the link chain? #3

Closed
kabriel opened this issue Dec 30, 2017 · 4 comments
Closed

How can I add a custom link to the link chain? #3

kabriel opened this issue Dec 30, 2017 · 4 comments
Assignees
Labels
enhancement Used for enhancements to AppSync SDK

Comments

@kabriel
Copy link

kabriel commented Dec 30, 2017

How would I extend the link chain with a link such as apollo-link-error?
https://github.com/apollographql/apollo-link/tree/master/packages/apollo-link-error

@manueliglesias manueliglesias self-assigned this Jan 2, 2018
@manueliglesias manueliglesias added the enhancement Used for enhancements to AppSync SDK label Jan 2, 2018
@manueliglesias
Copy link
Contributor

Hi @kabriel

Thanks for trying the service and the sdk!

As of now, it is not possible to customize the link chain. We're looking into supporting it, stay tuned.

For now, you can use a vanilla apollo-client instance with this package's links

let link = ApolloLink.from([
new OfflineLink(store),
new ComplexObjectLink(complexObjectsCredentials),
new AuthLink({ url, region, auth }),
ApolloLink.split(
operation => {
const { query } = operation;
const { kind, operation: graphqlOperation } = getMainDefinition(query);
const isSubscription = kind === 'OperationDefinition' && graphqlOperation === 'subscription';
return isSubscription;
},
ApolloLink.from([
new NonTerminatingHttpLink('subsInfo', { uri: url }, true),
new SubscriptionHandshakeLink('subsInfo'),
]),
new HttpLink({ uri: url }),
),
]);

@jpstrikesback
Copy link

Hey there, just want to chime in to mention that we'd like to use apollo-link-state for local state, and potentially try a different cache implementation like apollo-hermes-cache.

@jpstrikesback
Copy link

jpstrikesback commented Mar 4, 2018

We're currently doing this now via the PR #62, usage (i.e. using the fork via npm/yarn link) is rather difficult mind you if your bundler isn't fond of symlinks (metro seems to choke on them)

manueliglesias added a commit to manueliglesias/aws-mobile-appsync-sdk-js that referenced this issue Apr 16, 2018
Allows the usage of:

- Custom link
- Custom cache
- Custom cache options

Fixes awslabs#3
Fixes awslabs#21
Fixes awslabs#24
Fixes awslabs#36
Fixes awslabs#52
Fixes awslabs#70
Fixes awslabs#87
Closes awslabs#62
@manueliglesias
Copy link
Contributor

Once PR #96 gets merged, it should be possible to use custom links with the AWS AppSync client like this: (e.g. apollo-link-error)

import { ApolloLink } from 'apollo-link';
import { onError } from 'apollo-link-error';
import AWSAppSyncClient, { createAppSyncLink } from "aws-appsync";

const onErrorLink = onError(({ graphQLErrors, networkError }) => {
  if (graphQLErrors)
    graphQLErrors.map(({ message, locations, path }) =>
      console.log(
        `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
      )
    );
  if (networkError) console.log(`[Network error]: ${networkError}`);
});

const appSyncLink = createAppSyncLink({
  url: appSyncConfig.graphqlEndpoint,
  region: appSyncConfig.region,
  auth: {
    type: appSyncConfig.authenticationType,
    apiKey: appSyncConfig.apiKey
  }
});

const link = ApolloLink.from([
  onErrorLink,
  appSyncLink
]);

const client = new AWSAppSyncClient({}, { link });

manueliglesias added a commit that referenced this issue Apr 19, 2018
* Use custom link cache and cache options

Allows the usage of:

- Custom link
- Custom cache
- Custom cache options

Fixes #3
Fixes #21
Fixes #24
Fixes #36
Fixes #52
Fixes #70
Fixes #87
Closes #62

* Pass store to OfflineLink when using createAppSyncLink

* Fix eslint rules violations

* Fix typo. Address CR comment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Used for enhancements to AppSync SDK
Projects
None yet
Development

No branches or pull requests

3 participants