vic / apollo-phoenix-websocket

An Apollo networkInterface for executing GraphQL queries via Phoenix Channels
Apache License 2.0
91 stars 9 forks source link

Execute afterware function. #3

Closed conor-mac-aoidh closed 7 years ago

conor-mac-aoidh commented 7 years ago

Small fix that checks whether to execute a middleware or afterware method

conor-mac-aoidh commented 7 years ago

@vic I would welcome feedback on this commit

The reason for resolve instead of reject is to mirror the default apollo-client, which calls the afterware regardless of the response type. This enables afterware to check the response, and throw an error if required. This solves the issue mentioned here and enables afterware such as:

export function applyAfterware({response, options}, next) {
  if (!!response.error && response.error === 'Unauthorized') {
    throw new Error('Unauthorized');
  }
  next();
}
vic commented 7 years ago

Looks good to me, thank you very much. Merging 🎉