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

GraphQL Endpoint #237

Closed
nickfthedev opened this issue Sep 27, 2023 · 5 comments
Closed

GraphQL Endpoint #237

nickfthedev opened this issue Sep 27, 2023 · 5 comments

Comments

@nickfthedev
Copy link

Hello there!
I saw that there is an GraphQL endpoint in the source code but i can't find out how to use it.

Maybe you can help?

@oliver006
Copy link
Collaborator

The PR that introduced the GraphQL endpoint (thx @weirdian2k3 !) has an example:
#228

@nickfthedev
Copy link
Author

@oliver006 Thank you

@weirdian2k3 Hello Ian, Thank you for creating this endpoint. However, the example above is not working in my case. I get the error "unacceptable". Maybe you stumbled across a similar error?

I did some research on this:
https://shopify.dev/docs/api/usage/response-codes

According to this the response code 406 means the following:
The requested resource is only capable of generating content not acceptable according to the Accept headers sent in the request.

func GraphQLTest(c echo.Context) error {
	// Get Access Token
	t, err := utils.GetAccessToken(c)
	if err != nil {
		fmt.Printf("Error: %s\n", err.Error())
		return c.String(500, "Token Error")
	}
	fmt.Printf("Token: %s\n", t.Token)
	// Endpoint Test
	client := goshopify.NewClient(utils.ShopifyApp, t.Shopname, t.Token)

	req := `mutation webPixelCreate($webPixel: WebPixelInput!) {
		webPixelCreate(webPixel: $webPixel) {
			userErrors {
				code
				field
				message
			}
			webPixel {
				settings
				id
			}
		}
	}`

	settings, err := json.Marshal(map[string]interface{}{
		"accountID": fmt.Sprintf("%d", 12121324),
	})

	if err != nil {
		fmt.Printf("Error: %v\n", err.Error())
		return c.String(500, " Error")
	}

	variables := map[string]interface{}{
		"webPixel": map[string]interface{}{
			"settings": string(settings),
		},
	}

	var foo struct {
	}

	err = client.GraphQL.Query(req, &variables, &foo)
	if err != nil {
		fmt.Printf("Error: %v\n", err.Error())
		return c.String(500, " Error")

	}
	return c.Render(http.StatusOK, "hello.html", map[string]interface{}{})
}

@weirdian2k3
Copy link

Sorry for taking so long to get back to you.
One thing I forgot to note is that you need to specify a newer version to use graphql, the default for this library isn't high enough

Something like

client := goshopifyNewClient("shop-name", "token", goshopify.WithVersion("2023-07"))

@nickfthedev
Copy link
Author

Sorry for taking so long to get back to you.
One thing I forgot to note is that you need to specify a newer version to use graphql, the default for this library isn't high enough

Something like

client := goshopifyNewClient("shop-name", "token", goshopify.WithVersion("2023-07"))

Hello Ian,

Thank you very much for your fast reply! I will try it out as soon as possible

@nickfthedev
Copy link
Author

It works! That was the thing I was missing. Thank you so much!

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

3 participants