Amplify-js: Amplify graphql client and apollo-link-state

Created on 3 Jul 2018  路  6Comments  路  Source: aws-amplify/amplify-js

Do you want to request a feature or report a bug?

Feature report or documentation addition

What is the current behavior?

I would like to know if it is possible de combine the use of apollo-link-state lib with the Aws amplify graphql client ? Or is this functionality already included in the amplify client ?

Thanks,

GraphQL question

All 6 comments

I use appsync with middlewares like this:

import { ApolloProvider } from 'react-apollo';
import { Rehydrated } from 'aws-appsync-react';
import { ApolloLink } from 'apollo-link';
import AWSAppSyncClient, { createAppSyncLink } from 'aws-appsync';
const middlewareAuthLink = new ApolloLink((operation, forward) => {
  return forward(operation);
});
const appSyncLink = createAppSyncLink({
  url: awsconfig.graphqlEndpoint,
  region: awsconfig.region,
  auth: {
    // Your appsync auth
  },
});
const link = ApolloLink.from([middlewareAuthLink, appSyncLink]);
const defaultOptions = {}; // e.g. fetch policies
const client = new AWSAppSyncClient(
  {},
  {
    link,
    defaultOptions,
  }
);
export default () =>  (
  <ApolloProvider client={client}>
    <Rehydrated>
      <App />
    </Rehydrated>
  </ApolloProvider>
);

Thanks for your answer @ricsam. But in your example you are not using the amplify graphql client right ? Or do you mean that we can use the two client similarly ?
So instead of using the AWSAppSyncClient in the Apollo provider we will use the Amplify one ?

@unasirisak Correct. Unfortunately I do not know if it is possible to use apollo link with the amplify client. If you change to the AppSync client https://github.com/awslabs/aws-mobile-appsync-sdk-js you can use apollo link and interact with the appsync graphql backend. It is kinda weird that both exist. I personally prefer to use the appsync sdk for interaction with the gql endpoint. The features of amplify and aws mobile hub are still accessible when using the appsync sdk

@unasirisak as @ricsam mentioned it is currently not possible to use apollo link state with the AWS Amplify graphql client as apollo link state is specific to the Apollo client. The appsync sdk mentioned above is built to work with the Apollo client, so you can use apollo link with that.

We will be working to improve the Amplify graphql client in the near future. Stay tuned.

I am going to close this issue for now. Please reopen if you have any further questions or concerns.

@jordanranz Has there been any movement here?

React Native needs apollo-client-devtools and a library for AWS AppSync + apollo-link-state ASAP :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

karlmosenbacher picture karlmosenbacher  路  3Comments

DougWoodCDS picture DougWoodCDS  路  3Comments

oste picture oste  路  3Comments

shinnapatthesix picture shinnapatthesix  路  3Comments

guanzo picture guanzo  路  3Comments