Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save montalvomiguelo/647c99313171a496a486630d35087b69 to your computer and use it in GitHub Desktop.
Save montalvomiguelo/647c99313171a496a486630d35087b69 to your computer and use it in GitHub Desktop.
# Insomnia Configuration
## Run the test query
{
shop {
id
name
}
}
# Query Structure Examples
## QueryRoot objects
{
shop {
id
name
description
email
}
}
## 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: "gqlcustomer@gmail.com"
}
)
{
customer {
id
firstName
lastName
email
}
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
email
}
}
}
}
# 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