From 437a64ec74173eb58d522748d5b3088115b05e1e Mon Sep 17 00:00:00 2001 From: Oleg Ilyenko Date: Mon, 19 Sep 2016 23:45:19 +0200 Subject: [PATCH] Provide variables as a JSON `Object` instead of a `String` --- src/components/GraphiQL.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/GraphiQL.js b/src/components/GraphiQL.js index bde82cd98c2..33db24731fc 100644 --- a/src/components/GraphiQL.js +++ b/src/components/GraphiQL.js @@ -475,7 +475,19 @@ export class GraphiQL extends React.Component { _fetchQuery(query, variables, operationName, cb) { const fetcher = this.props.fetcher; - const fetch = fetcher({ query, variables, operationName }); + let jsonVariables = null; + + try { + jsonVariables = JSON.parse(variables); + } catch (error) { + jsonVariables = null; + } + + const fetch = fetcher({ + query, + variables: jsonVariables, + operationName + }); if (isPromise(fetch)) { // If fetcher returned a Promise, then call the callback when the promise