1

I'm running an apollo-server-express as a gateway application. Setting up a few underlying GraphQL Applications with makeRemoteExecutableSchema and an apollo-link-http.

Usually every call just works. If an error is part of the response and data is null it also works. But if data contains just the data and errors contains an error. Data will be passed though but errors is empty

const headerSet = setContext((request, previousContext) => {
  return setHeaders(previousContext);
});

const errorLink = onError(({ response, forward, operation, graphQLErrors, networkError }) => {
  if (graphQLErrors) {
    graphQLErrors.map((err) => {
      Object.setPrototypeOf(err, Error.prototype);
    });
  }
  if (networkError) {
    logger.error(networkError, 'A wild network error appeared');
  }
});

const httpLink = new HttpLink({
  uri: remoteURL,
  fetch
});

const link = headerSet.concat(errorLink).concat(httpLink);

Example A "Working Example":

Query

{
  checkName(name: "namethatistoolooooooong")
}

Query Response

{
  "errors": [
    {
      "message": "name is too long, the max length is 20 characters",
      "path": [
        "checkName"
      ],
      "extensions": {
        "code": "INPUT_VALIDATION_ERROR"
      }
    }
  ],
  "data": null
}

Example B "Errors hidden":

Query

mutation inviteByEmail {
  invite(email: "invalid!!!~~~test!--@example.com") {
    status
  }
}

Response from remote service (httpLink)

response.errors and graphQLErrors in onError method also contains the error

{
  "errors": [
    {
      "message": "Email not valid",
      "path": [
        "invite"
      ],
      "extensions": {
        "code": "INPUT_VALIDATION_ERROR"
      }
    }
  ],
  "data": {
    "invite": {
      "status": null
    }
  }
}

Response

{
  "data": {
    "invite": {
      "status": null
    }
  }
}

According to graphql spec I would have expected the errors object to not be hidden if it is part of the response

https://graphql.github.io/graphql-spec/June2018/#sec-Errors

If the data entry in the response is present (including if it is the value null), the errors entry in the response may contain any errors that occurred during execution. If errors occurred during execution, it should contain those errors.

DeltaM
  • 11
  • 1

0 Answers0