Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 };
};
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();
}
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;
}
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;
}
_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) {
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);
}
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);
}
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);
}
};
_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;