awslabs / aws-mobile-appsync-sdk-js

JavaScript library files for Offline, Sync, Sigv4. includes support for React Native
Apache License 2.0
921 stars 266 forks source link

fix(subscription): update request return type correctly match apollo-link (v2) #728

Closed dpilch closed 2 years ago

dpilch commented 2 years ago

Description of changes: Continuing change from https://github.com/awslabs/aws-mobile-appsync-sdk-js/pull/566. This change was originally created by a contributor but it appears to have been abandoned. See https://github.com/awslabs/aws-mobile-appsync-sdk-js/pull/566 for full description.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

See v3 change: https://github.com/awslabs/aws-mobile-appsync-sdk-js/pull/727

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

dpilch commented 2 years ago

Canceling this change. Please use ApolloLink exported from @apollo/client and there shouldn't be an issue.

import React from "react";
import { registerRootComponent } from "expo";
import Amplify from "aws-amplify";
import AppSyncConfig from "./src/aws-exports";
import { createAuthLink } from "aws-appsync-auth-link";
import { createSubscriptionHandshakeLink } from "aws-appsync-subscription-link";
import {
  ApolloLink,
  ApolloClient,
  ApolloProvider,
  InMemoryCache,
} from "@apollo/client";
import App from "./App";

Amplify.configure(AppSyncConfig);

const url = AppSyncConfig.aws_appsync_graphqlEndpoint;
const region = AppSyncConfig.aws_appsync_region;
const auth = {
  type: AppSyncConfig.aws_appsync_authenticationType,
  apiKey: AppSyncConfig.aws_appsync_apiKey,
};

const link = ApolloLink.from([
  createAuthLink({ url, region, auth }),
  createSubscriptionHandshakeLink({ url, region, auth }),
]);

const client = new ApolloClient({
  link,
  cache: new InMemoryCache(),
});

const WithProvider = () => (
  <ApolloProvider client={client}>
    <App />
  </ApolloProvider>
);

export default registerRootComponent(WithProvider);