public T ReadByIdDefault <T>(Id id, UserContext.ReadType readType, GraphQLDocument document) where T : class { var selectionSet = document != null?GetSelectionSet(document) : null; switch (readType) { case UserContext.ReadType.WithDocument: return(GetWithDocument <T>(selectionSet, id)); case UserContext.ReadType.Shallow: return(GetShallow <T>(id)); case UserContext.ReadType.Full: return(GetFull <T>(id)); default: throw new ArgumentOutOfRangeException(nameof(readType), readType, null); } }
public static User GetCurrentUser(this UserContext context, UserContext.ReadType readType) { return(context .Search <User>(expr => expr.Filter(u => u.G("UserId").Eq(context.UserName)), readType) .SingleOrDefault()); }
public T[] Search <T>(Func <ReqlExpr, ReqlExpr> searchFunction, GraphQLDocument document, UserContext.ReadType readType) where T : NodeBase { var type = typeof(T[]); var table = GetTable(type); switch (readType) { case UserContext.ReadType.WithDocument: var selectionSet = GetSelectionSet(document); var hashMap = GetHashMap(selectionSet, type); var importTree = GetImportTree(typeof(T), hashMap, null); var docExpr = searchFunction(table); docExpr = docExpr.Map(item => Merge(item, importTree)); docExpr = docExpr.Map(item => item.Pluck(hashMap)); var docResult = docExpr.CoerceTo("ARRAY").Run(_connection) as JArray; var docRet = Utils.DeserializeObject(type, docResult); return(docRet as T[]); case UserContext.ReadType.Shallow: var shallowSearchExpr = searchFunction(table); var shallowResult = shallowSearchExpr.CoerceTo("ARRAY").Run(_connection) as JArray; var shallowRet = Utils.DeserializeObject(type, shallowResult); return(shallowRet as T[]); } return(null); }