0

We are using Apollo Angular Client to call an Apollo Server. I am grouping together two queries. One of them fails.

On the server side, one of the resolvers throws an error.

throw new UserInputError("ERR_MSG", { "message":"addtional info"})

How am I supposed to handle the response on the client side when one of the calls fails? I want to use the data that worked from one query and show an error message for the data that failed.

this.apollo.watchQuery({
   query: gql(query),
   variables: { a: 'a' }
   }).valueChanges.subscribe(
   (response) => {
   let a = resp.data?.Query1;
   let b = resp.data?.Query2;
   },
   (err) => {
   // always get here with only the one error
   }
);

I'm not even sure if this is a server side issue or client side issue? I'm guessing I did something wrong SERVER SIDE because I don't even see the successful data passed back in the playground.

1 Answers1

0

My issue did turn out to be server side. Although many articles talked about adding null to the schema, we are letting the build create our schema automatically from classes. So to solve my issue, I had to add nullable to all my queries. Once added, my combined query returns data for successes and null for failures along with an error object.

@Query(() => [MyClass]**, { nullable: true }**)
Dharman
  • 30,962
  • 25
  • 85
  • 135