Skip to content

Commit 3ef34d8

Browse files
Updating README for Using Authorization and Subscription links with Apollo Client V3 (#716)
Co-authored-by: Tyler Austin <austyle@amazon.com>
1 parent 0401969 commit 3ef34d8

File tree

1 file changed

+36
-29
lines changed

1 file changed

+36
-29
lines changed

README.md

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77
You can use any HTTP or GraphQL client to connect to a GraphQL API on AppSync.
88

9-
For front-end web and mobile development, we recommend using the [Amplify](https://aws-amplify.github.io/) clients which are optimized to connect to the AppSync backend.
9+
For front-end web and mobile development, we recommend using the [Amplify](https://aws-amplify.github.io/) clients which are optimized to connect to the AppSync backend.
1010

11-
* For DynamoDB data sources, use the DataStore category in the Amplify client. It provides the best developer experience and built-in conflict detection and resolution.
12-
* For non-DynamoDB data sources in scenarios where you have no offline requirements, use the API (GraphQL) category in the Amplify client.
13-
* For use cases where you are utilizing the Apollo V3 client, use the Apollo Links in this repository to help with authorization and subscriptions.
11+
- For DynamoDB data sources, use the DataStore category in the Amplify client. It provides the best developer experience and built-in conflict detection and resolution.
12+
- For non-DynamoDB data sources in scenarios where you have no offline requirements, use the API (GraphQL) category in the Amplify client.
13+
- For use cases where you are utilizing the Apollo V3 client, use the Apollo Links in this repository to help with authorization and subscriptions.
1414

1515
## [AWS AppSync](https://aws.amazon.com/appsync/) Links for Apollo V3
1616

17-
If you would like to use the [Apollo JavaScript client version 3](https://www.apollographql.com/docs/react/) to connect to your AppSync GraphQL API, this repository (on the current stable branch) provides Apollo links to use the different AppSync authorization modes, and to setup subscriptions over web sockets. Please log questions for this client SDK in this repo and questions for the AppSync service in the [official AWS AppSync forum](https://forums.aws.amazon.com/forum.jspa?forumID=280&start=0) .
17+
If you would like to use the [Apollo JavaScript client version 3](https://www.apollographql.com/docs/react/) to connect to your AppSync GraphQL API, this repository (on the current stable branch) provides Apollo links to use the different AppSync authorization modes, and to setup subscriptions over web sockets. Please log questions for this client SDK in this repo and questions for the AppSync service in the [official AWS AppSync forum](https://forums.aws.amazon.com/forum.jspa?forumID=280&start=0) .
1818

1919
![npm](https://img.shields.io/npm/dm/aws-appsync-auth-link.svg)
2020
![npm](https://img.shields.io/npm/dm/aws-appsync-subscription-link.svg)
@@ -88,23 +88,23 @@ npx pod-install
8888

8989
Please visit the [documentation with the Amplify Framework](https://aws-amplify.github.io/docs/js/api) for detailed instructions.
9090

91-
* [React / React Native](#react--react-native)
92-
* [Using Authorization and Subscription links with Apollo Client V3 (No offline support)](#using-authorization-and-subscription-links-with-apollo-client-v3-no-offline-support)
93-
* [Queries and Subscriptions using Apollo V3](#queries-and-subscriptions-using-apollo-v3)
94-
* [Creating a client (Apollo V2)](#creating-a-client-apollo-v2)
95-
* [Queries](#queries)
96-
* [Mutations & optimistic UI (with graphqlMutation helper)](#mutations--optimistic-ui-with-graphqlmutation-helper)
97-
* [Mutations & optimistic UI (without graphqlMutation helper)](#mutations--optimistic-ui-without-graphqlmutation-helper)
98-
* [Subscriptions (with buildSubscription helper)](#subscriptions-with-buildsubscription-helper)
99-
* [Subscriptions (without buildSubscription helper)](#subscriptions-without-buildsubscription-helper)
100-
* [Offline configuration (Apollo V2)](#offline-configuration-apollo-v2)
101-
* [Error handling](#error-handling)
102-
* [Custom storage engine](#custom-storage-engine)
103-
* [Offline helpers](#offline-helpers)
104-
* [Vue](#vue)
105-
* [main.js](#mainjs)
106-
* [App.vue](#appvue)
107-
* [connected component](#connected-component)
91+
- [React / React Native](#react--react-native)
92+
- [Using Authorization and Subscription links with Apollo Client V3 (No offline support)](#using-authorization-and-subscription-links-with-apollo-client-v3-no-offline-support)
93+
- [Queries and Subscriptions using Apollo V3](#queries-and-subscriptions-using-apollo-v3)
94+
- [Creating a client (Apollo V2)](#creating-a-client-apollo-v2)
95+
- [Queries](#queries)
96+
- [Mutations & optimistic UI (with graphqlMutation helper)](#mutations--optimistic-ui-with-graphqlmutation-helper)
97+
- [Mutations & optimistic UI (without graphqlMutation helper)](#mutations--optimistic-ui-without-graphqlmutation-helper)
98+
- [Subscriptions (with buildSubscription helper)](#subscriptions-with-buildsubscription-helper)
99+
- [Subscriptions (without buildSubscription helper)](#subscriptions-without-buildsubscription-helper)
100+
- [Offline configuration (Apollo V2)](#offline-configuration-apollo-v2)
101+
- [Error handling](#error-handling)
102+
- [Custom storage engine](#custom-storage-engine)
103+
- [Offline helpers](#offline-helpers)
104+
- [Vue](#vue)
105+
- [main.js](#mainjs)
106+
- [App.vue](#appvue)
107+
- [connected component](#connected-component)
108108

109109
### React / React Native
110110

@@ -119,10 +119,13 @@ For versions of the Apollo client newer than 2.4.6 you can use custom links for
119119
import { createAuthLink } from "aws-appsync-auth-link";
120120
import { createSubscriptionHandshakeLink } from "aws-appsync-subscription-link";
121121

122-
import { ApolloLink } from "apollo-link";
123-
import { createHttpLink } from "apollo-link-http";
124-
import ApolloClient from "apollo-client";
125-
import { InMemoryCache } from "apollo-cache-inmemory";
122+
import {
123+
ApolloProvider,
124+
ApolloClient,
125+
InMemoryCache,
126+
HttpLink,
127+
ApolloLink,
128+
} from "@apollo/client";
126129

127130
import appSyncConfig from "./aws-exports";
128131

@@ -135,7 +138,7 @@ const auth = {
135138
// credentials: async () => credentials, // Required when you use IAM-based auth.
136139
};
137140

138-
const httpLink = createHttpLink({ uri: url });
141+
const httpLink = new HttpLink({ uri: url });
139142

140143
const link = ApolloLink.from([
141144
createAuthLink({ url, region, auth }),
@@ -146,6 +149,10 @@ const client = new ApolloClient({
146149
link,
147150
cache: new InMemoryCache(),
148151
});
152+
153+
const ApolloWrapper = ({ children }) => {
154+
return <ApolloProvider client={client}>{children}</ApolloProvider>;
155+
};
149156
```
150157

151158
#### Queries and Subscriptions using Apollo V3
@@ -561,8 +568,8 @@ export default graphql(listPosts, {
561568

562569
When using the AWS AppSync SDK offline capabilities (e.g. `disableOffline: false`), you can provide configurations for the following:
563570

564-
* Error handling
565-
* Custom storage engine
571+
- Error handling
572+
- Custom storage engine
566573

567574
#### Error handling
568575

0 commit comments

Comments
 (0)