All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dft.api.shopify.v202410.ShopifyGraphQlMetafieldAPI Maven / Gradle / Ivy

There is a newer version: 1.0.7
Show newest version
package com.dft.api.shopify.v202410;

import com.dft.api.shopify.ShopifyGraphQLSdk;
import com.dft.api.shopify.model.auth.AccessCredential;
import com.dft.api.shopify.v202410.model.common.GraphQlQuery;
import com.dft.api.shopify.v202410.model.common.GraphQlVariable;
import com.dft.api.shopify.v202410.model.common.QueryResponse;
import com.dft.api.shopify.v202410.model.metafield.MetafieldsSetData;
import com.dft.api.shopify.v202410.model.metafield.RequestMetafield;
import com.dft.api.shopify.v202410.model.product.ProductData;
import com.dft.api.shopify.v202410.model.product.ProductVariantsBulkInput;
import com.fasterxml.jackson.core.type.TypeReference;

import java.util.List;

public class ShopifyGraphQlMetafieldAPI extends ShopifyGraphQLSdk {

    public ShopifyGraphQlMetafieldAPI(AccessCredential accessCredential) {
        super(accessCredential);
    }

    public QueryResponse getProductVariantMetafields(String productId, List metafieldKeys) {
        GraphQlVariable variables = new GraphQlVariable();
        variables.setId(String.format("gid://shopify/Product/%s", productId));
        variables.setKeys(metafieldKeys);

        GraphQlQuery graphQlQuery = new GraphQlQuery();
        graphQlQuery.setQuery("query call($id: ID!, $keys: [String!]!) { product(id: $id) { legacyResourceId variants(first: 250) { nodes{ legacyResourceId metafields(first: 250, keys: $keys) { nodes { key value } } } } } }");
        graphQlQuery.setVariables(variables);

        return getQueryData(graphQlQuery, new TypeReference<>() {});
    }

    public QueryResponse createOrUpdateProductMetaFields(GraphQlVariable variables) {
        GraphQlQuery graphQlQuery = new GraphQlQuery();
        graphQlQuery.setQuery("mutation updateProductMetafields($input: ProductInput!) { productUpdate(input: $input) { product { id metafields(first: 50) { nodes { id legacyResourceId namespace key value } } } userErrors { message field } } }");
        graphQlQuery.setVariables(variables);

        return getQueryData(graphQlQuery, new TypeReference<>() {});
    }

    public QueryResponse getProductMetafields(String productId) {
        GraphQlVariable variables = new GraphQlVariable();
        variables.setId(String.format("gid://shopify/Product/%s", productId));

        GraphQlQuery graphQlQuery = new GraphQlQuery();
        graphQlQuery.setQuery("query call($id: ID!, $keys: [String!]) { product(id: $id) { legacyResourceId metafields(first: 250, keys: $keys) { nodes { id namespace key value description } pageInfo{ endCursor hasNextPage } } } }");
        graphQlQuery.setVariables(variables);

        return getQueryData(graphQlQuery, new TypeReference<>() {});
    }

    public QueryResponse setShopMetafields(GraphQlVariable> variables) {
        GraphQlQuery graphQlQuery = new GraphQlQuery();
        graphQlQuery.setQuery("mutation MetafieldsSet($input: [MetafieldsSetInput!]!) { metafieldsSet(metafields: $input) { metafields { legacyResourceId key type value namespace ownerType } userErrors { field message code } } }");
        graphQlQuery.setVariables(variables);
        return getQueryData(graphQlQuery, new TypeReference<>() {});
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy