Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('...should be returning Amplify.PubSub', inject([AmplifyService], (service: AmplifyService) => {
const myPubSub = service.pubsub();
expect(myPubSub).toEqual(Amplify.PubSub);
}));
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');
}
}
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');
}
}
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 };
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
'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) {
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,
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 {