From 9581286871976205d2b6c24c48b07ee055ed24d1 Mon Sep 17 00:00:00 2001 From: Andy Edwards Date: Sun, 10 Jul 2016 22:32:24 -0500 Subject: [PATCH 1/3] fix password reset --- src/server/graphql/httpGraphQLHandler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/graphql/httpGraphQLHandler.js b/src/server/graphql/httpGraphQLHandler.js index 6891aae..5556755 100644 --- a/src/server/graphql/httpGraphQLHandler.js +++ b/src/server/graphql/httpGraphQLHandler.js @@ -5,7 +5,7 @@ export default async (req, res) => { // Check for admin privileges const {query, variables, ...newContext} = req.body; const authToken = req.user || {}; - const context = {authToken, context: newContext}; + const context = {authToken, ...newContext}; const result = await graphql(Schema, query, null, context, variables); if (result.errors) { console.log('DEBUG GraphQL Error:', result.errors); From 6c0885d55f1af992ab521721576a420ba571d668 Mon Sep 17 00:00:00 2001 From: Andy Edwards Date: Sun, 10 Jul 2016 23:02:23 -0500 Subject: [PATCH 2/3] fix error messages coming from http graphql requests --- src/server/graphql/httpGraphQLHandler.js | 9 ++++----- src/universal/utils/fetching.js | 10 +++------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/server/graphql/httpGraphQLHandler.js b/src/server/graphql/httpGraphQLHandler.js index 5556755..300fc1e 100644 --- a/src/server/graphql/httpGraphQLHandler.js +++ b/src/server/graphql/httpGraphQLHandler.js @@ -1,14 +1,13 @@ import Schema from './rootSchema'; import {graphql} from 'graphql'; +import {prepareClientError} from './models/utils'; export default async (req, res) => { // Check for admin privileges const {query, variables, ...newContext} = req.body; const authToken = req.user || {}; const context = {authToken, ...newContext}; - const result = await graphql(Schema, query, null, context, variables); - if (result.errors) { - console.log('DEBUG GraphQL Error:', result.errors); - } - res.send(result); + const result = await graphql(Schema, query, null, context, variables) + const {error} = prepareClientError(result) + res.send({data: result.data, error}) }; diff --git a/src/universal/utils/fetching.js b/src/universal/utils/fetching.js index 6a791f9..b7e82d5 100644 --- a/src/universal/utils/fetching.js +++ b/src/universal/utils/fetching.js @@ -32,11 +32,7 @@ export function getJSON(route) { // return Object.assign({}, ...(for (p of fields) {[p]: o[p]})); // } -export const getClientError = errors => { - if (!errors) { - return; - } - const error = errors[0].message; +export const getClientError = error => { if (!error || error.indexOf('{"_error"') === -1) { return {_error: 'Server query error'}; } @@ -63,6 +59,6 @@ export const fetchGraphQL = async graphParams => { body: serializedParams }); const resJSON = await res.json(); - const {data, errors} = resJSON; - return {data, error: getClientError(errors)}; + const {data, error} = resJSON; + return {data, error: getClientError(error)}; }; From 9a5df82d73670243840abc809879836dd8e33d4f Mon Sep 17 00:00:00 2001 From: Andy Edwards Date: Sun, 17 Jul 2016 12:34:26 -0500 Subject: [PATCH 3/3] don't send empty error to client --- src/server/graphql/httpGraphQLHandler.js | 8 +++++--- src/universal/utils/fetching.js | 9 ++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/server/graphql/httpGraphQLHandler.js b/src/server/graphql/httpGraphQLHandler.js index 300fc1e..705d654 100644 --- a/src/server/graphql/httpGraphQLHandler.js +++ b/src/server/graphql/httpGraphQLHandler.js @@ -7,7 +7,9 @@ export default async (req, res) => { const {query, variables, ...newContext} = req.body; const authToken = req.user || {}; const context = {authToken, ...newContext}; - const result = await graphql(Schema, query, null, context, variables) - const {error} = prepareClientError(result) - res.send({data: result.data, error}) + const result = await graphql(Schema, query, null, context, variables); + const {error} = prepareClientError(result); + const body = {data: result.data}; + if (error) body.error = error; + res.send(body); }; diff --git a/src/universal/utils/fetching.js b/src/universal/utils/fetching.js index b7e82d5..b2cf68b 100644 --- a/src/universal/utils/fetching.js +++ b/src/universal/utils/fetching.js @@ -33,10 +33,13 @@ export function getJSON(route) { // } export const getClientError = error => { - if (!error || error.indexOf('{"_error"') === -1) { - return {_error: 'Server query error'}; + if (error) { + if (error.indexOf('{"_error"') === -1) { + return {_error: 'Server query error'}; + } + return JSON.parse(error); } - return JSON.parse(error); + return null; }; export const prepareGraphQLParams = graphParams => {