How to use the apollo-client.ApolloError function in apollo-client

To help you get started, we’ve selected a few apollo-client 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 mirumee / saleor-storefront / src / @sdk / index.ts View on Github external
const handleDataErrors = (
  mapFn: MapFn | WatchMapFn,
  data: TData,
  apolloErrors?: readonly GraphQLError[]
) => {
  // INFO: user input errors will be moved to graphql errors
  const userInputErrors = getErrorsFromData(data);
  const errors =
    apolloErrors || userInputErrors
      ? new ApolloError({
          extraInfo: userInputErrors,
          graphQLErrors: apolloErrors,
        })
      : null;

  if (errors && isDataEmpty(data)) {
    return { errors };
  }

  const result = getMappedData(mapFn, data);

  return { data: result };
};
github apollographql / react-apollo / packages / hooks / src / data / MutationData.ts View on Github external
private onMutationCompleted(
    response: ExecutionResult,
    mutationId: number
  ) {
    const { onCompleted, ignoreResults } = this.getOptions();

    const { data, errors } = response;
    const error =
      errors && errors.length > 0
        ? new ApolloError({ graphQLErrors: errors })
        : undefined;

    const callOncomplete = () =>
      onCompleted ? onCompleted(data as TData) : null;

    if (this.isMostRecentMutation(mutationId) && !ignoreResults) {
      this.updateResult({
        called: true,
        loading: false,
        data,
        error
      });
    }
    callOncomplete();
  }
github Innovic-io / angular-nestjs-rendering / src / server / modules / pets / pets.resolvers.ts View on Github external
async getPetById(obj, { _id }, context?, info?) {

    if (!ObjectID.isValid(_id)) {
      throw new ApolloError(WRONG_ID_ERROR);
    }

    const result = await this.ownerService.findByPetId(_id);

    if (!result) {
      return null;
    }
    const [ pet ] = result.pets;

    return pet;
  }
github MadRabbit / graphql-mock / src / mock.ts View on Github external
fail(error: any | any[] | string) {
    const errors = typeof error === 'string' ? [{ message: error }] : error;

    this.results.error = error instanceof ApolloError ? error : new ApolloError({
      graphQLErrors: Array.isArray(errors) ? errors : [errors]
    });

    return this;
  }
github apollographql / react-apollo / packages / components / lib / react-components.esm.js View on Github external
_this.onMutationCompleted = function (response, mutationId) {
            var _a = _this.props, onCompleted = _a.onCompleted, ignoreResults = _a.ignoreResults;
            var data = response.data, errors = response.errors;
            var error = errors && errors.length > 0
                ? new ApolloError({ graphQLErrors: errors })
                : undefined;
            var callOncomplete = function () {
                return onCompleted ? onCompleted(data) : null;
            };
            if (_this.hasMounted &&
                _this.isMostRecentMutation(mutationId) &&
                !ignoreResults) {
                _this.setState({ loading: false, data: data, error: error }, callOncomplete);
            }
            else {
                callOncomplete();
            }
        };
        _this.onMutationError = function (error, mutationId) {
github Innovic-io / angular-nestjs-rendering / src / server / modules / pets / pets.resolvers.ts View on Github external
async updatePet(obj, pet: IPet, context?, info?) {

    if (!ObjectID.isValid(pet._id) || !ObjectID.isValid(pet.owner)) {
      throw new ApolloError(WRONG_ID_ERROR);
    }

    return await this.ownerService.updatePet(pet);
  }
github apollo-elements / apollo-elements / packages / mixins / apollo-mutation-mixin.js View on Github external
onCompletedMutation(response, mutationId) {
      const { data, errors = [] } = response;
      const error = errors.length ? new ApolloError({ graphQLErrors: errors }) : null;
      if (this.isMostRecentMutation(mutationId) && !this.ignoreResults) {
        this.loading = false;
        this.error = error;
        this.data = data;
      }
      return this.onCompleted(data);
    }
github eventespresso / event-espresso-core / assets / prototype / application / services / apollo / mutations / useEntityMutation.ts View on Github external
const onMutationComplete = (response: FetchResult, onCompleted: OnMutationCompletedFn): void => {
		const { data, errors } = response;
		const error = errors && errors.length > 0 ? new ApolloError({ graphQLErrors: errors }) : undefined;

		updateResult({
			called: true,
			loading: false,
			data,
			error,
		});

		if (typeof onCompleted === 'function') {
			onCompleted(data);
		}
	};
github apollographql / react-apollo / packages / components / lib / Query.js View on Github external
_this.getQueryResult = function (client) {
            var result = {
                data: Object.create(null),
            };
            Object.assign(result, observableQueryFields(_this.observableQuery));
            if (_this.props.skip) {
                result = tslib_1.__assign({}, result, { data: undefined, error: undefined, loading: false });
            }
            else {
                var currentResult = _this.observableQuery.getCurrentResult();
                var loading = currentResult.loading, partial = currentResult.partial, networkStatus = currentResult.networkStatus, errors = currentResult.errors;
                var error = currentResult.error, data = currentResult.data;
                data = data || Object.create(null);
                if (errors && errors.length > 0) {
                    error = new ApolloError({ graphQLErrors: errors });
                }
                Object.assign(result, { loading: loading, networkStatus: networkStatus, error: error });
                if (loading) {
                    var previousData = _this.previousResult
                        ? _this.previousResult.data
                        : {};
                    Object.assign(result.data, previousData, data);
                }
                else if (error) {
                    Object.assign(result, {
                        data: (_this.observableQuery.getLastResult() || {}).data,
                    });
                }
                else {
                    var fetchPolicy = _this.observableQuery.options.fetchPolicy;
                    var partialRefetch = _this.props.partialRefetch;