How to use the aws-appsync.createAppSyncLink function in aws-appsync

To help you get started, we’ve selected a few aws-appsync examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gnemtsov / ab-app2 / frontend / src / index.jsx View on Github external
return previousContext;
    }
});

const errorLink = 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}`);
});

AWS.config.update({ region: "eu-west-1" });
const appSyncLink = createAppSyncLink({
    url:
        process.env.NODE_ENV === "development"
            ? process.env.REACT_APP_LOCAL_APPSYNC_URL
            : "https://vipqqwuxvfdn7gaos7u4aav3su.appsync-api.eu-west-1.amazonaws.com/graphql",
    region: "eu-west-1",
    auth: {
        type: AUTH_TYPE.AWS_IAM,
        credentials: new AWS.CognitoIdentityCredentials({
            IdentityPoolId: "eu-west-1:dffe4e03-9e89-4118-911f-ee327e257d9f"
        })
    }
});

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

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