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

Quotes on Keys #1

Open
robindata-gmbh opened this issue Nov 15, 2018 · 3 comments
Open

Quotes on Keys #1

robindata-gmbh opened this issue Nov 15, 2018 · 3 comments

Comments

@robindata-gmbh
Copy link

How I set in response the keys from JSON in Quotes?

https://graphql.org/learn/serving-over-http/

@topliceanu
Copy link
Owner

Hi @robindata-gmbh I'm afraid I don't understand what the issue is! Can you please add more details!

@robindata-gmbh
Copy link
Author

Hi,

on https://graphql.org/learn/serving-over-http/

Query variables can be sent as a JSON-encoded string in an additional query parameter called variables.

Your example: curl -XPOST http://vm:8080/graphql -d 'mutation {createPost(user:1,title:"p1",body:"b1"){id}}'

When we use Relay or Apollo as client, that used like graphql.org, than is your CURL not right.

mutation {createPost(user:1,title:"p1",body:"b1"){id}}

graphql.org:

{
    "query": "mutation function(foo, bar)",
    "variables": {},
    "operationName":"name"
}

its okay, i write a little code:

        var apolloQuery map[string]interface{}

	if err := json.Unmarshal(body, &apolloQuery); err != nil { 
		w.WriteHeader(422) 
		if err := json.NewEncoder(w).Encode(err); err != nil {
			log.Fatalln("Error GraphQL unmarshalling data", err)
			w.WriteHeader(http.StatusInternalServerError)
			return
		}
	}

	query := apolloQuery["query"]
	variables := apolloQuery["variables"]
	result := graphql.Do(graphql.Params{
		Schema:         freeschema,
		RequestString:  query.(string),
		VariableValues: variables.(map[string]interface{}),
		Context:        context.WithValue(context.Background(), "httprequest", r),
	})

It's runing with:

curl -X POST http://localhost:5000/xql -H "Content-Type: application/json"  -d \
'{
	"operationName":"tokenAuth",
	"query": "mutation TokenAuth($user: TokenAuthInput!) { tokenAuth(input: $user) { token }}",
        "variables": { "user": { "email": "email@email.com", "password": "password" } }
}'

currently have I a error: "Syntax Error GraphQL request (2:3) Expected Name, found String "query...."?

The problem, your interface does not accept a real json, and quoted keys in the payload are considered to be errors. https://www.w3schools.com/js/js_json_syntax.asp

Syntax Error GraphQL request (2:2) Expected Name, found String ....

@topliceanu
Copy link
Owner

Hey @robindata-gmbh sorry for the, I was away on holiday. Thanks for the detailed explanation!
I know it's a big ask, but if you can create a Pull Request with an example and the fix, something that I can run locally, that would help me a lot. I'll merge everything afterwards.
Thanks

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

2 participants