Exemplo n.º 1
0
        /// <summary>
        /// Generates a query to receive selected <c>products</c> from a Shopify store. The generated query will query the following on products:
        ///     - id
        ///     - title
        ///     - descriptionHtml
        ///     - images (with aliases defined by ShopifyClient.defaultImageResolutions)
        ///         - altText
        ///         - src
        ///     - options
        ///         - name
        ///         - values
        ///     - variants
        ///         - id
        ///         - available
        ///         - price
        ///         - title
        ///         - weight
        ///         - weightUnit
        ///         - selectedOptions
        ///             - name
        ///             - values
        ///         - image (with aliases defined by ShopifyClient.defaultImageResolutions)
        ///             - altText
        ///             - src
        ///     - collections
        ///         - image (with aliases defined by ShopifyClient.defaultImageResolutions)
        ///             - altText
        ///             - src
        ///         - title
        ///         - updatedAt
        ///
        /// </summary>
        /// <param name="callback">callback that will receive responses from server</param>
        /// <param name="productIds">a list of product ids you'd like to query</param>
        /// \code
        /// // Example usage querying two product ids using a List<string>
        /// List<string> productIds = new List<string>() {
        ///     "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzk4OTUyNzYwOTk=",
        ///     "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzk4OTUyNzkwNDM="
        /// };
        ///
        /// ShopifyBuy.Client().products((products, error) => {
        ///     Debug.Log(products[0].title());
        ///     Debug.Log(products[1].title());
        /// }, productIds);
        /// \endcode
        public void products(ProductsHandler callback, List <string> productIds)
        {
            QueryRootQuery query = new QueryRootQuery();

            query.nodes(n => n
                        .onProduct((p) => {
                DefaultQueries.products.Product(p, DefaultImageResolutions);
            }),
                        ids: productIds
                        );

            Loader.Query(query, (response) => {
                var error = (ShopifyError)response;
                if (error != null)
                {
                    callback(null, error);
                }
                else
                {
                    List <Product> products = new List <Product> ();

                    foreach (Shopify.Unity.Product product in response.data.nodes())
                    {
                        products.Add(product);
                    }

                    callback(products, error);
                }
            });
        }
Exemplo n.º 2
0
        public IEnumerator CanQueryTwoShops()
        {
            string domain1        = "graphql.myshopify.com";
            string authorization1 = "351c122017d0f2a957d32ae728ad749c";
            string domain2        = "graphql-many-products.myshopify.com";
            string authorization2 = "43b7fef8bd2f27f1d645586b72c9b825";

            StoppableWaitForTime waiter = Utils.GetWaitQuery();
            List <string>        names  = new List <string>();

            QueryLoader queryLoader1 = new QueryLoader(new UnityLoader(domain1, authorization1));
            QueryLoader queryLoader2 = new QueryLoader(new UnityLoader(domain2, authorization2));

            QueryResponseHandler callback = (QueryResponse response) => {
                names.Add(response.data.shop().name());

                if (names.Count == 2)
                {
                    waiter.Stop();
                }
            };

            queryLoader1.Query(TestQueries.Query, callback);
            queryLoader2.Query(TestQueries.Query, callback);

            yield return(waiter);

            Assert.IsTrue(waiter.IsStopped, Utils.MaxQueryMessage);
            Assert.AreNotEqual(names[0], names[1]);
        }
Exemplo n.º 3
0
        public void CanQueryHandleLoadErrors()
        {
            QueryResponse response    = null;
            QueryLoader   queryLoader = new QueryLoader(new TestLoader());

            queryLoader.Query(TestQueries.QueryFail, (QueryResponse r) => {
                response = r;
            });

            Assert.IsNull(response.data);
            Assert.IsNull(response.errors);
            Assert.AreEqual("Error: 404 Not Found error", response.HTTPError);
        }
Exemplo n.º 4
0
        public void CanQuery()
        {
            QueryResponse response    = null;
            QueryLoader   queryLoader = new QueryLoader(new TestLoader());

            queryLoader.Query(TestQueries.Query, (QueryResponse r) => {
                response = r;
            });

            Assert.IsNull(response.errors);
            Assert.IsNull(response.HTTPError);
            Assert.IsNotNull(response.data);
            Assert.AreEqual("test shop", response.data.shop().name());
        }
Exemplo n.º 5
0
        void Start()
        {
            string domain        = "graphql.myshopify.com";
            string authorization = "351c122017d0f2a957d32ae728ad749c";

            QueryLoader queryLoader = new QueryLoader(new UnityLoader(domain, authorization));

            queryLoader.Query(TestQueries.Query, (QueryResponse response) => {
                IntegrationTest.Assert(response.HTTPError == null, "http errors were not null: " + response.HTTPError);
                IntegrationTest.Assert(response.errors == null, "GraphQL errors were null");
                IntegrationTest.Assert(response.data != null, "Received a response");
                IntegrationTest.Assert(response.data.shop().name() != null, "graphql");

                IntegrationTest.Pass();
            });
        }
Exemplo n.º 6
0
        public void CanMutateUsingLambda()
        {
            QueryResponse response    = null;
            QueryLoader   queryLoader = new QueryLoader(new TestLoader());

            queryLoader.Query(
                q => q.shop(shop => shop.name()),
                (QueryResponse r) => {
                response = r;
            }
                );

            Assert.IsNull(response.errors);
            Assert.IsNull(response.HTTPError);
            Assert.IsNotNull(response.data);
            Assert.AreEqual("test shop", response.data.shop().name());
        }
Exemplo n.º 7
0
        public IEnumerator RanQueryUsingUnityLoader()
        {
            string domain               = "graphql.myshopify.com";
            string authorization        = "351c122017d0f2a957d32ae728ad749c";
            StoppableWaitForTime waiter = Utils.GetWaitQuery();

            QueryLoader queryLoader = new QueryLoader(new UnityLoader(domain, authorization));

            queryLoader.Query(TestQueries.Query, (QueryResponse response) => {
                waiter.Stop();

                Assert.IsNull(response.HTTPError, "http errors were not null: " + response.HTTPError);
                Assert.IsNull(response.errors, "GraphQL errors were null");
                Assert.IsNotNull(response.data, "Received a response");
                Assert.AreEqual("graphql", response.data.shop().name());
            });

            yield return(waiter);

            Assert.IsTrue(waiter.IsStopped, Utils.MaxQueryMessage);
        }
Exemplo n.º 8
0
        public IEnumerator TestWithValidQuery()
        {
            var requestIsFinished = false;

            string domain        = "graphql.myshopify.com";
            string authorization = "351c122017d0f2a957d32ae728ad749c";

            var queryLoader = new QueryLoader(new UnityEditorLoader(domain, authorization));

            queryLoader.Query(TestQueries.Query, (QueryResponse response) => {
                Assert.True(response.HTTPError == null, "http errors were not null: " + response.HTTPError);
                Assert.True(response.errors == null, "GraphQL errors were null");
                Assert.True(response.data != null, "Received a response");
                Assert.True(response.data.shop().name() != null, "graphql");
                requestIsFinished = true;
            });

            while (!requestIsFinished)
            {
                yield return(null);
            }
        }