Query with variables not returning as expected. #589
Replies: 5 comments 2 replies
-
Hi, please post the code generating your GraphQL request (and the objects used with it), that's commonly where the issues are and where there is a difference in using this lib compared to bare GraphQL testing UIs.... |
Beta Was this translation helpful? Give feedback.
-
Hi @rose-a, Thanks for your response. Here's the code. public class QueryOrderLineItemsByOrderIdAndCursor
{
protected string _orderId;
protected int _numberOfRecords;
public string? Cursor { get; set; }
public int EstimatedQueryCost { get; set; } = 10;
public string Query()
{
return @"query($orderId: ID!, $numRecords: Int!, $cursor:String) {
order(id: $orderId) {
lineItems(first:$numRecords, after: $cursor) {
edges {
node {
discountedTotalSet {
shopMoney {
amount
}
}
id
discountedUnitPriceSet {
shopMoney {
amount
}
}
originalTotalSet {
shopMoney {
amount
}
}
originalUnitPriceSet {
shopMoney {
amount
}
}
quantity
variant {
id
}
totalDiscountSet {
shopMoney {
amount
}
}
}
}
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
}
}
}
}";
}
public object Variables()
{
return new { numRecords = _numberOfRecords, cursor = Cursor, orderId = _orderId };
}
public object UpdateCursor(string cursor)
{
Cursor = cursor;
return Variables();
}
}
|
Beta Was this translation helpful? Give feedback.
-
This is the Response Type [DataContract]
public class OrderResponse
{
[DataMember(Name = "order")]
public Order Order { get; set; }
} I've used that response type successfully when I've queried an order without using variables (see below). It appears to be something to do with how the variables are handled. query {
order(id: "gid://shopify/Order/4993391231162") {
lineItems(first:5) {
edges {
node {
discountedTotalSet {
shopMoney {
amount
}
}
id
discountedUnitPriceSet {
shopMoney {
amount
}
}
originalTotalSet {
shopMoney {
amount
}
}
originalUnitPriceSet {
shopMoney {
amount
}
}
quantity
variant {
id
}
totalDiscountSet {
shopMoney {
amount
}
}
}
}
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
}
}
} |
Beta Was this translation helpful? Give feedback.
-
The response that's coming back is this: {"data":{"order":null},"extensions":{"cost":{"requestedQueryCost":38,"actualQueryCost":1,"throttleStatus":{"maximumAvailable":10000.0,"currentlyAvailable":9999,"restoreRate":500.0}}}} |
Beta Was this translation helpful? Give feedback.
-
OK, I suspected it to be a deserialization problem (which is a quite common mistake with this library), but since the server does in fact return I don't see any glaring mistakes, you could try to intercept the request and see what the variables object coming out of your c# app looks like... Perhaps the cursor is not |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm using the client to query Shopify's api. I've successfully performed a number of queries, both for individual items and collections. However, I'm having issues with the following query and I'm stumped. The query works as expected if I use Shopify's GraphQL Testing App. The query is:
And it takes the following variables:
It successfully returns without errors but the data is empty (null). I've performed similar queries but without the variables and they have return the order by id correctly. Any assistance would be appreciated.
Thanks
Mat
Beta Was this translation helpful? Give feedback.
All reactions