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

shopify graphql admin api Message: slice doesn't exist in any of 1 places to unmarshal, Locations: [], Extensions: map[code:graphql_decode_error #152

Open
codeliger opened this issue Sep 6, 2024 · 1 comment

Comments

@codeliger
Copy link

codeliger commented Sep 6, 2024

I am following the Shopify GraphQL Admin API documentation on Orders here:
https://shopify.dev/docs/api/admin-graphql/2024-07/queries/orders

My first 3 retrieved orders work without an error. Then when retrieving again I get this error:
Message: slice doesn't exist in any of 1 places to unmarshal, Locations: [], Extensions: map[code:graphql_decode_error]

Here my my schema:

	var q struct {
		Orders struct {
			Edges []struct {
				Cursor string
				Node   struct {
					ID                       string
					Test                     bool
					Name                     string
					Email                    *string
					DisplayFinancialStatus   string
					DisplayFulfillmentStatus string
					ReturnStatus             string
					Note                     string
					ClientIP                 string
					Closed                   bool
					ClosedAt                 *time.Time
					CancelledAt              *time.Time
					CustomAttributes         []struct {
						Key   string
						Value string
					}
					Customer struct {
						Email string
					}
				}
			}
			PageInfo struct {
				EndCursor   string
				HasNextPage bool
			}
		} `graphql:"orders(first: $first, after: $after)"`
	}

Here is the WithDebug(true) schema response stored in the graphql.Errors object:

{
	"data": {
		"orders": {
			"edges": [
				{
					"cursor": "x==",
					"node": {
						"id": "gid://shopify/Order/x",
						"test": false,
						"name": "#1004",
						"email": null,
						"displayFinancialStatus": "PAID",
						"displayFulfillmentStatus": "UNFULFILLED",
						"returnStatus": "NO_RETURN",
						"note": "unfulfilled",
						"clientIp": "x",
						"closed": false,
						"closedAt": null,
						"cancelledAt": null,
						"customAttributes": [],
						"customer": null
					}
				},
				{
					"cursor": "x==",
					"node": {
						"id": "gid://shopify/Order/x",
						"test": false,
						"name": "#1005",
						"email": null,
						"displayFinancialStatus": "REFUNDED",
						"displayFulfillmentStatus": "FULFILLED",
						"returnStatus": "NO_RETURN",
						"note": "fulfilled then refunded (not returned)",
						"clientIp": "x",
						"closed": true,
						"closedAt": "2024-08-29T02:07:04Z",
						"cancelledAt": null,
						"customAttributes": [],
						"customer": null
					}
				},
				{
					"cursor": "x==",
					"node": {
						"id": "gid://shopify/Order/x",
						"test": false,
						"name": "#1006",
						"email": null,
						"displayFinancialStatus": "PAID",
						"displayFulfillmentStatus": "FULFILLED",
						"returnStatus": "IN_PROGRESS",
						"note": "fulfulled and return in progress",
						"clientIp": "x",
						"closed": false,
						"closedAt": null,
						"cancelledAt": null,
						"customAttributes": [],
						"customer": null
					}
				}
			],
			"pageInfo": {
				"endCursor": "x==",
				"hasNextPage": false
			}
		}
	},
	"extensions": {
		"cost": {
			"requestedQueryCost": 8,
			"actualQueryCost": 8,
			"throttleStatus": {
				"maximumAvailable": 2000.0,
				"currentlyAvailable": 1992,
				"restoreRate": 100.0
			}
		}
	}
}

I noticed that extensions was included in the response and assumed that the error was related so I attempted to add this structure at the root of the query which failed, then at the orders level of the query which failed:

Extensions struct {
	Cost struct {
		RequestedQueryCost int64
		ActualQueryCost    int64
		ThrottleStatus     struct {
			MaximumAvailable   int64
			CurrentlyAvailable int64
			RestoreRate        int64
		}
}

Extensions did not solve the error. Probably because it does not contain a slice.
I tried with and without pointers on multiple different optional object types and it didn't seem to make a difference either.

This issue may be related to #139

It works fine with QueryRaw and json.Unmarshal.

@hgiasac
Copy link

hgiasac commented Sep 7, 2024

First, the extensions field is an optional response. To get that data you need to use a custom option (docs).

I can't reproduce this issue locally. Maybe the server randomly returns an inconsistent response structure so the decoder can't parse the response.

If it's possible you can try again with this branch https://github.com/hasura/go-graphql-client/pull/141/files to see if the issue can be fixed

go get github.com/hasura/go-graphql-client@fix-unexpected-array-deserialization-error

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