Shopify API - get bulk products by collection id using graphQL - graphql

I need to fetch all products using Shopify API by collection id...
I tried:
mutation {
bulkOperationRunQuery(
query:"""
{
products(query: "tag:women OR collection:172173852808") {
edges{
node{
id
tags
images {
edges {
node {
id
originalSrc
}
}
}
variants(first:10) {
edges{
node{
id
price
compareAtPrice
image{
originalSrc
}
inventoryQuantity
selectedOptions{
name
value
}
sku
title
weight
weightUnit
}
}
}
}
}
}
}
"""
) {
bulkOperation {
id
status
}
userErrors {
field
message
}
}
}
Result Shopify gives me is just product with tags: women and there are no products from collection id 172173852808
How to run a query to get products from one or more specific connections?

If every product in that collection has the tag woman, just change your query to bulk download the collection and its products. Also, before you go and do a bulk query, verify it works without being a bulk query. That usually exposes the problems with the setup.

Related

GraphQL query filtering multiple relations

(From Strapi) I am trying to get all "acts" with a certain age (can return multiple) and with a certain place (can return multiple). I can't figure out how to filter that.
This is what I am trying in GraphQL-playground (works without the variables), but it says "Unknown argument "age" on field "Act.ages"." (and "place" respectively).
query GetActs ($age:Int, $place:String) {
acts {
data {
id
attributes {
Title
ages (age: $age) {
data {
id
attributes {
age
}
}
}
places (place: $place) {
data {
id
attributes {
place
}
}
}
}
}
}
}
I just ran into this same issue. I can't make out the error you're reporting, but here is what worked for me.
You can use filter at the collection level to drill down to nested fields for the corresponding attributes. This follows the GraphQL example at the bottom of this Strapi resource on filtering nested fields.
Solution
query GetActs ($age:Int, $place:String) {
acts (filters: {ages: {age: {eq: $age}}, places: {place: {eq: $place}}}) {
data {
id
attributes {
Title
ages {
data {
id
attributes {
age
}
}
}
places {
data {
id
attributes {
place
}
}
}
}
}
}
}

GraphQl request from Strapi only returning 10 items [duplicate]

I am using React with Strapi and GrapqQL in order to retreive my data from Strapi.
Seems that my query retrieves only maximum 10 items. The API is changed with this new version and I am not allowed to use first:100 in the query.
This link 1 is obsolete. I don't know if this is a policy from Strapi's or GraphQL's new version.
1 https://graphql.org/learn/pagination/
const REVIEWS = gql`
query GetReviews {
reviews (sort: "createdAt:desc") {
data{
id
attributes{
title
rating
body
createdAt
categories{
data{
id
attributes
{
name
}
}
}
}
}
}
}
`
The documentation for Strapi v4 is available here.
Could you try with:
const REVIEWS = gql`
query GetReviews {
reviews (sort: "createdAt:desc", pagination: { limit: 100 }) {
data{
id
attributes{
title
rating
body
createdAt
categories{
data{
id
attributes
{
name
}
}
}
}
}
}
}
`
The default and maximum values for pagination[limit] can be configured in the ./config/plugins.js file with the graphql.config.defaultLimit and graphql.config.maxLimit keys.

Shopify Admin API, graphQL, create draft order - add products

This is my fist time creating an order. From what I understand you need to create a draft order - add products, price, email, notes etc. I am just creating a test query now to see how it works and it tells me "Add at least 1 product". I am trying to add a product, but I dont know how. I have been messing around and reading and cant figure it out.
This is my query:
mutation draftOrderCreate {
draftOrderCreate(input: {email: "123abc#hotmail.com"}) {
draftOrder {
id
order {
id
}
status
}
userErrors {
field
message
}
}
}
If anyone can give me an example on how to add products to this would be great. Thanks.
You can create an draft order like so:
mutation draftOrderCreate($items: DraftOrderInput!) {
draftOrderCreate(input: $items) {
draftOrder {
id
order {
id
}
status
}
userErrors {
field
message
}
}
}
query variables:
{
"items": {
"email": "123abc#hotmail.com",
"lineItems": [
{
"variantId": "gid://shopify/ProductVariant/32231002996788",
"quantity": 1
}
]
}
}
Or if you don't want to use query variables you can pass the whole object as the input:
mutation draftOrderCreate {
draftOrderCreate(input: {email: "123abc#hotmail.com", lineItems: [{variantId: "gid://shopify/ProductVariant/32231002996788", quantity: 1}]}) {
draftOrder {
id
order {
id
}
status
}
userErrors {
field
message
}
}
}

How to get variant by variant Id from product object using by graphql Shopify

Query so far
{
product1: product(id: "gid://shopify/Product/777854222396") {
title
totalVariants
variants(first:99) {
.....
}
hasOutOfStockVariants
}
product2: product(id: "gid://shopify/Product/511571296316") {
title
}
}
What can be done to fetch variant based on id
I have found ProductVariant on their GraphQL Admin API reference docs, you can take reference from their else I didn't find any ProductVariant Schema open at QueryRoot as defined here in the open graphQL admin panel although they have mentioned an example.
query {
productVariant(id: "gid://shopify/ProductVariant/10782354800682") {
inventoryItem {
inventoryLevels (first:10) {
edges {
node {
location {
name
}
available
}
}
}
}
}
}

Shopify GraphQL partial matching on query filter

I'm just getting started with the new Shopify GraphQL Admin API. I'm trying to retreive all products, where the title field contains a certain word.
Currently I can successfully retrieve a product by including the full product title (exact match):
{
shop {
id
name
}
products(first: 10, query:"title:'RAVEN DUSTY OLIVE/SILVER MESH'") {
edges {
node {
productType
title
}
}
}
}
However, I want to partially match the title to display all products with the word "Raven" anywhere in the title, but the following returns no results:
{
shop {
id
name
}
products(first: 10, query:"title:'RAVEN'") {
edges {
node {
productType
title
}
}
}
}
Any ideas on how to get the partial matching working?
Bjorn! This should work:
{
shop {
id
name
}
products(first: 10, query:"title:RAVEN*") {
edges {
node {
productType
title
}
}
}
}
Check out the docs: https://help.shopify.com/en/api/getting-started/search-syntax
Also you can try with
query: "title:*${searchText}*"
you can see two * at the initial and the end

Resources