I cloned this React dashboard and adapted it to my needs then i wanted to fetch data from graphql and display it in a table ( orders and products tables , I’ll continue talking about orders ) then when the user click on a specific button it opens a page that have all the specific details about the order he chooses! an id will be taken from the first query ( orders that display many orders ) and will be passed as a variable to the 2nd query with is order to display that order details . i wanna Know how to display the data from the first query then the specific data for a single order
this is how the UI should look ( it is changed but I just wanted to clarify the idea more ) :
orders list :
orders details :
graphql :
an input type has been created that is likely to be reused.(PaginationInput)
query :
query Orders($input1: PaginationInput) {
Orders(input: $input1){
pageInfo {
hasNextPage
hasPreviousPage
}
edges{
cursor
node {
id
closed
email
createdAt
updatedAt
cancelledAt
displayFinancialStatus
displayFulfillmentStatus
lineItems{
edges{
node {
customAttributes{
key
value
}
id
quantity
title
variant{
id
image {
altText
id
src
}
title
weight
weightUnit
price
}
}
}
}
phone
subtotalPrice
totalPrice
totalRefunded
totalTax
processedAt
}
}
}
}
query Order($id: ID!){
Order (id: $id){
id
displayFinancialStatus
displayFulfillmentStatus
email
id
createdAt
subtotalPrice
totalRefunded
totalShippingPrice
totalPrice
totalTax
updatedAt
lineItems{
edges {
node {
customAttributes{
key
value
}
quantity
title
id
variant{
id
title
weight
weightUnit
price
image {
src
}
}
}
}
}
shippingAddress {
address1
address2
city
company
country
countryCode
firstName
id
lastName
name
phone
province
provinceCode
zip
}
}
}
query variables example :
{
"input1": {
"num": 30
},
"id": "gid://shopify/Order/order_id_here"
}
i’m still new to graphql so i don’t know ho to do this !
2
Answers
I don’t know about graphql, but I can help you with the UI part, for showing data for a particular order.
You have a table, and the table has a unique index key for each row. From the Database, we can distinguish all the rows using this key. so, while showing the table you might use node packages for react-tables or the traditional method,
Apollo Client is a pretty good library for React to use graphql to communicate with a backend server.
Studying Apollo Client’s useQuery hook should provide you what you need.
Eventually, something along the lines of
You can then display
data
in your UI.I do recommend familiarising yourself with how Apollo Client works first with a smaller example application before attempting to call a large query like
Orders
you have here.