Created
November 2, 2018 15:29
-
-
Save shopifypartners/24783acc1242db8757b0216c8154eacf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Insomnia Configuration | |
## Run the test query | |
{ | |
shop { | |
id | |
name | |
} | |
} | |
# Query Structure Examples | |
## QueryRoot objects | |
{ | |
shop { | |
id | |
name | |
description | |
} | |
} | |
## Connections and edges | |
{ | |
products(first:3) { | |
edges { | |
node { | |
id | |
handle | |
variants(first:3) { | |
edges { | |
node { | |
id | |
displayName | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
## Filtering connections using the query parameter | |
{ | |
orders(first:10, query:"fulfillment_status:fulfilled") { | |
edges { | |
node { | |
id | |
name | |
displayFulfillmentStatus | |
} | |
} | |
} | |
} | |
## Single Object by ID | |
{ | |
product(id: "gid://shopify/Product/1730990145609") { | |
id | |
handle | |
variants (first:5) { | |
edges { | |
node { | |
title | |
} | |
} | |
} | |
} | |
} | |
# Mutation Structure Examples | |
## Basics and Inputs | |
mutation { | |
customerCreate ( | |
input: { | |
firstName: "GraphQL", | |
lastName: "Customer", | |
email: "[email protected]" | |
} | |
) | |
{ | |
customer { | |
id | |
firstName | |
lastName | |
} | |
userErrors { | |
field | |
message | |
} | |
} | |
} | |
## Inputs v2 | |
mutation { | |
draftOrderCreate( | |
input: { | |
customerId: "gid://shopify/Customer/870935789641", | |
lineItems: [ | |
{ | |
title: "My custom line item!", | |
quantity: 1, | |
originalUnitPrice: 10 | |
}, | |
{ | |
title: "My SECOND custom line item!", | |
quantity: 3, | |
originalUnitPrice: 3.99 | |
} | |
] | |
} | |
) | |
{ | |
userErrors { | |
field | |
message | |
} | |
draftOrder { | |
id | |
customer { | |
id | |
} | |
} | |
} | |
} | |
# GraphQL Variables | |
## Variables | |
### query | |
query getDraftOrderByID($id: ID!) { | |
draftOrder (id: $id) { | |
totalPrice | |
lineItems (first: 5) { | |
edges { | |
node { | |
originalUnitPrice | |
quantity | |
} | |
} | |
} | |
} | |
} | |
### variables | |
{ | |
"id": "gid://shopify/DraftOrder/135477690441" | |
} | |
# Pagination | |
## What is PageInfo? | |
### query | |
query getFirstOrders($numOrders: Int, $numLineItems: Int) | |
{ | |
orders(first:$numOrders) { | |
pageInfo { | |
hasNextPage | |
} | |
edges { | |
node { | |
id | |
lineItems (first:$numLineItems) { | |
edges { | |
node { | |
id | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
### variables | |
{ | |
"numOrders": 10, | |
"numLineItems": 5 | |
} | |
## The Cursor | |
### query | |
query getFirstOrdersCursor($numOrders: Int, $numLineItems: Int) | |
{ | |
orders(first:$numOrders) { | |
pageInfo { | |
hasNextPage | |
} | |
edges { | |
cursor | |
node { | |
id | |
lineItems (first:$numLineItems) { | |
edges { | |
node { | |
id | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
### variables | |
{ | |
"numOrders": 10, | |
"numLineItems": 5 | |
} | |
## The Cursor v2 | |
### query | |
query getFirstOrdersWithCursor($numOrders: Int, $numLineItems: Int, $cursor: String) | |
{ | |
orders(first:$numOrders, after:$cursor) { | |
pageInfo { | |
hasNextPage | |
} | |
edges { | |
cursor | |
node { | |
id | |
lineItems (first:$numLineItems) { | |
edges { | |
node { | |
id | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
### variables | |
{ | |
"numOrders": 10, | |
"numLineItems": 5, | |
"cursor": "eyJsYXN0X2lkIjo2OTA1NzE5MzU4MTcsImxhc3RfdmFsdWUiOiIyMDE3LTExLTIxIDE0OjE3OjAzIn0=" | |
} | |
# Advanced | |
## Fragments - Handle Multiple Cases | |
### query | |
query getLineItemLocationId($id: ID!) { | |
node(id: $id) { | |
... on LineItem { | |
id | |
variant { | |
inventoryItem { | |
inventoryLevels(first: 1) { | |
edges { | |
node { | |
location { | |
id | |
name | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
### variables | |
{ | |
"id": "gid://shopify/LineItem/1588425490505" | |
} | |
## Multiple Queries - One Request | |
mutation { | |
VipGold: customerUpdate( | |
input: { | |
id: "gid://shopify/Customer/870935789641", | |
tags: ["Gold"] | |
} | |
) | |
{ | |
customer { | |
tags | |
} | |
} | |
VipPlatinum: customerUpdate( | |
input: { | |
id: "gid://shopify/Customer/870602047561", | |
tags: ["Platinum"] | |
} | |
) | |
{ | |
customer { | |
tags | |
} | |
} | |
VipDiamond: customerUpdate( | |
input: { | |
id: "gid://shopify/Customer/870602014793", | |
tags: ["Diamond"] | |
} | |
) | |
{ | |
customer { | |
tags | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I create a draft order using rest API. I am able to add custom discount on it. Now, when I go to my shop's UI, I can add automatic discounts.
I want to replicate this behavious using graphql api, I think I can use mutation at L94 on this node: https://shopify.dev/docs/api/admin-graphql/2024-01/queries/automaticDiscount#field-discountautomatic-discountautomatic for the same. Can anyone help me figure out the next steps?