Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.41 KB | None | 0 0
  1. How to execute a query:
  2.  
  3. public static async Task<string> ExecuteQuery(Schema schema, string querystring, Inputs inputs = null)
  4.         {
  5.             try
  6.             {
  7.                 var result = await new DocumentExecuter().ExecuteAsync(_ =>
  8.                 {
  9.                     _.Schema = schema;
  10.                     _.Query = querystring;
  11.                     _.Inputs = inputs;
  12.                 }).ConfigureAwait(false);
  13.  
  14.                 var json = new DocumentWriter(Formatting.None, null).Write(result);
  15.                 return json;
  16.             }
  17.             catch (Exception ex)
  18.             {
  19.                 return string.Empty;
  20.                 //return new ResponseMessage();
  21.             }
  22.         }
  23.  
  24. ------------------------------------------------------------------------------------------
  25. Root Query Class:
  26.  
  27.     public class ViewerType : ObjectGraphType
  28.     {
  29.         public ViewerType()
  30.         {
  31.             Name = "Viewer";
  32.  
  33.             #region "Queries"
  34.             Field<ListGraphType<PrescriptionType>>("Prescriptions",
  35.                 resolve: context => new PrescriptionMongoDataAccessLayer().GetPrescriptions(string.Empty));
  36.  
  37.             Field<PrescriptionType>("OnePrescription",
  38.                 arguments: new QueryArguments(new QueryArgument<StringGraphType> {Name = "id"}),
  39.                 resolve: context =>
  40.                 {
  41.                     var id = context.GetArgument<string>("id");
  42.                     return new PrescriptionMongoDataAccessLayer().GetOnePrescriptions(id);
  43.                 });
  44.  
  45.             Field<ListGraphType<DrugsType>>("Drugs",
  46.                 arguments: new QueryArguments(new QueryArgument<StringGraphType>() {Name = "drugName"}),
  47.                 resolve: context =>
  48.                 {
  49.                     var drugname = context.Arguments["drugName"].ToString();
  50.                     return new DrugsDataAccessLayer().SearchDrugs(drugname);
  51.                 });
  52.  
  53.             Field<LoginResultType>("LogIn",
  54.                 arguments: new QueryArguments(new QueryArgument<StringGraphType>() { Name = "username" }, new QueryArgument<StringGraphType> { Name = "password"}),
  55.                 resolve: context =>
  56.                 {
  57.                     var username = context.Arguments["username"].ToString();
  58.                     var password = context.Arguments["password"].ToString();
  59.                     //database/business logic
  60.                 });
  61.         }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement