/// <summary> /// <see ref="ShopifyClient">ShopifyClient </see> is the entry point to communicate with the Shopify Storefront API. /// <see ref="ShopifyClient">ShopifyClient </see> also has functionality to easily generate and send queries to receive /// information about products and collections. It also has the ability to create checkouts. /// </summary> /// <param name="accessToken">the access token used to query the Shopify Storefront API for a store</param> /// <param name="domain">domain for the Shopify store</param> /// \code /// // Example that initializes a new ShopifyClient which will query all products /// string accessToken = "b8d417759a62f7b342f3735dbe86b322"; /// string shopDomain = "unity-buy-sdk.myshopify.com"; /// /// ShopifyClient client = new ShopifyClient(accessToken, shopDomain); /// /// client.products((products, error) => { /// Debug.Log(products[0].title()); /// Debug.Log(products[1].title()); /// }); /// \endcode public ShopifyClient(string accessToken, string domain) { _AccessToken = accessToken; _Domain = domain; Loader = new QueryLoader(new UnityLoader(domain, AccessToken)); }
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]); }
private ILoader GetLoader(ISession session) { using (new SessionIdLoggingContext(Session.SessionId)) { if (indexProjection != null) { ProjectionLoader loader = new ProjectionLoader(); loader.Init(session, SearchFactory, resultTransformer, indexProjection); return(loader); } if (criteria != null) { if (classes.GetLength(0) > 1) { throw new SearchException("Cannot mix criteria and multiple entity types"); } if (criteria is CriteriaImpl) { string targetEntity = ((CriteriaImpl)criteria).EntityOrClassName; if (classes.GetLength(0) == 1 && classes[0].FullName != targetEntity) { throw new SearchException("Criteria query entity should match query entity"); } try { System.Type entityType = ((CriteriaImpl)criteria).GetRootEntityTypeIfAvailable(); classes = new System.Type[] { entityType }; } catch (Exception e) { throw new SearchException("Unable to load entity class from criteria: " + targetEntity, e); } } QueryLoader loader = new QueryLoader(); loader.Init(session, searchFactoryImplementor); loader.EntityType = classes[0]; loader.Criteria = criteria; return(loader); } if (classes.GetLength(0) == 1) { QueryLoader loader = new QueryLoader(); loader.Init(session, searchFactoryImplementor); loader.EntityType = classes[0]; return(loader); } else { ObjectLoader loader = new ObjectLoader(); loader.Init(session, searchFactoryImplementor); return(loader); } } }
/// <summary> /// <see ref="ShopifyClient">ShopifyClient </see> is the entry point to communicate with the Shopify Storefront API. /// <see ref="ShopifyClient">ShopifyClient </see> also has functionality to easily generate and send queries to receive /// information about products and collections. It also has the ability to create checkouts. /// </summary> /// <param name="accessToken">the access token used to query the Shopify Storefront API for a store</param> /// <param name="domain">domain for the Shopify store</param> /// \code /// // Example that initializes a new ShopifyClient which will query all products /// string accessToken = "b8d417759a62f7b342f3735dbe86b322"; /// string shopDomain = "unity-buy-sdk.myshopify.com"; /// /// ShopifyClient client = new ShopifyClient(accessToken, shopDomain); /// /// client.products((products, error) => { /// Debug.Log(products[0].title()); /// Debug.Log(products[1].title()); /// }); /// \endcode public ShopifyClient(string accessToken, string domain, string locale = null) { _AccessToken = accessToken; _Domain = domain; _Locale = locale; Loader = new QueryLoader(new UnityLoader(domain, AccessToken, locale)); }
public void ParseRefinement(Queue <string> tokens) { // Dequeue left curly brace token string token = tokens.Dequeue(); if (token != "{") { throw new QuerySyntaxException(token, "{"); } // Dequeue Property token token = tokens.Dequeue(); string property = token; // Dequeue colon token token = tokens.Dequeue(); if (token != ":") { throw new QuerySyntaxException(token, ":"); } // Dequeue Value token token = tokens.Dequeue(); // Kluge to find checkpoints by transaction id if (property == Symbols.TRANSACTION_ID) { this.query = this.query.Replace("@", token); if (tokens.Dequeue() != "}") { throw new QuerySyntaxException(token, "}"); } return; } // If the token is FAILED, the oracle query must compare null, so it must remove quotes // and replace = with IS if (property == Symbols.FAILED && token == "null") { this.query += QueryLoader.GetRefinement(property, token).Replace("'", "").Replace("=", "IS"); } else { DateTime date; if (DateTime.TryParse(token, out date)) { this.query += QueryLoader.GetRefinement(property, date.ToOracleTimeStamp()); } else { this.query += QueryLoader.GetRefinement(property, token); } } // Dequeue the right curly brace token token = tokens.Dequeue(); if (token != "}") { throw new QuerySyntaxException(token, "}"); } }
/// <summary> /// <see ref="ShopifyClient">ShopifyClient </see> is the entry point to communicate with the Shopify Storefront API. /// <see ref="ShopifyClient">ShopifyClient </see> also has functionality to easily generate and send queries to receive /// information about products and collections. It also has the ability to create checkouts. /// </summary> /// <param name="accessToken">the access token used to query the Shopify Storefront API for a store</param> /// <param name="domain">domain for the Shopify store</param> /// \code /// // Example that initializes a new ShopifyClient which will query all products /// string accessToken = "b8d417759a62f7b342f3735dbe86b322"; /// string shopDomain = "unity-buy-sdk.myshopify.com"; /// /// ShopifyClient client = new ShopifyClient(accessToken, shopDomain); /// /// client.products((products, error) => { /// Debug.Log(products[0].title()); /// Debug.Log(products[1].title()); /// }); /// \endcode public ShopifyClient(string accessToken, string domain) { _AccessToken = accessToken; _Domain = domain; #if !SHOPIFY_MONO_UNIT_TEST Loader = new QueryLoader(new UnityLoader(domain, AccessToken)); #endif }
/* * * Each method in the parser is designed to parse exactly one rewrite * rule in the Context Free Grammar, and then passes the tokens to the appropriate * rewrite rule as they are encountered. The database queries are loaded in from the * QueryLoader class as needed and built by this parser. * */ public void ParseItem(Queue <string> tokens) { string token = tokens.Dequeue(); this.query = QueryLoader.GetItemQuery(token); //Dequeue WHERE tokens.Dequeue(); while (tokens.Count > 0) { ParseRefinement(tokens); } }
public void CanMutationHandleLoadErrors() { MutationResponse response = null; QueryLoader queryLoader = new QueryLoader(new TestLoader()); queryLoader.Mutation(TestQueries.MutationFail, (MutationResponse r) => { response = r; }); Assert.IsNull(response.data); Assert.IsNull(response.errors); Assert.AreEqual("Error: 404 Not Found error", response.HTTPError); }
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()); }
public void CanMutate() { MutationResponse response = null; QueryLoader queryLoader = new QueryLoader(new TestLoader()); queryLoader.Mutation(TestQueries.Mutation, (MutationResponse r) => { response = r; }); Assert.IsNull(response.errors); Assert.IsNull(response.HTTPError); Assert.IsNotNull(response.data); Assert.AreEqual("12345", response.data.customerAccessTokenCreate().customerAccessToken().accessToken()); }
/// <summary> /// Load an aggregate type from the database (including all related entities) /// </summary> /// <typeparam name="T">Type of the entity</typeparam> /// <param name="context">DbContext</param> /// <param name="keyPredicate">The predicate used to find the aggregate by key</param> /// <param name="queryMode">Load all objects at once, or perform multiple queries</param> /// <returns>The aggregate loaded from the database</returns> public static T LoadAggregate <T>(this DbContext context, Expression <Func <T, bool> > keyPredicate, QueryMode queryMode = QueryMode.SingleQuery) where T : class { var entityManager = new EntityManager(context); var graph = new AggregateRegister(new CacheProvider()).GetEntityGraph <T>(); var queryLoader = new QueryLoader(context, entityManager); if (graph == null) { throw new NotSupportedException("Type: '" + typeof(T).FullName + "' is not a known aggregate"); } var includeStrings = graph.GetIncludeStrings(entityManager); return(queryLoader.LoadEntity(keyPredicate, includeStrings, queryMode)); }
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(); }); }
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()); }
public void Reload(Func <IQueryable <Book>, IQueryable <Book> > Filter) { lock (this) { if (IsLoading) { return; } IsLoading = true; } StringResources stx = StringResources.Load("AppResources"); Message = stx.Text("Loading"); IQueryable <Book> Books = QuerySet(Shared.BooksDb.Books.AsQueryable()); if (Filter != null) { Books = Filter(Books); } if (!string.IsNullOrEmpty(Search)) { Books = Books.Where(x => x.Title.Contains(Search)); } Books = Books.Include(x => x.Info); QueryLoader <Book> BLoader = new QueryLoader <Book>(Books, Shared.BooksDb); Observables <Book, GRRow <BookDisplay> > ItemsObservable = new Observables <Book, GRRow <BookDisplay> >(); ItemsObservable.ConnectLoader(BLoader, x => x.Remap(ToGRRow)); ItemsObservable.LoadEnd += (s, e) => IsLoading = false; ItemsObservable.LoadStart += (s, e) => { Message = string.Format("{0} {1} / {2}", stx.Text("Loading"), BLoader.CurrentPage, BLoader.NTotal); IsLoading = true; }; BkTable.Items = ItemsObservable; IsLoading = false; }
// other methods are convenience wrappers around this. private static T UpdateGraph <T>(this DbContext context, T entity, T persisted, Expression <Func <IUpdateConfiguration <T>, object> > mapping, string mappingScheme, UpdateParams updateParams) where T : class { if (entity == null) { throw new ArgumentNullException("entity"); } var entityManager = new EntityManager(context); var queryLoader = new QueryLoader(context, entityManager); var register = new AggregateRegister(new CacheProvider()); var root = GetRootNode(mapping, mappingScheme, register); var differ = new GraphDiffer <T>(context, queryLoader, entityManager, root); var queryMode = updateParams != null ? updateParams.QueryMode : QueryMode.SingleQuery; return(differ.Merge(entity, persisted, queryMode)); }
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); }
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); } }
public void ParseSearchType(Queue <string> tokens) { // If next token is a StringList, parse that if (tokens.Peek().IsValidStringList()) { ParseStringList(tokens); } else { string token = tokens.Dequeue(); this.query = QueryLoader.GetSearchTypeQuery(token); // Dequeue the WHERE token tokens.Dequeue(); while (tokens.Count > 0) { ParseRefinement(tokens); } if (token == Symbols.TRANSACTION) { this.query += "\n)"; } } }
/// <summary> /// Performs both filter and non-filter compiling. /// </summary> /// <param name="replacements">Defined query substitutions.</param> /// <param name="shallow">Does this represent a shallow (scalar or entity-id) select?</param> /// <param name="collectionRole">the role name of the collection used as the basis for the filter, NULL if this is not a filter.</param> private void DoCompile(IDictionary <string, string> replacements, bool shallow, String collectionRole) { // If the query is already compiled, skip the compilation. if (_compiled) { if (log.IsDebugEnabled) { log.Debug("compile() : The query is already compiled, skipping..."); } return; } // Remember the parameters for the compilation. _tokenReplacements = replacements ?? new Dictionary <string, string>(1); _shallowQuery = shallow; try { // PHASE 1 : Analyze the HQL AST, and produce an SQL AST. var translator = Analyze(collectionRole); _sqlAst = translator.SqlStatement; // at some point the generate phase needs to be moved out of here, // because a single object-level DML might spawn multiple SQL DML // command executions. // // Possible to just move the sql generation for dml stuff, but for // consistency-sake probably best to just move responsiblity for // the generation phase completely into the delegates // (QueryLoader/StatementExecutor) themselves. Also, not sure why // QueryLoader currently even has a dependency on this at all; does // it need it? Ideally like to see the walker itself given to the delegates directly... if (_sqlAst.NeedsExecutor) { _statementExecutor = BuildAppropriateStatementExecutor(_sqlAst); } else { // PHASE 2 : Generate the SQL. _generator = new HqlSqlGenerator(_sqlAst, _factory); _generator.Generate(); _queryLoader = new QueryLoader(this, _factory, _sqlAst.Walker.SelectClause); } _compiled = true; } catch (QueryException qe) { qe.QueryString = _queryIdentifier; throw; } catch (RecognitionException e) { // we do not actually propogate ANTLRExceptions as a cause, so // log it here for diagnostic purposes if (log.IsInfoEnabled) { log.Info("converted antlr.RecognitionException", e); } throw QuerySyntaxException.Convert(e, _queryIdentifier); } _enabledFilters = null; //only needed during compilation phase... }
/// <summary> /// It is possible to instantiate a <see ref="ShopifyClient">ShopifyClient </see> by passing an instance /// that implements <see ref="BaseLoader">BaseLoader </see>. <see ref="BaseLoader">BaseLoaders </see> handle network communication with /// the Storefront API. This functionality is useful if you'd like to use the Shopify SDK for Unity in a C# environment /// outside of Unity. The <c>domain</c> string is inferred from <see ref="BaseLoader">BaseLoaders </see> which can be used /// to request a specific client. /// </summary> /// <param name="loader">a loader which will handle network communication with the Storefront API</param> /// \code /// // Example that initializes a new ShopifyClient using a custom loader for another C# platform /// string accessToken = "b8d417759a62f7b342f3735dbe86b322"; /// string shopDomain = "unity-buy-sdk.myshopify.com"; /// /// CustomLoaderForNonUnityPlatform loader = new CustomLoaderForNonUnityPlatform(accessToken, shopDomain); /// /// ShopifyClient client = new ShopifyClient(loader); /// /// client.products((products, error) => { /// Debug.Log(products[0].title()); /// Debug.Log(products[1].title()); /// }); /// \endcode public ShopifyClient(BaseLoader loader) { _AccessToken = loader.AccessToken; _Domain = loader.Domain; Loader = new QueryLoader(loader); }
/// <summary> /// Overwrites the QueryLoader instance with a new one with the specified locale. /// /// <param name="locale">locale for fetching translated content of supported types and fields</param> /// \code /// // Example usage for updating the locale to French: /// ShopifyBuy.Client(shopDomain).UpdateLocale("fr") /// \endcode public void UpdateLocale(string locale) { Loader = new QueryLoader(new UnityLoader(_Domain, _AccessToken, locale)); _Locale = locale; }
public void ParseStringList(Queue <string> tokens) { this.query += QueryLoader.GetStringList(tokens.Dequeue()); }