Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POST variables not serializing properly #31

Open
erikreedstrom opened this issue Nov 2, 2017 · 5 comments
Open

POST variables not serializing properly #31

erikreedstrom opened this issue Nov 2, 2017 · 5 comments

Comments

@erikreedstrom
Copy link

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"
}
@lilyball
Copy link

lilyball commented Dec 6, 2017

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

@lilyball
Copy link

lilyball commented Dec 6, 2017

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
Copy link

lilyball commented Dec 6, 2017

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
                 }
             })
 

@aponski
Copy link

aponski commented Mar 15, 2018

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

@fbjork
Copy link

fbjork commented Apr 19, 2018

Any update on this issue?

lilyball pushed a commit to lilyball/graphql-ide that referenced this issue Nov 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants