How to use the @aws-amplify/api.getGraphqlOperationType function in @aws-amplify/api

To help you get started, we’ve selected a few @aws-amplify/api 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-react / src / API / GraphQL / Connect.js View on Github external
!API ||
			typeof API.graphql !== 'function' ||
			typeof API.getGraphqlOperationType !== 'function'
		) {
			throw new Error(
				'No API module found, please ensure @aws-amplify/api is imported'
			);
		}

		const hasValidQuery =
			query && API.getGraphqlOperationType(query) === 'query';
		const hasValidMutation =
			mutation && API.getGraphqlOperationType(mutation) === 'mutation';
		const hasValidSubscription =
			subscription &&
			API.getGraphqlOperationType(subscription.query) === 'subscription';

		if (!hasValidQuery && !hasValidMutation && !hasValidSubscription) {
			console.warn('No query, mutation or subscription was specified');
		}

		if (hasValidQuery) {
			try {
				data = null;

				const response = await API.graphql({ query, variables });

				data = response.data;
			} catch (err) {
				data = err.data;
				errors = err.errors;
			}
github aws-amplify / amplify-js / packages / aws-amplify-react / src / API / GraphQL / Connect.js View on Github external
} = this.props;

		let { data, mutation: mutationProp, errors } = this.getDefaultState();

		if (
			!API ||
			typeof API.graphql !== 'function' ||
			typeof API.getGraphqlOperationType !== 'function'
		) {
			throw new Error(
				'No API module found, please ensure @aws-amplify/api is imported'
			);
		}

		const hasValidQuery =
			query && API.getGraphqlOperationType(query) === 'query';
		const hasValidMutation =
			mutation && API.getGraphqlOperationType(mutation) === 'mutation';
		const hasValidSubscription =
			subscription &&
			API.getGraphqlOperationType(subscription.query) === 'subscription';

		if (!hasValidQuery && !hasValidMutation && !hasValidSubscription) {
			console.warn('No query, mutation or subscription was specified');
		}

		if (hasValidQuery) {
			try {
				data = null;

				const response = await API.graphql({ query, variables });
github aws-amplify / amplify-js / packages / aws-amplify-react / src / API / GraphQL / Connect.js View on Github external
let { data, mutation: mutationProp, errors } = this.getDefaultState();

		if (
			!API ||
			typeof API.graphql !== 'function' ||
			typeof API.getGraphqlOperationType !== 'function'
		) {
			throw new Error(
				'No API module found, please ensure @aws-amplify/api is imported'
			);
		}

		const hasValidQuery =
			query && API.getGraphqlOperationType(query) === 'query';
		const hasValidMutation =
			mutation && API.getGraphqlOperationType(mutation) === 'mutation';
		const hasValidSubscription =
			subscription &&
			API.getGraphqlOperationType(subscription.query) === 'subscription';

		if (!hasValidQuery && !hasValidMutation && !hasValidSubscription) {
			console.warn('No query, mutation or subscription was specified');
		}

		if (hasValidQuery) {
			try {
				data = null;

				const response = await API.graphql({ query, variables });

				data = response.data;
			} catch (err) {