graphql-ide icon indicating copy to clipboard operation
graphql-ide copied to clipboard

POST variables not serializing properly

Open erikreedstrom opened this issue 8 years ago • 5 comments

The request payload of when using POST method passes variables as JSON string rather than object.

Expected

{
  "query": "mutation UpsertCustomer...",
  "variables": {
    "homepolish_id": 421,
    "input":{ "age": 36 }
  },
  "operationName":"UpsertCustomer"
}

Actual

{
  "query": "mutation UpsertCustomer...",
  "variables": "{"homepolish_id": 421, "input": {"age": 36}}",
  "operationName": "UpsertCustomer"
}

erikreedstrom avatar Nov 02 '17 15:11 erikreedstrom

This is a major issue. It makes GraphQL IDE.app completely useless for any queries that include variables.

lilyball avatar Dec 06 '17 19:12 lilyball

I guess not completely useless. It turns out GET works. I was told to use POST with our GraphQL server but apparently that's not actually a requirement.

lilyball avatar Dec 06 '17 19:12 lilyball

The following diff appears to fix the bug:

diff --git a/src/app/components/project-detail/project-detail.jsx b/src/app/components/project-detail/project-detail.jsx
index 223b2c4..c923713 100644
--- a/src/app/components/project-detail/project-detail.jsx
+++ b/src/app/components/project-detail/project-detail.jsx
@@ -509,6 +509,17 @@ export default ({store, actionCreators, selectors, queries, factories, history,
                 return
             }
 
+            let queryVariables = null
+            try {
+                const variablesStr = query.get('variables')
+                if (variablesStr != '') {
+                    queryVariables = JSON.parse(variablesStr)
+                }
+            } catch (e) {
+                swal("Error", "The query variables are not valid JSON.", "error")
+                return
+            }
+
             const startTime = moment()
 
             this.props.tabsUpdate({
@@ -535,7 +546,7 @@ export default ({store, actionCreators, selectors, queries, factories, history,
                 params: {
                     query: query.get('query'),
                     operationName: query.get('operationName'),
-                    variables: query.get('variables')
+                    variables: queryVariables
                 }
             })
 

lilyball avatar Dec 06 '17 19:12 lilyball

Unfortunately for me this app is useless because of this bug.

aponski avatar Mar 15 '18 08:03 aponski

Any update on this issue?

fbjork avatar Apr 19 '18 02:04 fbjork