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]);
        }
Exemple #2
0
        /// <summary>
        /// Generates GraphQL queries.
        /// </summary>
        /// <param name="buildQuery">Delegate to build query</param>
        /// <param name="callback">callback that receives the query response</param>
        public void Query(QueryRootDelegate buildQuery, QueryResponseHandler callback)
        {
            QueryRootQuery query = new QueryRootQuery();

            buildQuery(query);

            Query(query, callback);
        }
Exemple #3
0
        /// <summary>
        /// Sends GraphQL queries to the GraphQL endpoint.
        /// </summary>
        /// <param name="query">query to be sent to the GraphQL endpoint</param>
        /// <param name="callback">callback that receives the query response</param>
        public void Query(QueryRootQuery query, QueryResponseHandler callback)
        {
#if SHOPIFY_VERBOSE_DEBUG
            Console.WriteLine("Sending Query: " + query.ToString() + "\n");
#endif

            Loader.Load(query.ToString(), (string response, string error) => {
#if SHOPIFY_VERBOSE_DEBUG
                Console.WriteLine("Response: " + response + "\n");
                Console.WriteLine("Error: " + error + "\n");
#endif
                if (error != null)
                {
                    callback(new QueryResponse(error));
                }
                else
                {
                    callback(new QueryResponse(GetJSON(response)));
                }
            });
        }
        public void QueryConnection(BuildQueryOnConnectionLoopDelegate getQuery, GetConnectionFromResponseDelegate getConnection, QueryResponseHandler callback)
        {
            QueryResponse mergedResponse = null;
            QueryRootQuery query = getQuery(null);

            QueryLoop queryLoop = (loop) => {
                Loader.Query(query, (response) => {
                    var error = (ShopifyError) response;
                    if (error != null) {
                        callback(response);
                    } else {
                        if (mergedResponse == null) {
                            mergedResponse = response;
                        } else {
                            MergeConnections(getConnection(mergedResponse.data), getConnection(response.data));
                        }

                        query = getQuery(response);

                        if (query != null) {
                            loop(loop);
                        } else {
                            callback(mergedResponse);
                        }
                    }
                });
            };

            queryLoop(queryLoop);
        }