How to use the @aws-amplify/core.PubSub function in @aws-amplify/core

To help you get started, we’ve selected a few @aws-amplify/core 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 aws-amplify / amplify-js / packages / aws-amplify-angular / src / __tests__ / providers / amplify.service.spec.ts View on Github external
it('...should be returning Amplify.PubSub', inject([AmplifyService], (service: AmplifyService) => {
      const myPubSub =  service.pubsub();
      expect(myPubSub).toEqual(Amplify.PubSub);
    }));
github aws-amplify / amplify-js / packages / api / src / API.ts View on Github external
private _graphqlSubscribe({
		query,
		variables,
		authMode: defaultAuthenticationType,
	}: GraphQLOptions): Observable {
		const {
			aws_appsync_region: region,
			aws_appsync_graphqlEndpoint: appSyncGraphqlEndpoint,
			aws_appsync_authenticationType,
			aws_appsync_apiKey: apiKey,
			graphql_headers = () => ({}),
		} = this._options;
		const authenticationType =
			defaultAuthenticationType || aws_appsync_authenticationType || 'AWS_IAM';

		if (Amplify.PubSub && typeof Amplify.PubSub.subscribe === 'function') {
			return Amplify.PubSub.subscribe('', {
				provider: INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER,
				appSyncGraphqlEndpoint,
				authenticationType,
				apiKey,
				query: print(query),
				region,
				variables,
				graphql_headers,
			});
		} else {
			logger.debug('No pubsub module applied for subscription');
			throw new Error('No pubsub module applied for subscription');
		}
	}
github aws-amplify / amplify-js / packages / api-graphql / src / GraphQLAPI.ts View on Github external
private _graphqlSubscribe({
		query,
		variables,
		authMode: defaultAuthenticationType,
	}: GraphQLOptions): Observable {
		const {
			aws_appsync_region: region,
			aws_appsync_graphqlEndpoint: appSyncGraphqlEndpoint,
			aws_appsync_authenticationType,
			aws_appsync_apiKey: apiKey,
			graphql_headers = () => ({}),
		} = this._options;
		const authenticationType =
			defaultAuthenticationType || aws_appsync_authenticationType || 'AWS_IAM';

		if (Amplify.PubSub && typeof Amplify.PubSub.subscribe === 'function') {
			return Amplify.PubSub.subscribe('', {
				provider: INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER,
				appSyncGraphqlEndpoint,
				authenticationType,
				apiKey,
				query: print(query),
				region,
				variables,
				graphql_headers,
			});
		} else {
			logger.debug('No pubsub module applied for subscription');
			throw new Error('No pubsub module applied for subscription');
		}
	}
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Categories.js View on Github external
import Amplify from '@aws-amplify/core';

const Auth = Amplify.Auth;
const API = Amplify.API;
const Analytics = Amplify.Analytics;
const Storage = Amplify.Storage;
const PubSub = Amplify.PubSub;
const Interactions = Amplify.Interactions;

export { Auth, API, Analytics, Storage, PubSub, Interactions };
github aws-amplify / amplify-js / packages / api / src / API.ts View on Github external
import { v4 as uuid } from 'uuid';

const logger = new Logger('API');

export const graphqlOperation = (query, variables = {}) => ({ query, variables });

/**
 * Export Cloud Logic APIs
 */
export default class APIClass {
    /**
     * @private
     */
    private _options;
    private _api = null;
    private _pubSub = Amplify.PubSub;

    /**
     * Initialize Storage with AWS configuration
     * @param {Object} options - Configuration object for storage
     */
    constructor(options) {
        this._options = options;
        logger.debug('API Options', this._options);
    }

    public getModuleName() {
        return 'API';
    }

    /**
     * Configure API part with aws configurations
github aws-amplify / amplify-js / packages / api / src / API.ts View on Github external
'x-amz-subscriber-id': this.clientIdentifier
                        } : {})
                    };

                    try {
                        const {
                            extensions: { subscription },

                        } = await this._graphql({ query, variables }, additionalheaders);

                        const { newSubscriptions } = subscription;

                        const newTopics =
                            Object.getOwnPropertyNames(newSubscriptions).map(p => newSubscriptions[p].topic);

                        const observable = Amplify.PubSub.subscribe(newTopics, subscription);

                        handle = observable.subscribe({
                            next: (data) => observer.next(data),
                            complete: () => observer.complete(),
                            error: (data) => {
                                const error = { ...data };
                                if (!error.errors) {
                                    error.errors = [{
                                        ...new GraphQLError('Network Error')
                                    }];
                                }
                                observer.error(error);
                            }
                        });

                    } catch (error) {
github aws-amplify / amplify-js / packages / aws-amplify / src / index.ts View on Github external
JS,
	ClientDevice,
	Signer,
	I18n,
	ServiceWorker,
} from '@aws-amplify/core';

export default Amplify;

Amplify.Auth = Auth;
Amplify.Analytics = Analytics;
Amplify.API = API;
Amplify.Storage = Storage;
Amplify.I18n = I18n;
Amplify.Cache = Cache;
Amplify.PubSub = PubSub;
Amplify.Logger = Logger;
Amplify.ServiceWorker = ServiceWorker;
Amplify.Interactions = Interactions;
Amplify.UI = UI;
Amplify.XR = XR;
Amplify.Predictions = Predictions;

export {
	Auth,
	Analytics,
	Storage,
	API,
	PubSub,
	I18n,
	Logger,
	Hub,
github aws-amplify / amplify-js / packages / api / src / API.ts View on Github external
private _graphqlSubscribe({ query, variables }: GraphQLOptions): Observable {
        if (Amplify.PubSub && typeof Amplify.PubSub.subscribe === 'function') {
            return new Observable(observer => {

                let handle = null;

                (async () => {
                    const {
                        aws_appsync_authenticationType: authenticationType,
                    } = this._options;
                    const additionalheaders = {
                        ...(authenticationType === 'API_KEY' ? {
                            'x-amz-subscriber-id': this.clientIdentifier
                        } : {})
                    };

                    try {
                        const {